Skip to content

Commit

Permalink
Updates closingDate to use null as closed or date as open
Browse files Browse the repository at this point in the history
  • Loading branch information
thiessenp-cds committed Oct 21, 2024
1 parent a644fda commit a769fea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ export const SetClosingDate = ({
return true;
}, [closedMessage]);

const [status, setStatus] = useState(closingDate ? "closed" : "open");
// 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]

Check warning on line 56 in app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/manage/close/SetClosingDate.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/manage/close/SetClosingDate.tsx#L56

[react-hooks/exhaustive-deps] React Hook useCallback has an unnecessary dependency: 'closingDate'. Either exclude it or remove the dependency array.
);

const [status, setStatus] = useState(isPastDate(closingDate) ? "closed" : "open");
const [showDateTimeDialog, setShowDateTimeDialog] = useState(false);

const handleToggle = (value: boolean) => {
Expand Down Expand Up @@ -81,7 +91,7 @@ export const SetClosingDate = ({
);

const saveFormStatus = useCallback(async () => {
let closeDate = "open"; // this wil reset the closing date to null;
let closeDate = null;

if (status === "closed") {
const now = new Date(); // Set date to now to close the form right away
Expand All @@ -99,6 +109,7 @@ export const SetClosingDate = ({
return;
}

// TODO: not working, needs more work
// update the local template store
setClosingDate(status !== "open" ? closeDate : null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export const closeForm = async ({
closedDetails,
}: {
id: string;
closingDate: string;
closingDate: string | null;
closedDetails?: ClosedDetails;
}): Promise<{
formID: string;
Expand Down
12 changes: 3 additions & 9 deletions lib/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,15 +1251,9 @@ export const onlyIncludePublicProperties = (template: FormRecord): PublicFormRec
export const updateClosedData = async (
ability: UserAbility,
formID: string,
closingDate: string,
closingDate: string | null,
details?: ClosedDetails
) => {
let d = null;

if (closingDate !== "open") {
d = closingDate;
}

let detailsData: ClosedDetails | null = null;

// Add the closed details if they exist
Expand All @@ -1276,7 +1270,7 @@ export const updateClosedData = async (
id: formID,
},
data: {
closingDate: d,
closingDate,
closedDetails:
detailsData !== null ? (detailsData as Prisma.JsonObject) : Prisma.JsonNull,
},
Expand All @@ -1297,7 +1291,7 @@ export const updateClosedData = async (
);
throw e;
}
return { formID, closingDate: d };
return { formID, closingDate };
};

export const updateSecurityAttribute = async (
Expand Down

0 comments on commit a769fea

Please sign in to comment.