From d28f37ef2869915b2f99d2b7f1f9009becaeaf88 Mon Sep 17 00:00:00 2001 From: sandeep14k Date: Wed, 9 Oct 2024 11:44:45 +0530 Subject: [PATCH 1/3] daedline field for notice containing opening tag --- callbacks/admin/rc/notice.ts | 1 + components/Modals/ViewNotice.tsx | 20 +++++++++++++++++++- pages/admin/rc/[rcid]/notice.tsx | 1 + pages/student/rc/[rcid]/notices.tsx | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/callbacks/admin/rc/notice.ts b/callbacks/admin/rc/notice.ts index 5b233ddf..94636f2c 100644 --- a/callbacks/admin/rc/notice.ts +++ b/callbacks/admin/rc/notice.ts @@ -19,6 +19,7 @@ export interface NoticeParams { created_by: string; CreatedAt: string; last_reminder_at: number; + deadline: string; } export interface NoticeResponse { title: string; diff --git a/components/Modals/ViewNotice.tsx b/components/Modals/ViewNotice.tsx index 8413bb1c..d607fab9 100644 --- a/components/Modals/ViewNotice.tsx +++ b/components/Modals/ViewNotice.tsx @@ -20,10 +20,17 @@ const boxStyle = { maxHeight: "90vh", }; function ViewNotice({ currentNotice }: { currentNotice: NoticeParams }) { - let value = currentNotice.CreatedAt; + const value = currentNotice.CreatedAt; const publishedDateAndTime = `${new Date(value).toLocaleDateString( "en-GB" )} ${new Date(value).toLocaleTimeString()}`; + const isOpeningTag = currentNotice.tags.includes("opening"); + function formatDeadline(deadline: string): string { + return deadline === "0001-01-01T00:00:00Z" + ? "N/A" + : new Date(deadline).toLocaleString(); + } + const deadlineDate = formatDeadline(currentNotice.deadline); return ( @@ -55,6 +62,17 @@ function ViewNotice({ currentNotice }: { currentNotice: NoticeParams }) { readOnly: true, }} /> + {isOpeningTag && ( + + )} Description { From 44f88128c147112c9fd254b4fbc3aaa733aef7d1 Mon Sep 17 00:00:00 2001 From: sandeep14k Date: Wed, 9 Oct 2024 12:10:56 +0530 Subject: [PATCH 2/3] updated edit rc notice --- components/Modals/EditRCNotices.tsx | 90 ++++++++++++++++++----------- 1 file changed, 57 insertions(+), 33 deletions(-) diff --git a/components/Modals/EditRCNotices.tsx b/components/Modals/EditRCNotices.tsx index edcd4118..2d149584 100644 --- a/components/Modals/EditRCNotices.tsx +++ b/components/Modals/EditRCNotices.tsx @@ -59,6 +59,7 @@ function EditNotice({ created_by: "", CreatedAt: "", last_reminder_at: 0, + deadline: "", }); const [isFetched, setisFetched] = useState(false); @@ -68,27 +69,19 @@ function EditNotice({ formState: { errors }, reset, } = useForm(); - const handleEditNotice = (data: NoticeResponse) => { - const editNotice = async () => { - const finData = { - ...data, - subject: data.title, - recruitment_cycle_id: 0, - description, - }; - await noticeRequest.put(token, rid, finData).then(() => { - const fetch = async () => { - if (rid === undefined || rid === "") return; - const Newnotice: NoticeParams[] = await noticeRequest.getAll( - token, - rid - ); - setNotice(Newnotice); - }; - fetch(); - }); + + const handleEditNotice = async (data: NoticeResponse) => { + const finData = { + ...data, + subject: data.title, + recruitment_cycle_id: 0, + description, }; - editNotice(); + await noticeRequest.put(token, rid, finData).then(async () => { + if (rid === undefined || rid === "") return; + const newNotices: NoticeParams[] = await noticeRequest.getAll(token, rid); + setNotice(newNotices); + }); handleCloseEdit(); }; @@ -100,23 +93,34 @@ function EditNotice({ }; getAllNotices(); }, [token, rid]); - const handleChange = (value: any) => { - for (let i = 0; i < notices.length; i += 1) { - if (notices[i].ID === value) { - reset(notices[i]); - setDescription(notices[i].description); - setCurrNotice(notices[i]); - setisFetched(true); - break; - } + + const handleChange = (value: unknown) => { + const selectedNotice = notices.find((notice) => notice.ID === value); + if (selectedNotice) { + reset(selectedNotice); + setDescription(selectedNotice.description); + setCurrNotice(selectedNotice); + setisFetched(true); } }; + + const formatDate = (date: string): string => + date === "0001-01-01T00:00:00Z" ? "N/A" : new Date(date).toLocaleString(); + + const publishedDateAndTime = `${new Date( + currNotice.CreatedAt + ).toLocaleDateString("en-GB")} ${new Date( + currNotice.CreatedAt + ).toLocaleTimeString()}`; + const isOpeningTag = currNotice.tags.includes("opening"); + const deadlineDate = formatDate(currNotice.deadline); + return (

Edit Notice

- Select ID + Select ID @@ -136,8 +142,16 @@ function EditNotice({ id="title" variant="filled" {...register("title", { required: true })} - error={!!errors.subject} - helperText={errors.subject && "Title is required"} + error={!!errors.title} + helperText={errors.title && "Title is required"} + /> + + {isOpeningTag && ( + + )} Description {isFetched && ( From 78c1f873c32b6f1559b112300460f06ee99960c3 Mon Sep 17 00:00:00 2001 From: sandeep14k Date: Wed, 9 Oct 2024 15:20:30 +0530 Subject: [PATCH 3/3] prevent TextField label overlap --- components/Modals/EditRCNotices.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/Modals/EditRCNotices.tsx b/components/Modals/EditRCNotices.tsx index 2d149584..795df7fb 100644 --- a/components/Modals/EditRCNotices.tsx +++ b/components/Modals/EditRCNotices.tsx @@ -144,7 +144,9 @@ function EditNotice({ {...register("title", { required: true })} error={!!errors.title} helperText={errors.title && "Title is required"} + InputLabelProps={{ shrink: true }} // This will prevent the overlap /> + + + {isOpeningTag && (