From 0a242515df4d2caa7d25cf24f607c104c20128da Mon Sep 17 00:00:00 2001 From: Kishore <42832651+kishore03109@users.noreply.github.com> Date: Thu, 14 Sep 2023 16:10:39 +0800 Subject: [PATCH] feat(announcement): add announcement block --- .../components/Homepage/AnnouncementBody.tsx | 225 ++++++++++++++++++ .../Homepage/AnnouncementSection.tsx | 69 ++++++ 2 files changed, 294 insertions(+) create mode 100644 src/layouts/components/Homepage/AnnouncementBody.tsx create mode 100644 src/layouts/components/Homepage/AnnouncementSection.tsx diff --git a/src/layouts/components/Homepage/AnnouncementBody.tsx b/src/layouts/components/Homepage/AnnouncementBody.tsx new file mode 100644 index 0000000000..1c36fc240e --- /dev/null +++ b/src/layouts/components/Homepage/AnnouncementBody.tsx @@ -0,0 +1,225 @@ +import { Text, Box, FormControl, VStack } from "@chakra-ui/react" +import { DragDropContext } from "@hello-pangea/dnd" +import { + FormLabel, + Input, + FormErrorMessage, + Button, + DateRangePicker, + DatePicker, + Textarea, +} from "@opengovsg/design-system-react" +import _ from "lodash" +import { BiPlus } from "react-icons/bi" + +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 & { + announcements: AnnouncementOption[] + } + announcements: Partial[] +} + +export const AnnouncementBody = ({ + errors, + button, + url, + announcements = [], +}: AnnouncementBodyProps) => { + const { + onDragEnd, + onChange, + onCreate, + onDelete, + onDisplay, + } = useEditableContext() + console.log("in announcement body") + console.log({ errors, button, url, announcements }) + return ( + + + + + + Announcements + + + You can display up to 5 announcements at a time. Newly added + announcements are shown on the top of the list + + + onDisplay("announcement")}> + + + {announcements.map( + ( + { + title: announcementTitle, + date: announcementDate, + announcementContent, + linkText: announcementLinkText, + linkUrl: announcementLinkUrl, + }, + announcementIndex + ) => { + return ( + + + + Title + + + {errors.announcements[announcementIndex].title} + + + + Date + { + console.log(value) + onChange({ + target: { + id: `announcement-${announcementIndex}-date`, + value, + }, + }) + }} + /> + + {errors.announcements[announcementIndex].date} + + + + Announcement +