-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/date-time
- Loading branch information
Showing
13 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...ocale]/(form administration)/form-builder/[id]/settings/manage/close/ClosedDateBanner.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useTranslation } from "@i18n/client"; | ||
import { Alert } from "@clientComponents/globals"; | ||
import { formClosingDateEst } from "lib/utils/date/utcToEst"; | ||
import { dateHasPast } from "lib/utils"; | ||
|
||
export const ClosedDateBanner = ({ closingDate }: { closingDate?: string | null }) => { | ||
const { t } = useTranslation("form-builder"); | ||
|
||
if (!closingDate) { | ||
return null; | ||
} | ||
|
||
const isPastClosingDate = dateHasPast(Date.parse(closingDate)); | ||
|
||
const { month, day, year, hour, minute } = formClosingDateEst(closingDate); | ||
|
||
const closedText = t("closingDate.banner.text", { | ||
month, | ||
day, | ||
year, | ||
hour, | ||
minute, | ||
}); | ||
|
||
if (!isPastClosingDate) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Alert.Info> | ||
<p className="mt-3 font-bold">{closedText}</p> | ||
</Alert.Info> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
components/clientComponents/forms/ClosingNotice/Notice.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"use client"; | ||
|
||
import { isFutureDate } from "lib/utils/date/isFutureDate"; | ||
import { useTranslation } from "@i18n/client"; | ||
import { formClosingDateEst } from "lib/utils/date/utcToEst"; | ||
|
||
export const Notice = ({ closingDate, language }: { closingDate?: string; language: string }) => { | ||
const { t } = useTranslation("common"); | ||
|
||
if (!closingDate) { | ||
return null; | ||
} | ||
|
||
if (!isFutureDate(closingDate)) { | ||
return null; | ||
} | ||
|
||
const { month, day, year, hour, minute } = formClosingDateEst(closingDate, language); | ||
|
||
return ( | ||
<div className="mb-4 w-3/5 border-l-8 border-gcds-blue-750 pl-4"> | ||
<div className="mb-6 font-bold text-gcds-blue-750">{t("closingNotice.title")}</div> | ||
<p className="pb-2"> | ||
{t("closingNotice.text1")} <br /> | ||
<span className="font-bold"> | ||
{t("closingNotice.text2", { | ||
month, | ||
day, | ||
year, | ||
hour, | ||
minute, | ||
})} | ||
</span> | ||
</p> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const isFutureDate = (utcDate?: string) => { | ||
if (!utcDate) { | ||
return false; | ||
} | ||
const date = new Date(utcDate); | ||
const now = new Date(); | ||
return date > now; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export const formClosingDateEst = (utcDate: string, lang: string = "en") => { | ||
const date = new Date(utcDate); | ||
|
||
const options: Intl.DateTimeFormatOptions = { | ||
timeZone: "America/New_York", | ||
year: "numeric", | ||
month: "long", | ||
day: "2-digit", | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
hour12: false, | ||
}; | ||
|
||
const locale = lang === "fr" ? "fr-CA" : "en-CA"; | ||
|
||
// Create a formatter for EST | ||
const formatter = new Intl.DateTimeFormat(locale, options); | ||
|
||
// Format the date in EST | ||
const parts = formatter.formatToParts(date); | ||
|
||
// Extract the parts | ||
const month = parts.find((part) => part.type === "month")?.value; | ||
const day = parts.find((part) => part.type === "day")?.value; | ||
const year = parts.find((part) => part.type === "year")?.value; | ||
const hour = parts.find((part) => part.type === "hour")?.value; | ||
const minute = parts.find((part) => part.type === "minute")?.value; | ||
|
||
return { | ||
month, | ||
day, | ||
year, | ||
hour, | ||
minute, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters