diff --git a/src/app/(routes)/admin/jobs/events/[jobId]/page.tsx b/src/app/(routes)/admin/jobs/events/[jobId]/page.tsx index b85473a5..e5564073 100644 --- a/src/app/(routes)/admin/jobs/events/[jobId]/page.tsx +++ b/src/app/(routes)/admin/jobs/events/[jobId]/page.tsx @@ -5,7 +5,7 @@ import { JobEvents } from "@/components/Admin/JobEvents"; import { fetchJobEvents } from "@/helpers/api"; import { EventFC } from "@/helpers/recruiter/types"; import { Button } from "@/components/ui/button"; -import { AddEvent } from "@/components/Admin/JobEvents"; +import { AddEvent,EditEvent } from "@/components/Admin/JobEvents"; import Loader from "@/components/Loader/loader"; import toast from "react-hot-toast"; @@ -13,6 +13,8 @@ const EventsPage = ({ params }: { params: { jobId: string } }) => { const [events, setData] = useState<[EventFC]>(null); const [loading, setLoading] = useState(true); const [addEventForm, setAddEventForm] = useState(false); + const [editEventForm, setEditEventForm] = useState(false); + const [editEventId, setEditEventId] = useState(null); useEffect(() => { const fetchData = async () => { @@ -33,6 +35,14 @@ const EventsPage = ({ params }: { params: { jobId: string } }) => {

Events And Applications

+ {editEventForm && editEventId && ( + + )} {addEventForm && ( { jobId={params.jobId} /> )} -
+
+ {editEventId && ( + + )} +
{loading && (
@@ -56,7 +76,7 @@ const EventsPage = ({ params }: { params: { jobId: string } }) => { )} {events && (
- +
)}
diff --git a/src/components/Admin/JobEvents.tsx b/src/components/Admin/JobEvents.tsx index 36d4e4e7..0f344865 100644 --- a/src/components/Admin/JobEvents.tsx +++ b/src/components/Admin/JobEvents.tsx @@ -11,6 +11,7 @@ import { getStudentSalaryOffers, postOnCampusOffer, promoteStudent, + updateEvent } from "@/helpers/api"; import { Button } from "../ui/button"; import toast from "react-hot-toast"; @@ -33,6 +34,210 @@ const options = typeOptions.map((option) => ({ label: option, })); +export const EditEvent = ({ + open, + setOpen, + eventId, + jobId +}: { + open: boolean; + setOpen: (open: boolean) => void; + eventId: string; + jobId: string; +}) => { + const [formValues, setFormValues] = useState({ + id: "", + jobId: "", + roundNumber: 0, + type: "", + metadata: "", + startDateTime: "", + endDateTime: "", + visibleToRecruiter: false, + }); +const [loading, setLoading] = useState(true); + useEffect(() => { + if (eventId && open) { + fetchEventData(); + + } + + }, [eventId, open]); + + const fetchEventData = async () => { + try { + const eventData = await fetchEventById(eventId); + setFormValues({ + id: eventData.id, + jobId: jobId, + roundNumber: eventData.roundNumber, + type: eventData.type, + metadata: eventData.metadata, + startDateTime: new Date(eventData.startDateTime).toISOString().slice(0, 16), + endDateTime: new Date(eventData.endDateTime).toISOString().slice(0, 16), + visibleToRecruiter: eventData.visibleToRecruiter, + }); + setLoading(false); + } catch { + toast.error("Failed to fetch event details."); + } + }; + + const handleClose = () => setOpen(false); + + const handleChange = (e: React.ChangeEvent) => { + const { name, value, type, checked } = e.currentTarget; + setFormValues({ + ...formValues, + [name]: type === "checkbox" ? checked : value, + }); + }; + + + const convertToISOFormat = (date: string) => { + return new Date(date).toISOString(); + }; + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + try { + + const updatedValues = { + ...formValues, + startDateTime: convertToISOFormat(formValues.startDateTime), + endDateTime: convertToISOFormat(formValues.endDateTime), + }; + + await updateEvent([updatedValues]); + toast.success("Successfully updated the event"); + window.location.reload(); + } catch (error: any) { + console.error("API Error:", error.response?.data || error.message); + } + + }; + + return ( + + +
+ {loading && ( +
+ +
+ )} + + {!loading &&(
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+ )} +
+
+ ); +}; + export const AddEvent = ({ open, setOpen, @@ -368,7 +573,7 @@ const MakeJobOfferModal = ({ ); }; -export const JobEvents = ({ events }: { events: [EventFC] }) => { +export const JobEvents = ({ events, editEventID, setEditEventId }: { events: EventFC[], editEventID: string, setEditEventId: (id: string) => void }) => { const [eventId, setEventId] = useState(null); const changeApplications = (eventId: string) => { @@ -408,6 +613,7 @@ export const JobEvents = ({ events }: { events: [EventFC] }) => { : `bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-600` } border-b dark:border-gray-700`} onClick={() => { + setEditEventId(event.id); changeApplications(event.id); }} > diff --git a/src/helpers/api.ts b/src/helpers/api.ts index c1579331..8f4943f7 100644 --- a/src/helpers/api.ts +++ b/src/helpers/api.ts @@ -545,6 +545,27 @@ export const createJobEvent = async ( }); }; +export const updateEvent = async ( + body: +[ + { + id: string; + jobId: string; + roundNumber: number; + type: string; + metadata: string; + startDateTime: string; + endDateTime: string; + visibleToRecruiter: boolean; + }] +) => { + return apiCall(`/events`, { + method: "PATCH", + body: body, + }); +}; + + export const login = async (email: string, role: string) => { const response = await apiCall("/auth/login/", { method: "POST",