From f367532d9502ce47c8d82867ae53f94a667feeaa Mon Sep 17 00:00:00 2001 From: Peter Thiessen Date: Tue, 22 Oct 2024 10:09:19 -0400 Subject: [PATCH] Adds date check to status update --- .../[id]/settings/manage/close/SetClosingDate.tsx | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/manage/close/SetClosingDate.tsx b/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/manage/close/SetClosingDate.tsx index 2e8483df2e..33ae773364 100644 --- a/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/manage/close/SetClosingDate.tsx +++ b/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/manage/close/SetClosingDate.tsx @@ -16,6 +16,7 @@ import { closeForm } from "@formBuilder/actions"; import { ClosingDateDialog } from "./ClosingDateDialog"; import { ScheduledClosingDate } from "./ScheduledClosingDate"; +import { dateHasPast } from "@lib/utils"; export const SetClosingDate = ({ formId, @@ -46,17 +47,9 @@ export const SetClosingDate = ({ return true; }, [closedMessage]); - // TODO: not working, needs more work - const isPastDate = useCallback( - (closingDate: string | null | undefined) => { - const date1 = new Date(closingDate || 0).getTime(); - const date2 = Date.now(); - return date1 < date2; - }, - [closingDate] + const [status, setStatus] = useState( + dateHasPast(Date.parse(closingDate || "")) ? "closed" : "open" ); - - const [status, setStatus] = useState(isPastDate(closingDate) ? "closed" : "open"); const [showDateTimeDialog, setShowDateTimeDialog] = useState(false); const handleToggle = (value: boolean) => { @@ -109,8 +102,6 @@ export const SetClosingDate = ({ return; } - // TODO: not working, needs more work - // update the local template store setClosingDate(status !== "open" ? closeDate : null); if (status === "closed") {