From 74f8294591b42ba9a5e728710498c0f6d5a5bc0f Mon Sep 17 00:00:00 2001 From: Jacob Pihl Date: Wed, 15 Nov 2023 14:57:05 +0100 Subject: [PATCH] Added ability to cancel pause period This adds the ability to cancel an ongoing pause period after it has been set. --- src/apps/patron-page/PatronPage.dev.tsx | 4 ++ src/apps/patron-page/PatronPage.entry.tsx | 1 + .../pause-reservation/pause-reservation.tsx | 62 +++++++++++++------ src/core/storybook/reservationListArgs.ts | 4 ++ 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/apps/patron-page/PatronPage.dev.tsx b/src/apps/patron-page/PatronPage.dev.tsx index ee779ad039..061e913698 100644 --- a/src/apps/patron-page/PatronPage.dev.tsx +++ b/src/apps/patron-page/PatronPage.dev.tsx @@ -85,6 +85,10 @@ export default { defaultValue: "Save", control: { type: "text" } }, + pauseReservationModalCancelButtonLabelText: { + defaultValue: "Cancel pause", + control: { type: "text" } + }, patronPageBasicDetailsHeaderText: { defaultValue: "Basic details", control: { type: "text" } diff --git a/src/apps/patron-page/PatronPage.entry.tsx b/src/apps/patron-page/PatronPage.entry.tsx index a59586ab65..11a14c75b7 100644 --- a/src/apps/patron-page/PatronPage.entry.tsx +++ b/src/apps/patron-page/PatronPage.entry.tsx @@ -34,6 +34,7 @@ interface PatronPageTextProps { pauseReservationModalBelowInputsTextText: string; pauseReservationModalLinkText: string; pauseReservationModalSaveButtonLabelText: string; + pauseReservationModalCancelButtonLabelText: string; patronPageBasicDetailsHeaderText: string; patronPageBasicDetailsNameLabelText: string; patronPageBasicDetailsAddressLabelText: string; diff --git a/src/apps/reservation-list/modal/pause-reservation/pause-reservation.tsx b/src/apps/reservation-list/modal/pause-reservation/pause-reservation.tsx index c1882653cd..fa977dd44b 100644 --- a/src/apps/reservation-list/modal/pause-reservation/pause-reservation.tsx +++ b/src/apps/reservation-list/modal/pause-reservation/pause-reservation.tsx @@ -1,4 +1,4 @@ -import React, { FC, useCallback, useState, useEffect, FormEvent } from "react"; +import React, { FC, useCallback, useState, useEffect, useId } from "react"; import { useQueryClient } from "react-query"; import Link from "../../../../components/atoms/links/Link"; import Modal, { useModalButtonHandler } from "../../../../core/utils/modal"; @@ -25,15 +25,17 @@ const PauseReservation: FC = ({ id, user }) => { const { mutate } = useUpdateV5(); const { close } = useModalButtonHandler(); const { pauseReservation } = getModalIds(); + const saveFormId = useId(); + const config = useConfig(); const [startDate, setStartDate] = useState( config("pauseReservationStartDateConfig") ); const [endDate, setEndDate] = useState(""); + const pauseActive = user?.onHold?.from && user?.onHold?.to; const save = useCallback( - (e: FormEvent) => { - e.preventDefault(); + (localStartDate?: string, localEndDate?: string) => { if (!user) { return; } @@ -46,12 +48,10 @@ const PauseReservation: FC = ({ id, user }) => { receiveSms: user.receiveSms } as Patron; - if (startDate || endDate) { - saveData.onHold = { - from: startDate === "" ? undefined : startDate, - to: endDate === "" ? undefined : endDate - }; - } + saveData.onHold = { + from: localStartDate === "" ? undefined : localStartDate, + to: localEndDate === "" ? undefined : localEndDate + }; mutate( { @@ -69,9 +69,15 @@ const PauseReservation: FC = ({ id, user }) => { } ); }, - [close, endDate, mutate, pauseReservation, queryClient, startDate, user] + [close, mutate, pauseReservation, queryClient, user] ); + const resetPauseDates = useCallback(() => { + setStartDate(config("pauseReservationStartDateConfig")); + setEndDate(""); + save(); + }, [config, save]); + useEffect(() => { if (user?.onHold?.from) { setStartDate(user.onHold.from); @@ -90,7 +96,7 @@ const PauseReservation: FC = ({ id, user }) => { "pauseReservationModalAriaDescriptionText" )} > -
save(e)} className="modal-pause__container"> +

{t("pauseReservationModalHeaderText")}

@@ -99,12 +105,20 @@ const PauseReservation: FC = ({ id, user }) => { {t("pauseReservationModalBodyText")}

- + { + e.preventDefault(); + save(startDate, endDate); + }} + > + +

{t("pauseReservationModalBelowInputsTextText")} @@ -120,12 +134,22 @@ const PauseReservation: FC = ({ id, user }) => {

+ {pauseActive && ( + + )}
- +
); }; diff --git a/src/core/storybook/reservationListArgs.ts b/src/core/storybook/reservationListArgs.ts index ce828fc01e..8eb4c5ac45 100644 --- a/src/core/storybook/reservationListArgs.ts +++ b/src/core/storybook/reservationListArgs.ts @@ -211,6 +211,10 @@ export default { defaultValue: "Save", control: { type: "text" } }, + pauseReservationModalCancelButtonLabelText: { + defaultValue: "Cancel pause", + control: { type: "text" } + }, listDetailsNothingSelectedLabelText: { defaultValue: "Pick", control: { type: "text" }