From c637b2cd8263bf7f851bb5b911f10a2476b96f20 Mon Sep 17 00:00:00 2001 From: Mikkel Jakobsen Date: Thu, 26 Oct 2023 13:44:06 +0200 Subject: [PATCH] Make the digital reservation label functionality clearer By renaming the parameters and thereby make the purpose of the functions and their parameters self explanatory. Hopefully it is more clear :) --- .../reservation-material/reservation-info.tsx | 9 +++++-- src/apps/reservation-list/utils/helpers.ts | 24 +++++++++++-------- .../GroupModal/GroupModalReservationsList.tsx | 2 +- .../ReservationStatusInfoLabel.tsx | 8 +++---- src/core/utils/helpers/date.ts | 6 ++--- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/apps/reservation-list/reservation-material/reservation-info.tsx b/src/apps/reservation-list/reservation-material/reservation-info.tsx index 25bf41ca22..3954ddbd4a 100644 --- a/src/apps/reservation-list/reservation-material/reservation-info.tsx +++ b/src/apps/reservation-list/reservation-material/reservation-info.tsx @@ -51,9 +51,14 @@ const ReservationInfo: FC = ({ return ""; } + const date = (isDigital ? expiryDate : pickupDeadline) ?? null; + if (!date) { + return ""; + } + return getReservationStatusInfoLabel({ - pickupBranch: pickupBranch ?? undefined, - pickupDeadline: (isDigital ? expiryDate : pickupDeadline) ?? "", + pickupBranch, + date, t, isDigital }); diff --git a/src/apps/reservation-list/utils/helpers.ts b/src/apps/reservation-list/utils/helpers.ts index 40d04c5f1c..fb74e1b0b5 100644 --- a/src/apps/reservation-list/utils/helpers.ts +++ b/src/apps/reservation-list/utils/helpers.ts @@ -39,28 +39,32 @@ export const getReadyForPickup = (list: ReservationType[]) => { }); }; +export const infoLabelTextType = { + pickUpLatest: "reservationPickUpLatestText", + loanBefore: "reservationListLoanBeforeText" +} as const; + export const getReservationStatusInfoLabel = ({ pickupBranch, - pickupDeadline, + date, isDigital, t }: { - pickupBranch?: string; - pickupDeadline: string; + pickupBranch: string | null | undefined; + date: string; isDigital: boolean; t: UseTextFunction; }) => { const textKey = pickupBranch - ? "reservationPickUpLatestText" - : "reservationListLoanBeforeText"; - const date = formatDateDependingOnDigitalMaterial({ - date: pickupDeadline, - materialIsDigital: isDigital - }); + ? infoLabelTextType.pickUpLatest + : infoLabelTextType.loanBefore; return t(textKey, { placeholders: { - "@date": date + "@date": formatDateDependingOnDigitalMaterial({ + date, + isDigital + }) } }); }; diff --git a/src/components/GroupModal/GroupModalReservationsList.tsx b/src/components/GroupModal/GroupModalReservationsList.tsx index 1e58b037cf..61072738e7 100644 --- a/src/components/GroupModal/GroupModalReservationsList.tsx +++ b/src/components/GroupModal/GroupModalReservationsList.tsx @@ -91,7 +91,7 @@ const GroupModalReservationsList: FC = ({ ) : ( expiryDate && ( ) diff --git a/src/components/reservation/ReservationStatusInfoLabel.tsx b/src/components/reservation/ReservationStatusInfoLabel.tsx index 026fcce883..743f650580 100644 --- a/src/components/reservation/ReservationStatusInfoLabel.tsx +++ b/src/components/reservation/ReservationStatusInfoLabel.tsx @@ -5,14 +5,14 @@ import { useText } from "../../core/utils/text"; import { getReservationStatusInfoLabel } from "../../apps/reservation-list/utils/helpers"; export interface ReservationStatusInfoLabelProps { - pickupBranch?: string; - expiryDate: string; + pickupBranch?: string | null; + date: string; isDigital: boolean; } const ReservationStatusInfoLabel: FC = ({ pickupBranch, - expiryDate, + date, isDigital }) => { const t = useText(); @@ -20,7 +20,7 @@ const ReservationStatusInfoLabel: FC = ({ {getReservationStatusInfoLabel({ pickupBranch, - pickupDeadline: expiryDate, + date, t, isDigital })} diff --git a/src/core/utils/helpers/date.ts b/src/core/utils/helpers/date.ts index 7105d755d1..7fb295cec8 100644 --- a/src/core/utils/helpers/date.ts +++ b/src/core/utils/helpers/date.ts @@ -15,12 +15,12 @@ export const formatDateTime = (date: string) => { export const formatDateDependingOnDigitalMaterial = ({ date, - materialIsDigital + isDigital }: { date: string; - materialIsDigital: boolean; + isDigital: boolean; }) => { - return materialIsDigital ? formatDateTime(date) : formatDate(date); + return isDigital ? formatDateTime(date) : formatDate(date); }; export default getCurrentUnixTime;