Skip to content

Commit

Permalink
Merge pull request #1312 from danskernesdigitalebibliotek/develop
Browse files Browse the repository at this point in the history
Release 2024.27.0
  • Loading branch information
kasperg authored Jul 2, 2024
2 parents 4da2d1c + 4d7acfe commit 50e06f8
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 387 deletions.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,25 @@
"@testing-library/react": "^14.2.2",
"@testing-library/react-hooks": "^8.0.1",
"@tsconfig/create-react-app": "^1.0.2",
"@types/node": "^20.14.2",
"@types/node": "^20.14.9",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-flatpickr": "^3.8.11",
"@types/react-redux": "^7.1.24",
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^7.13.0",
"@typescript-eslint/parser": "^7.14.1",
"@vitest/coverage-istanbul": "^1.6.0",
"autoprefixer": "^10.4.19",
"babel-loader": "^9.1.3",
"babel-plugin-istanbul": "^6.1.1",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"caniuse-lite": "^1.0.30001636",
"caniuse-lite": "^1.0.30001639",
"chokidar-cli": "^3.0.0",
"concurrently": "^8.2.2",
"core-js": "^3.37.1",
"css-loader": "^7.1.2",
"cssnano": "^7.0.2",
"cssnano": "^7.0.3",
"cypress": "^9.6.1",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
Expand All @@ -106,36 +106,36 @@
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.34.2",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-webpack-plugin": "^4.2.0",
"glob": "^8.0.1",
"happy-dom": "^14.12.0",
"happy-dom": "^14.12.3",
"istanbul-lib-coverage": "^3.2.2",
"markdownlint-cli2": "^0.4.0",
"mutationobserver-shim": "^0.3.7",
"nyc": "^17.0.0",
"orval": "^6.26.0",
"postcss": "^8.4.38",
"postcss": "^8.4.39",
"postcss-cli": "^11.0.0",
"postcss-loader": "^8.1.1",
"postcss-scss": "^4.0.9",
"prettier": "^2.6.2",
"replace-in-file": "^6.3.2",
"sass": "^1.77.5",
"sass": "^1.77.6",
"source-map-support": "^0.5.21",
"style-loader": "^4.0.0",
"stylelint": "^15.11.0",
"stylelint-config-prettier": "^9.0.5",
"stylelint-config-recommended-scss": "^6.0.0",
"stylelint-prettier": "^2.0.0",
"stylelint-scss": "^6.3.1",
"stylelint-scss": "^6.3.2",
"stylelint-webpack-plugin": "^5.0.1",
"svg-url-loader": "^8.0.0",
"ts-node": "^10.9.2",
"typescript": "^4.6.4",
"vitest": "^0.28.5",
"webpack": "^5.92.0",
"webpack": "^5.92.1",
"webpack-cli": "^5.1.4",
"webpack-version-file-plugin": "^0.4.0"
},
Expand All @@ -144,7 +144,7 @@
"prop-types": "Since we use former ddb-react components that depend on prop-types we keep this. Should be removed when usage of prop-types is deprecated."
},
"dependencies": {
"@danskernesdigitalebibliotek/dpl-design-system": "^2024.25.0-44a88057ebe723f137f5ebe751cf0b6953c029b3",
"@danskernesdigitalebibliotek/dpl-design-system": "^2024.27.0-50a60f2057fffa8dac33aaaa4ceff523369c6b68",
"@fullcalendar/core": "^6.1.14",
"@fullcalendar/daygrid": "^6.1.14",
"@fullcalendar/interaction": "^6.1.14",
Expand All @@ -158,7 +158,7 @@
"dayjs": "^1.11.11",
"downshift": "8.5.0",
"focus-trap-react": "^10.2.3",
"graphql": "^16.8.2",
"graphql": "^16.9.0",
"graphql-tag": "^2.12.6",
"lodash": "^4.17.21",
"prop-types": "^15.8.1",
Expand All @@ -175,6 +175,6 @@
"unfetch": "^4.2.0"
},
"peerDependencies": {
"postcss": "^8.4.38"
"postcss": "^8.4.39"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
soonOverdue: loansSoonOverduePhysical,
farFromOverdue: loansFarFromOverduePhysical,
isLoading: isLoadingLoansPhysical
},
publizon: {
soonOverdue: loansSoonOverdueDigital,
farFromOverdue: loansFarFromOverdueDigital,
isLoading: isLoadingLoansDigital
}
} = useLoans();

Expand Down Expand Up @@ -120,12 +125,16 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
break;

case soon:
setLoansToDisplay(loansSoonOverduePhysical);
setLoansToDisplay(
loansSoonOverduePhysical.concat(loansSoonOverdueDigital)
);
setModalHeader(t("loansSoonOverdueText"));
break;

case longer:
setLoansToDisplay(loansFarFromOverduePhysical);
setLoansToDisplay(
loansFarFromOverduePhysical.concat(loansFarFromOverdueDigital)
);
setModalHeader(t("loansNotOverdueText"));
break;

Expand All @@ -140,6 +149,8 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
loansFarFromOverduePhysical,
loansOverduePhysical,
loansSoonOverduePhysical,
loansSoonOverdueDigital,
loansFarFromOverdueDigital,
t
]
);
Expand All @@ -158,7 +169,8 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
: openDueDateModal(yesterday)
},
{
listLength: loansSoonOverduePhysical.length,
listLength:
loansSoonOverduePhysical.length + loansSoonOverdueDigital.length,
badge: t("statusBadgeWarningText"),
header: t("loansSoonOverdueText"),
color: "warning",
Expand All @@ -170,7 +182,8 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
: openDueDateModal(soon)
},
{
listLength: loansFarFromOverduePhysical.length,
listLength:
loansFarFromOverduePhysical.length + loansFarFromOverdueDigital.length,
header: t("loansNotOverdueText"),
dataCy: "loans-not-overdue",
color: "neutral",
Expand Down Expand Up @@ -218,7 +231,11 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
materialsCount={loans.length}
header={t("physicalLoansText")}
emptyListText={t("noPhysicalLoansText")}
isLoading={isLoadingLoans || isLoadingLoansPhysical}
isLoading={
isLoadingLoans ||
isLoadingLoansPhysical ||
isLoadingLoansDigital
}
linkText={t("dashboardLoansLinkText")}
linkUrl={physicalLoansUrl}
/>
Expand All @@ -242,7 +259,10 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
...dashboardNotificationsReservations
]}
isLoading={
isLoadingLoans || isLoadingLoansPhysical || isLoadingReservations
isLoadingLoans ||
isLoadingLoansPhysical ||
isLoadingLoansDigital ||
isLoadingReservations
}
/>
)}
Expand Down
85 changes: 36 additions & 49 deletions src/apps/patron-page/PatronPage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import React, { useEffect, useState, FC, FormEvent } from "react";
import { set } from "lodash";
import { useQueryClient } from "react-query";
import { PatronV5, UpdatePatronRequestV4 } from "../../core/fbs/model";
import {
useUpdateV5,
getGetPatronInformationByPatronIdV2QueryKey
} from "../../core/fbs/fbs";
import { useText } from "../../core/utils/text";
import Link from "../../components/atoms/links/Link";
import BasicDetailsSection from "./sections/BasicDetailsSection";
Expand All @@ -17,15 +11,15 @@ import { useUrls } from "../../core/utils/url";
import { useNotificationMessage } from "../../core/utils/useNotificationMessage";
import { usePatronData } from "../../core/utils/helpers/usePatronData";
import PatronPageSkeleton from "./PatronPageSkeleton";
import useSavePatron from "../../core/utils/useSavePatron";
import { Patron } from "../../core/utils/types/entities";

const PatronPage: FC = () => {
const queryClient = useQueryClient();
const t = useText();
const u = useUrls();
const deletePatronUrl = u("deletePatronUrl");
const { mutate } = useUpdateV5();
const { data: patronData, isLoading } = usePatronData();
const [patron, setPatron] = useState<PatronV5 | null>(null);
const [patron, setPatron] = useState<Patron | null>(null);
const [pin, setPin] = useState<string | null>(null);
const [isPinChangeValid, setIsPinChangeValid] = useState<boolean>(true);
const [disableSubmitButton, setDisableSubmitButton] = useState(false);
Expand All @@ -34,6 +28,34 @@ const PatronPage: FC = () => {
);
const [NotificationComponent, handleNotificationMessage] =
useNotificationMessage();
const { savePatron, savePincode } = useSavePatron({
patron: patron || undefined,
fetchHandlers: {
savePatron: {
onSuccess: () => {
setDisableSubmitButton(false);
handleNotificationMessage(
t("patronPageHandleResponseInformationText")
);
},
onError: () => {
setDisableSubmitButton(false);
}
},
savePincode: {
onSuccess: () => {
setDisableSubmitButton(false);
setSuccessPinMessage(t("patronPinSavedSuccessText"));
handleNotificationMessage(
t("patronPageHandleResponseInformationText")
);
},
onError: () => {
setDisableSubmitButton(false);
}
}
}
});

useEffect(() => {
if (patronData && patronData.patron) {
Expand All @@ -46,7 +68,7 @@ const PatronPage: FC = () => {
}

// Changes the patron object by key.
// So using the paramters 123 and "phoneNumber" would change the phoneNumber to 123.
// So using the parameters 123 and "phoneNumber" would change the phoneNumber to 123.
const changePatron = (newValue: string | boolean, key: string) => {
// Deeeep copy
const copyUser = JSON.parse(JSON.stringify(patron));
Expand All @@ -57,50 +79,15 @@ const PatronPage: FC = () => {
const save = () => {
if (patron) {
setDisableSubmitButton(true);
// The save patron request is done in another section of the code, but in that section
// it is saved differently. Here, we save the input from the user, in the other scenario,
// the checkboxes (subscribe to texts, subscribe to emails) will be set automatically
const data: UpdatePatronRequestV4 = {
patron: {
emailAddress: patron.emailAddress,
receivePostalMail: patron.receivePostalMail,
phoneNumber: patron.phoneNumber,
onHold: patron.onHold,
preferredPickupBranch: patron.preferredPickupBranch,
receiveEmail: patron.receiveEmail,
receiveSms: patron.receiveSms
}
};
// If pincode is changed, the pincode should be updated.
if (pin) {
data.pincodeChange = {
savePincode({
pincode: pin,
libraryCardNumber: patron.patronId.toString()
};
});
} else {
savePatron(patron);
}
mutate(
{
data
},
{
onSuccess: () => {
queryClient.invalidateQueries(
getGetPatronInformationByPatronIdV2QueryKey()
);
if (pin) {
setSuccessPinMessage(t("patronPinSavedSuccessText"));
}
setDisableSubmitButton(false);
handleNotificationMessage(
t("patronPageHandleResponseInformationText")
);
},
// todo error handling, missing in figma
onError: () => {
setDisableSubmitButton(false);
}
}
);
}
};

Expand Down
Loading

0 comments on commit 50e06f8

Please sign in to comment.