Skip to content

Commit

Permalink
Merge pull request #345 from sandeep14k/master-resume
Browse files Browse the repository at this point in the history
daedline field for notice containing opening tag
  • Loading branch information
yashlm authored Oct 9, 2024
2 parents 6e21620 + 78c1f87 commit e401537
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 34 deletions.
1 change: 1 addition & 0 deletions callbacks/admin/rc/notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface NoticeParams {
created_by: string;
CreatedAt: string;
last_reminder_at: number;
deadline: string;
}
export interface NoticeResponse {
title: string;
Expand Down
96 changes: 63 additions & 33 deletions components/Modals/EditRCNotices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function EditNotice({
created_by: "",
CreatedAt: "",
last_reminder_at: 0,
deadline: "",
});
const [isFetched, setisFetched] = useState(false);

Expand All @@ -68,27 +69,19 @@ function EditNotice({
formState: { errors },
reset,
} = useForm<NoticeResponse>();
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();
};

Expand All @@ -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 (
<Box sx={boxStyle}>
<Stack spacing={3}>
<h2>Edit Notice</h2>
<FormControl sx={{ m: 1 }}>
<InputLabel id="edit-student">Select ID</InputLabel>
<InputLabel id="edit-notice">Select ID</InputLabel>
<Select
label="ID"
id="ID"
Expand All @@ -127,7 +131,9 @@ function EditNotice({
}}
>
{notices.map((notice: NoticeParams) => (
<MenuItem value={notice.ID}>{notice.ID}</MenuItem>
<MenuItem key={notice.ID} value={notice.ID}>
{notice.ID}
</MenuItem>
))}
</Select>
</FormControl>
Expand All @@ -136,17 +142,41 @@ 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"}
InputLabelProps={{ shrink: true }} // This will prevent the overlap
/>

<TextField
label="Published Date and Time"
variant="standard"
value={publishedDateAndTime}
InputProps={{
readOnly: true,
}}
InputLabelProps={{ shrink: true }} // This will prevent the overlap
/>

<TextField
label="Tags (csv)"
id="tags"
variant="filled"
{...register("tags", { required: true })}
error={!!errors.tags}
helperText={errors.tags && "Tags are required"}
InputLabelProps={{ shrink: true }} // This will prevent the overlap
/>

{isOpeningTag && (
<TextField
label="Deadline"
variant="standard"
value={deadlineDate}
InputProps={{
readOnly: true,
}}
/>
)}
<small style={{ fontWeight: 300 }}>Description</small>
{isFetched && (
<RichTextEditor onChange={setDescription} value={description} />
Expand Down
20 changes: 19 additions & 1 deletion components/Modals/ViewNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Box sx={boxStyle} className="modalScroll">
<Stack spacing={3}>
Expand Down Expand Up @@ -55,6 +62,17 @@ function ViewNotice({ currentNotice }: { currentNotice: NoticeParams }) {
readOnly: true,
}}
/>
{isOpeningTag && (
<TextField
multiline
label="Deadline"
defaultValue={deadlineDate}
variant="standard"
InputProps={{
readOnly: true,
}}
/>
)}
<small style={{ fontWeight: 300 }}>Description</small>
<RichText
// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
1 change: 1 addition & 0 deletions pages/admin/rc/[rcid]/notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function Index() {
created_by: "",
CreatedAt: "",
last_reminder_at: 0,
deadline: "",
});

const [openView, setOpenView] = useState(false);
Expand Down
1 change: 1 addition & 0 deletions pages/student/rc/[rcid]/notices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function Notices() {
created_by: "",
CreatedAt: "",
last_reminder_at: 0,
deadline: "",
});

useEffect(() => {
Expand Down

0 comments on commit e401537

Please sign in to comment.