From fb15984a68ecc6110c26257c4cab02d5ec0f8469 Mon Sep 17 00:00:00 2001 From: Kasper Birch Date: Tue, 7 Nov 2023 14:12:59 +0100 Subject: [PATCH] Change returns from `useReservations` to `useLoans` Now we return loans/reservations for both FBS and Publizon. --- src/apps/loan-list/list/loan-list.tsx | 63 +++++++++++---------------- src/core/utils/useLoans.tsx | 10 ++--- src/core/utils/useReservations.tsx | 7 +-- 3 files changed, 33 insertions(+), 47 deletions(-) diff --git a/src/apps/loan-list/list/loan-list.tsx b/src/apps/loan-list/list/loan-list.tsx index 69042ec1a0..3b3eabbff1 100644 --- a/src/apps/loan-list/list/loan-list.tsx +++ b/src/apps/loan-list/list/loan-list.tsx @@ -58,31 +58,24 @@ const LoanList: FC = ({ pageSize }) => { const [modalDetailsId, setModalDetailsId] = useState(null); const { fbs: { - sortedByDate: loansSortedByDateFbs, + loans: loansPhysical, stackedMaterialsDueDates: stackedMaterialsDueDatesFbs }, - publizon: { sortedByDate: loansSortedByDatePublizon } + publizon: { loans: loansDigital } } = useLoans(); + useEffect(() => { // If modalLoan is already set it should not be set again, because it will cause an infinite loop if (modalLoan) { return; } let loanForModal = null; - if (loansSortedByDateFbs && modalDetailsId) { - loanForModal = getFromListByKey( - loansSortedByDateFbs, - "loanId", - modalDetailsId - ); + if (loansPhysical && modalDetailsId) { + loanForModal = getFromListByKey(loansPhysical, "loanId", modalDetailsId); } - if ( - loanForModal?.length === 0 && - loansSortedByDatePublizon && - modalDetailsId - ) { + if (loanForModal?.length === 0 && loansDigital && modalDetailsId) { loanForModal = getFromListByKey( - loansSortedByDatePublizon, + loansDigital, "identifier", modalDetailsId ); @@ -90,12 +83,7 @@ const LoanList: FC = ({ pageSize }) => { if (loanForModal && loanForModal.length > 0) { setModalLoan(loanForModal[0]); } - }, [ - modalDetailsId, - modalLoan, - loansSortedByDateFbs, - loansSortedByDatePublizon - ]); + }, [modalDetailsId, modalLoan, loansPhysical, loansDigital]); const openAcceptModal = useCallback(() => { open(`${acceptModal}`); @@ -144,9 +132,8 @@ const LoanList: FC = ({ pageSize }) => { }, [allLoansId, loanDetails, openDueDateModal]); const listContainsLoans = - (Array.isArray(loansSortedByDateFbs) && loansSortedByDateFbs.length > 0) || - (Array.isArray(loansSortedByDatePublizon) && - loansSortedByDatePublizon.length > 0); + (Array.isArray(loansPhysical) && loansPhysical.length > 0) || + (Array.isArray(loansDigital) && loansDigital.length > 0); const resetAccepted = () => { setAccepted(false); @@ -158,11 +145,11 @@ const LoanList: FC = ({ pageSize }) => {

{t("loanListTitleText")}

{listContainsLoans && ( <> - {loansSortedByDateFbs && ( + {loansPhysical && ( = ({ pageSize }) => { > )} - {loansSortedByDatePublizon && ( + {loansDigital && ( )} )} - {loansSortedByDateFbs && - loansSortedByDatePublizon && - loansAreEmpty(loansSortedByDateFbs) && - loansAreEmpty(loansSortedByDatePublizon) && ( + {loansPhysical && + loansDigital && + loansAreEmpty(loansPhysical) && + loansAreEmpty(loansDigital) && ( = ({ pageSize }) => { modalId={constructMaterialDetailsModalId(loanDetails, modalDetailsId)} /> - {loansSortedByDateFbs && ( + {loansPhysical && ( resetAccepted()} @@ -237,8 +224,8 @@ const LoanList: FC = ({ pageSize }) => { openAcceptModal={openAcceptModal} loansModal={ dueDate - ? removeLoansWithDuplicateDueDate(dueDate, loansSortedByDateFbs) - : loansSortedByDateFbs + ? removeLoansWithDuplicateDueDate(dueDate, loansPhysical) + : loansPhysical } > {dueDate && ( diff --git a/src/core/utils/useLoans.tsx b/src/core/utils/useLoans.tsx index 36edec2fd7..a4ffc20277 100644 --- a/src/core/utils/useLoans.tsx +++ b/src/core/utils/useLoans.tsx @@ -57,19 +57,17 @@ const sortByDueDate = (list: LoanType[]) => { }; type Loans = { + loans: LoanType[]; overdue: LoanType[]; soonOverdue: LoanType[]; farFromOverdue: LoanType[]; isLoading: boolean; isError: boolean; - sortedByDate?: LoanType[]; stackedMaterialsDueDates?: string[]; }; type UseLoansType = { - all: Loans & { - loans: LoanType[]; - }; + all: Loans; fbs: Loans; publizon: Loans; }; @@ -157,19 +155,19 @@ const useLoans: UseLoans = () => { isError: loansIsError }, fbs: { + loans: loansSortedByDateFbs, overdue: loansOverdueFBS, soonOverdue: loansSoonOverdueFBS, farFromOverdue: loansFarFromOverdueFBS, - sortedByDate: loansSortedByDateFbs, stackedMaterialsDueDates: stackedMaterialsDueDatesFbs, isLoading: isLoadingFbs, isError: isErrorFbs }, publizon: { + loans: loansSortedByDatePublizon, overdue: LoansOverduePublizon, soonOverdue: loansSoonOverduePublizon, farFromOverdue: loansFarFromOverduePublizon, - sortedByDate: loansSortedByDatePublizon, isLoading: isLoadingPublizon, isError: isErrorPublizon } diff --git a/src/core/utils/useReservations.tsx b/src/core/utils/useReservations.tsx index 9a7319318e..fb706cc453 100644 --- a/src/core/utils/useReservations.tsx +++ b/src/core/utils/useReservations.tsx @@ -15,6 +15,7 @@ const getQueuedReservations = (list: ReservationType[]) => { }; type Reservations = { + reservations: ReservationType[]; readyToLoan: ReservationType[]; queued: ReservationType[]; isLoading: boolean; @@ -22,9 +23,7 @@ type Reservations = { }; type UseReservationsType = { - all: Reservations & { - reservations: ReservationType[]; - }; + all: Reservations; fbs: Reservations; publizon: Reservations; }; @@ -89,12 +88,14 @@ const useReservations: UseReservations = () => { isError: reservationsIsError }, fbs: { + reservations: mappedReservationsFbs, readyToLoan: reservationsReadyToLoanFBS, queued: reservationsQueuedFBS, isLoading: isLoadingFbs, isError: isErrorFbs }, publizon: { + reservations: mappedReservationsPublizon, readyToLoan: reservationsReadyToLoanPublizon, queued: reservationsQueuedPublizon, isLoading: isLoadingPublizon,