Skip to content

Commit

Permalink
Rename return loans from useLoans
Browse files Browse the repository at this point in the history
Remove the 'all' prefix because it is not necessary."
  • Loading branch information
kasperbirch1 committed Nov 6, 2023
1 parent 622a7f5 commit 5769941
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
const t = useText();
const { reservations, reservationsReadyToLoan, reservationsQueued } =
useReservations();
const {
allLoans,
allOverdueLoans,
allSoonOverdueLoans,
allFarFromOverdueLoans
} = useLoans();
const { loans, loansOverdue, loansSoonOverdue, loansFarFromOverdue } =
useLoans();
const [accepted, setAccepted] = useState<boolean>(false);
const [modalReservationDetailsId, setModalReservationDetailsId] = useState<
string | null
Expand Down Expand Up @@ -96,7 +92,7 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
[open, reservationDetails]
);

const modalLoan = allLoans.find(
const modalLoan = loans.find(
({ loanId }) => String(loanId) === modalLoanDetailsId
);

Expand Down Expand Up @@ -127,17 +123,17 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({

switch (dueDateInput) {
case yesterday:
setLoansToDisplay(allOverdueLoans);
setLoansToDisplay(loansOverdue);
setModalHeader(t("loansOverdueText"));
break;

case soon:
setLoansToDisplay(allSoonOverdueLoans);
setLoansToDisplay(loansSoonOverdue);
setModalHeader(t("loansSoonOverdueText"));
break;

case longer:
setLoansToDisplay(allFarFromOverdueLoans);
setLoansToDisplay(loansFarFromOverdue);
setModalHeader(t("loansNotOverdueText"));
break;

Expand All @@ -146,50 +142,43 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
}
open(constructModalId(dueDateModal as string, [dueDateInput]));
},
[
dueDateModal,
open,
allFarFromOverdueLoans,
allOverdueLoans,
allSoonOverdueLoans,
t
]
[dueDateModal, open, loansFarFromOverdue, loansOverdue, loansSoonOverdue, t]
);

const dashboardNotificationsLoan = [
{
listLength: allOverdueLoans.length,
listLength: loansOverdue.length,
badge: t("materialDetailsOverdueText"),
header: t("loansOverdueText"),
color: "danger",
dataCy: "physical-loans-overdue",
showNotificationDot: true,
notificationClickEvent: () =>
allOverdueLoans.length === 1
? openLoanDetailsModal(String(allOverdueLoans[0].loanId))
loansOverdue.length === 1
? openLoanDetailsModal(String(loansOverdue[0].loanId))
: openDueDateModal(yesterday)
},
{
listLength: allSoonOverdueLoans.length,
listLength: loansSoonOverdue.length,
badge: t("statusBadgeWarningText"),
header: t("loansSoonOverdueText"),
color: "warning",
dataCy: "physical-loans-soon-overdue",
showNotificationDot: true,
notificationClickEvent: () =>
allSoonOverdueLoans.length === 1
? openLoanDetailsModal(String(allSoonOverdueLoans[0].loanId))
loansSoonOverdue.length === 1
? openLoanDetailsModal(String(loansSoonOverdue[0].loanId))
: openDueDateModal(soon)
},
{
listLength: allFarFromOverdueLoans.length,
listLength: loansFarFromOverdue.length,
header: t("loansNotOverdueText"),
dataCy: "loans-not-overdue",
color: "neutral",
showNotificationDot: false,
notificationClickEvent: () =>
allFarFromOverdueLoans.length === 1
? openLoanDetailsModal(String(allFarFromOverdueLoans[0].loanId))
loansFarFromOverdue.length === 1
? openLoanDetailsModal(String(loansFarFromOverdue[0].loanId))
: openDueDateModal(longer)
}
];
Expand Down Expand Up @@ -240,7 +229,7 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
<>
<NotificationColumn
materials={dashboardNotificationsLoan}
materialsCount={allLoans.length}
materialsCount={loans.length}
headerUrl={physicalLoansUrl}
header={t("physicalLoansText")}
emptyListText={t("noPhysicalLoansText")}
Expand Down Expand Up @@ -281,7 +270,7 @@ const DashboardNotificationList: FC<DashboardNotificationListProps> = ({
)}
/>
</MaterialDetailsModal>
{dueDate && allLoans && loansToDisplay && (
{dueDate && loans && loansToDisplay && (
<LoansGroupModal
accepted={accepted}
resetAccepted={() => resetAccepted()}
Expand Down
48 changes: 24 additions & 24 deletions src/apps/loan-list/list/loan-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const LoanList: FC<LoanListProps> = ({ pageSize }) => {
const [accepted, setAccepted] = useState<boolean>(false);
const [modalDetailsId, setModalDetailsId] = useState<string | null>(null);
const {
sortedByLoanDateFbs,
sortedByLoanDatePublizon,
loansSortedByDateFbs,
loansSortedByDatePublizon,
stackedMaterialsDueDatesFbs
} = useLoans();
useEffect(() => {
Expand All @@ -67,20 +67,20 @@ const LoanList: FC<LoanListProps> = ({ pageSize }) => {
return;
}
let loanForModal = null;
if (sortedByLoanDateFbs && modalDetailsId) {
if (loansSortedByDateFbs && modalDetailsId) {
loanForModal = getFromListByKey(
sortedByLoanDateFbs,
loansSortedByDateFbs,
"loanId",
modalDetailsId
);
}
if (
loanForModal?.length === 0 &&
sortedByLoanDatePublizon &&
loansSortedByDatePublizon &&
modalDetailsId
) {
loanForModal = getFromListByKey(
sortedByLoanDatePublizon,
loansSortedByDatePublizon,
"identifier",
modalDetailsId
);
Expand All @@ -91,8 +91,8 @@ const LoanList: FC<LoanListProps> = ({ pageSize }) => {
}, [
modalDetailsId,
modalLoan,
sortedByLoanDateFbs,
sortedByLoanDatePublizon
loansSortedByDateFbs,
loansSortedByDatePublizon
]);

const openAcceptModal = useCallback(() => {
Expand Down Expand Up @@ -142,9 +142,9 @@ const LoanList: FC<LoanListProps> = ({ pageSize }) => {
}, [allLoansId, loanDetails, openDueDateModal]);

const listContainsLoans =
(Array.isArray(sortedByLoanDateFbs) && sortedByLoanDateFbs.length > 0) ||
(Array.isArray(sortedByLoanDatePublizon) &&
sortedByLoanDatePublizon.length > 0);
(Array.isArray(loansSortedByDateFbs) && loansSortedByDateFbs.length > 0) ||
(Array.isArray(loansSortedByDatePublizon) &&
loansSortedByDatePublizon.length > 0);

const resetAccepted = () => {
setAccepted(false);
Expand All @@ -156,53 +156,53 @@ const LoanList: FC<LoanListProps> = ({ pageSize }) => {
<h1 className="text-header-h1 my-32">{t("loanListTitleText")}</h1>
{listContainsLoans && (
<>
{sortedByLoanDateFbs && (
{loansSortedByDateFbs && (
<List
pageSize={pageSize}
emptyListLabel={t("loanListPhysicalLoansEmptyListText")}
loans={sortedByLoanDateFbs}
loans={loansSortedByDateFbs}
dueDates={stackedMaterialsDueDatesFbs}
view={view}
openLoanDetailsModal={openLoanDetailsModal}
openDueDateModal={openDueDateModal}
>
<ListHeader
header={t("loanListPhysicalLoansTitleText")}
amount={sortedByLoanDateFbs.length}
amount={loansSortedByDateFbs.length}
>
<ToggleListViewButtons
disableRenewLoansButton={
getAmountOfRenewableLoans(sortedByLoanDateFbs) === 0
getAmountOfRenewableLoans(loansSortedByDateFbs) === 0
}
view={view}
setView={setView}
loans={sortedByLoanDateFbs}
loans={loansSortedByDateFbs}
pageSize={pageSize}
openRenewLoansModal={openRenewLoansModal}
/>
</ListHeader>
</List>
)}
{sortedByLoanDatePublizon && (
{loansSortedByDatePublizon && (
<List
pageSize={pageSize}
emptyListLabel={t("loanListDigitalLoansEmptyListText")}
loans={sortedByLoanDatePublizon}
loans={loansSortedByDatePublizon}
view="list"
openLoanDetailsModal={openLoanDetailsModal}
openDueDateModal={openDueDateModal}
>
<ListHeader
header={t("loanListDigitalLoansTitleText")}
amount={sortedByLoanDatePublizon.length}
amount={loansSortedByDatePublizon.length}
/>
</List>
)}
</>
)}

{loansAreEmpty(sortedByLoanDateFbs) &&
loansAreEmpty(sortedByLoanDatePublizon) && (
{loansAreEmpty(loansSortedByDateFbs) &&
loansAreEmpty(loansSortedByDatePublizon) && (
<EmptyList
classNames="mt-24"
emptyListText={t("loanListDigitalPhysicalLoansEmptyListText")}
Expand All @@ -223,7 +223,7 @@ const LoanList: FC<LoanListProps> = ({ pageSize }) => {
modalId={constructMaterialDetailsModalId(loanDetails, modalDetailsId)}
/>
</MaterialDetailsModal>
{sortedByLoanDateFbs && (
{loansSortedByDateFbs && (
<LoansGroupModal
accepted={accepted}
resetAccepted={() => resetAccepted()}
Expand All @@ -233,8 +233,8 @@ const LoanList: FC<LoanListProps> = ({ pageSize }) => {
openAcceptModal={openAcceptModal}
loansModal={
dueDate
? removeLoansWithDuplicateDueDate(dueDate, sortedByLoanDateFbs)
: sortedByLoanDateFbs
? removeLoansWithDuplicateDueDate(dueDate, loansSortedByDateFbs)
: loansSortedByDateFbs
}
>
{dueDate && (
Expand Down
8 changes: 4 additions & 4 deletions src/apps/menu/menu-logged-in/MenuLoggedInContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface MenuLoggedInContentProps {

const MenuLoggedInContent: FC<MenuLoggedInContentProps> = ({ pageSize }) => {
const { reservations } = useReservations();
const { allLoans, allOverdueLoans, allSoonOverdueLoans } = useLoans();
const { loans, loansOverdue, loansSoonOverdue } = useLoans();
const { data: patronData } = usePatronData();
const { data: fbsFees } = useGetFeesV2();
const t = useText();
Expand Down Expand Up @@ -52,8 +52,8 @@ const MenuLoggedInContent: FC<MenuLoggedInContentProps> = ({ pageSize }) => {
}, [fbsFees]);

const showNotifications =
allOverdueLoans.length !== 0 ||
allSoonOverdueLoans.length !== 0 ||
loansOverdue.length !== 0 ||
loansSoonOverdue.length !== 0 ||
reservations.length !== 0;

return (
Expand Down Expand Up @@ -91,7 +91,7 @@ const MenuLoggedInContent: FC<MenuLoggedInContentProps> = ({ pageSize }) => {
{menuNavigationData.map((menuNavigationItem) => (
<MenuNavigationItem
menuNavigationItem={menuNavigationItem}
loansCount={allLoans.length}
loansCount={loans.length}
reservationCount={reservations.length}
feeCount={feeCount}
/>
Expand Down
48 changes: 24 additions & 24 deletions src/core/utils/useLoans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,53 +34,53 @@ const useLoans = () => {
: [];

// Combine all loans from both FBS and Publizon
const allLoans = sortByDueDate([...mappedLoansFbs, ...mappedLoansPublizon]);
const loans = sortByDueDate([...mappedLoansFbs, ...mappedLoansPublizon]);

// Combine "overdue loans" from both FBS and Publizon
const overdueLoansFBS = filterLoansOverdue(mappedLoansFbs);
const overdueLoansPublizon = filterLoansOverdue(mappedLoansPublizon);
const allOverdueLoans = sortByDueDate([
...overdueLoansFBS,
...overdueLoansPublizon
const loansOverdueFBS = filterLoansOverdue(mappedLoansFbs);
const LoansOverduePublizon = filterLoansOverdue(mappedLoansPublizon);
const loansOverdue = sortByDueDate([
...loansOverdueFBS,
...LoansOverduePublizon
]);

// combine "soon overdue" loans from both FBS and Publizon
const soonOverdueLoansFBS = filterLoansSoonOverdue(mappedLoansFbs, warning);
const soonOverdueLoansPublizon = filterLoansSoonOverdue(
const loansSoonOverdueFBS = filterLoansSoonOverdue(mappedLoansFbs, warning);
const loansSoonOverduePublizon = filterLoansSoonOverdue(
mappedLoansPublizon,
warning
);
const allSoonOverdueLoans = sortByDueDate([
...soonOverdueLoansFBS,
...soonOverdueLoansPublizon
const loansSoonOverdue = sortByDueDate([
...loansSoonOverdueFBS,
...loansSoonOverduePublizon
]);

// combine "far from overdue" loans from both FBS and Publizon
const farFromOverdueFBS = filterLoansNotOverdue(mappedLoansFbs, warning);
const farFromOverduePublizon = filterLoansNotOverdue(
const loansFarFromOverdueFBS = filterLoansNotOverdue(mappedLoansFbs, warning);
const loansFarFromOverduePublizon = filterLoansNotOverdue(
mappedLoansPublizon,
warning
);
const allFarFromOverdueLoans = sortByDueDate([
...farFromOverdueFBS,
...farFromOverduePublizon
const loansFarFromOverdue = sortByDueDate([
...loansFarFromOverdueFBS,
...loansFarFromOverduePublizon
]);

// The due dates are used for the stacked materials
// The stacked materials view shows materials stacked by
// due date, and for this we need a unique list of due dates
const sortedByLoanDateFbs = sortByDueDate(mappedLoansFbs);
const sortedByLoanDatePublizon = sortByDueDate(mappedLoansPublizon);
const loansSortedByDateFbs = sortByDueDate(mappedLoansFbs);
const loansSortedByDatePublizon = sortByDueDate(mappedLoansPublizon);

// list of all due dates used for the stacked materials
const stackedMaterialsDueDatesFbs = getDueDatesLoan(mappedLoansFbs);
return {
allLoans,
sortedByLoanDateFbs,
sortedByLoanDatePublizon,
allOverdueLoans,
allSoonOverdueLoans,
allFarFromOverdueLoans,
loans,
loansSortedByDateFbs,
loansSortedByDatePublizon,
loansOverdue,
loansSoonOverdue,
loansFarFromOverdue,
stackedMaterialsDueDatesFbs
};
};
Expand Down

0 comments on commit 5769941

Please sign in to comment.