diff --git a/src/layouts/EditHomepage/EditHomepage.jsx b/src/layouts/EditHomepage/EditHomepage.jsx index 456b94ae55..1d1a251458 100644 --- a/src/layouts/EditHomepage/EditHomepage.jsx +++ b/src/layouts/EditHomepage/EditHomepage.jsx @@ -60,7 +60,7 @@ import { KEY_HIGHLIGHT_SECTION, RESOURCES_SECTION, ANNOUNCEMENT_BLOCK, - ANNOUNCEMENT_SECTION, + getDefaultAnnouncementSection, } from "./constants" import { HomepagePreview } from "./HomepagePreview" import { getErrorValues } from "./utils" @@ -297,7 +297,7 @@ const EditHomepage = ({ match }) => { }) announcementItemErrors = _.map( section.announcements.announcement_items, - () => getErrorValues(ANNOUNCEMENT_SECTION) + () => getErrorValues(getDefaultAnnouncementSection()) ) if (!section.announcements.announcement_items) { // define an empty array to announcement_items to prevent error @@ -696,8 +696,8 @@ const EditHomepage = ({ match }) => { break } case "announcement": { - const val = ANNOUNCEMENT_SECTION - const err = getErrorValues(ANNOUNCEMENT_SECTION) + const val = getDefaultAnnouncementSection() + const err = getErrorValues(getDefaultAnnouncementSection()) const updatedHomepageState = onCreate( homepageState, elemType, diff --git a/src/layouts/EditHomepage/constants.ts b/src/layouts/EditHomepage/constants.ts index 4200c66795..60a373c25f 100644 --- a/src/layouts/EditHomepage/constants.ts +++ b/src/layouts/EditHomepage/constants.ts @@ -3,21 +3,28 @@ export const RESOURCES_SECTION = { subtitle: "Add a preview and link to your Resource Room", id: "resources", } as const -export const LocalDateTimeNow = new Date() - .toLocaleString("en-SG", { - timeZone: "Asia/Singapore", - }) - .slice(0, "dd/mm/yyyy".length) -export const ANNOUNCEMENT_SECTION = { - title: "Announcement", - date: LocalDateTimeNow, - announcement: "Announcement content", - link_text: "", - link_url: "", -} as const +export type AnnouncementSectionType = { + readonly title: "Announcement" + readonly date: string + readonly announcement: "Announcement content" + readonly link_text: "" + readonly link_url: "" +} -export type AnnouncementSectionType = typeof ANNOUNCEMENT_SECTION +export const getDefaultAnnouncementSection = (): AnnouncementSectionType => { + return { + title: "Announcement", + date: new Date() + .toLocaleString("en-SG", { + timeZone: "Asia/Singapore", + }) + .slice(0, "dd/mm/yyyy".length), + announcement: "Announcement content", + link_text: "", + link_url: "", + } +} export const ANNOUNCEMENT_BLOCK = { title: "New announcements block", id: "announcements",