Skip to content

Commit

Permalink
Make the digital reservation label functionality clearer
Browse files Browse the repository at this point in the history
By renaming the parameters and thereby make the purpose of the functions and their
parameters self explanatory. Hopefully it is more clear :)
  • Loading branch information
spaceo committed Oct 26, 2023
1 parent 91129c9 commit c637b2c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ const ReservationInfo: FC<ReservationInfoProps> = ({
return "";
}

const date = (isDigital ? expiryDate : pickupDeadline) ?? null;
if (!date) {
return "";
}

return getReservationStatusInfoLabel({
pickupBranch: pickupBranch ?? undefined,
pickupDeadline: (isDigital ? expiryDate : pickupDeadline) ?? "",
pickupBranch,
date,
t,
isDigital
});
Expand Down
24 changes: 14 additions & 10 deletions src/apps/reservation-list/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/GroupModal/GroupModalReservationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const GroupModalReservationsList: FC<GroupModalReservationsListProps> = ({
) : (
expiryDate && (
<ReservationStatusInfoLabel
expiryDate={expiryDate}
date={expiryDate}
isDigital
/>
)
Expand Down
8 changes: 4 additions & 4 deletions src/components/reservation/ReservationStatusInfoLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ 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<ReservationStatusInfoLabelProps> = ({
pickupBranch,
expiryDate,
date,
isDigital
}) => {
const t = useText();
return (
<InfoLabel>
{getReservationStatusInfoLabel({
pickupBranch,
pickupDeadline: expiryDate,
date,
t,
isDigital
})}
Expand Down
6 changes: 3 additions & 3 deletions src/core/utils/helpers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit c637b2c

Please sign in to comment.