Skip to content

Commit

Permalink
Adds date check to status update
Browse files Browse the repository at this point in the history
  • Loading branch information
thiessenp-cds committed Oct 22, 2024
1 parent a769fea commit f367532
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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") {
Expand Down

0 comments on commit f367532

Please sign in to comment.