Skip to content

Commit

Permalink
fix(announcement): use func to get new datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore03109 committed Sep 20, 2023
1 parent ce2460f commit c1bb664
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/layouts/EditHomepage/EditHomepage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
33 changes: 20 additions & 13 deletions src/layouts/EditHomepage/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c1bb664

Please sign in to comment.