From c1bb6644bb42dc6e734bf522ec550a434e4f1750 Mon Sep 17 00:00:00 2001 From: Kishore <42832651+kishore03109@users.noreply.github.com> Date: Wed, 20 Sep 2023 18:30:19 +0800 Subject: [PATCH] fix(announcement): use func to get new datetime --- src/layouts/EditHomepage/EditHomepage.jsx | 8 +++--- src/layouts/EditHomepage/constants.ts | 33 ++++++++++++++--------- 2 files changed, 24 insertions(+), 17 deletions(-) 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",