From 83184f7721af97ee6d1500b3c33930dbdb94c20f Mon Sep 17 00:00:00 2001 From: Kishore <42832651+kishore03109@users.noreply.github.com> Date: Thu, 14 Sep 2023 16:59:54 +0800 Subject: [PATCH] fix(announcement): interface bugs --- src/hooks/useDrag.tsx | 12 ++--- .../components/Homepage/AnnouncementBody.tsx | 45 ++++++++----------- .../homepage/AnnouncementsSection.tsx | 8 ++-- src/types/homepage.ts | 14 +++--- 4 files changed, 36 insertions(+), 43 deletions(-) diff --git a/src/hooks/useDrag.tsx b/src/hooks/useDrag.tsx index 26bedd9f9e..422118a289 100644 --- a/src/hooks/useDrag.tsx +++ b/src/hooks/useDrag.tsx @@ -364,7 +364,7 @@ export const onCreate = ( case "announcement": { const announcementKeyExist = !_.isEmpty( frontMatter.sections.find((section) => - EditorHomepageFrontmatterSection.isAnnouncementBlock(section) + EditorHomepageFrontmatterSection.isAnnouncements(section) ) ) if (!announcementKeyExist) { @@ -373,13 +373,13 @@ export const onCreate = ( } const announcementBlockIndex = frontMatter.sections.findIndex((section) => - EditorHomepageFrontmatterSection.isAnnouncementBlock(section) + EditorHomepageFrontmatterSection.isAnnouncements(section) ) const announcementBlockSection: AnnouncementBlockFrontmatterSection = frontMatter .sections[announcementBlockIndex] as AnnouncementBlockFrontmatterSection const announcements = createElement( - announcementBlockSection.announcementBlock.announcements, + announcementBlockSection.announcements.announcement_items, val as AnnouncementOption ) @@ -476,7 +476,7 @@ export const onDelete = ( case "announcement": { const announcementKeyExist = !_.isEmpty( frontMatter.sections.find((section) => - EditorHomepageFrontmatterSection.isAnnouncementBlock(section) + EditorHomepageFrontmatterSection.isAnnouncements(section) ) ) if (!announcementKeyExist) { @@ -485,13 +485,13 @@ export const onDelete = ( } const announcementBlockIndex = frontMatter.sections.findIndex((section) => - EditorHomepageFrontmatterSection.isAnnouncementBlock(section) + EditorHomepageFrontmatterSection.isAnnouncements(section) ) const announcementBlockSection: AnnouncementBlockFrontmatterSection = frontMatter .sections[announcementBlockIndex] as AnnouncementBlockFrontmatterSection const newAnnouncementOptions = deleteElement( - announcementBlockSection.announcementBlock.announcements, + announcementBlockSection.announcements.announcement_items, indexToDelete ) const newAnnouncementErrors = deleteElement( diff --git a/src/layouts/components/Homepage/AnnouncementBody.tsx b/src/layouts/components/Homepage/AnnouncementBody.tsx index 1c36fc240e..67b516cd86 100644 --- a/src/layouts/components/Homepage/AnnouncementBody.tsx +++ b/src/layouts/components/Homepage/AnnouncementBody.tsx @@ -5,7 +5,6 @@ import { Input, FormErrorMessage, Button, - DateRangePicker, DatePicker, Textarea, } from "@opengovsg/design-system-react" @@ -16,17 +15,12 @@ import { useEditableContext } from "contexts/EditableContext" import { Editable } from "layouts/components/Editable" -import { Announcement } from "types/announcements" import { AnnouncementOption } from "types/homepage" const MAX_ANNOUNCEMENTS = 5 -interface AnnouncementBodyFormFields { - button: string - url: string -} -interface AnnouncementBodyProps extends AnnouncementBodyFormFields { - errors: AnnouncementBodyFormFields & { +interface AnnouncementBodyProps { + errors: { announcements: AnnouncementOption[] } announcements: Partial[] @@ -34,8 +28,6 @@ interface AnnouncementBodyProps extends AnnouncementBodyFormFields { export const AnnouncementBody = ({ errors, - button, - url, announcements = [], }: AnnouncementBodyProps) => { const { @@ -45,8 +37,6 @@ export const AnnouncementBody = ({ onDelete, onDisplay, } = useEditableContext() - console.log("in announcement body") - console.log({ errors, button, url, announcements }) return ( @@ -73,15 +63,15 @@ export const AnnouncementBody = ({ title: announcementTitle, date: announcementDate, announcementContent, - linkText: announcementLinkText, - linkUrl: announcementLinkUrl, + link_text: announcementLinkText, + link_url: announcementLinkUrl, }, announcementIndex ) => { return ( Title @@ -115,13 +105,12 @@ export const AnnouncementBody = ({ Date { - console.log(value) onChange({ target: { - id: `announcement-${announcementIndex}-date`, + id: `announcements-${announcementIndex}-date`, value, }, }) @@ -141,7 +130,7 @@ export const AnnouncementBody = ({ Announcement