From 07065fc171a0cec882e78c52ff2d800a8c16ba90 Mon Sep 17 00:00:00 2001 From: princekumarofficial Date: Thu, 11 Jul 2024 15:21:15 +0530 Subject: [PATCH] Make Offer feature --- src/components/Admin/JobEvents.tsx | 203 +++++++++++++++++++++++++---- src/dto/SalaryDto.ts | 38 ++++++ src/helpers/api.ts | 20 +++ src/helpers/recruiter/types.ts | 1 + 4 files changed, 235 insertions(+), 27 deletions(-) create mode 100644 src/dto/SalaryDto.ts diff --git a/src/components/Admin/JobEvents.tsx b/src/components/Admin/JobEvents.tsx index f1c4b74c..feb6916e 100644 --- a/src/components/Admin/JobEvents.tsx +++ b/src/components/Admin/JobEvents.tsx @@ -1,15 +1,23 @@ "use client"; -import React, { use } from "react"; +import React from "react"; import { useState, useEffect } from "react"; -import { EventFC, ApplicationFC } from "@/helpers/recruiter/types"; -import { CircularProgress, Modal } from "@mui/material"; +import { EventFC, ApplicationFC, SalaryFC } from "@/helpers/recruiter/types"; +import { CircularProgress, Modal, Typography } from "@mui/material"; import { getResume } from "@/helpers/recruiter/api"; import VerifiedIcon from "@mui/icons-material/Verified"; -import { addEvent, fetchEventById, promoteStudent } from "@/helpers/api"; +import { + addEvent, + fetchEventById, + getStudentSalaryOffers, + postOnCampusOffer, + promoteStudent, +} from "@/helpers/api"; import { Button } from "../ui/button"; import toast from "react-hot-toast"; import Select from "react-select"; import { Unstable_NumberInput as NumberInput } from "@mui/base/Unstable_NumberInput"; +import Table from "../NewTableComponent/Table"; +import generateColumns from "../NewTableComponent/ColumnMapping"; const typeOptions = [ "POLL", @@ -191,7 +199,7 @@ const PromoteStudent = ({ onClose: () => void; events: EventFC[]; }) => { - const [roundNumber, setRoundNumber] = useState(); + const [roundNumber, setRoundNumber] = useState(0); const studentIds = students.map((student) => student.id); const [eventId, setEventId] = useState(); useEffect(() => { @@ -207,6 +215,7 @@ const PromoteStudent = ({ const updateEvent = async () => { await promoteStudent({ studentIds }, eventId); toast.success("Successfully promoted!"); + onClose(); }; return ( @@ -256,6 +265,107 @@ const PromoteStudent = ({ ); }; +const MakeJobOfferModal = ({ + open, + students, + onClose, + events, + lastEvent, +}: { + open: boolean; + students: any[]; + onClose: () => void; + events: EventFC[]; + lastEvent: EventFC; +}) => { + const studentIds = students.map((student) => student.id); + const [salaries, setSalaries] = useState(); + const columns = generateColumns([ + { + select: "", + baseSalary: 0, + totalCTC: 0, + takeHomeSalary: 0, + grossSalary: 0, + otherCompensations: 0, + salaryPeriod: "string", + job: { + role: "string", + company: { + name: "string", + }, + }, + }, + ]); + console.log(columns); + + const makeOffer = async (salaryId: string) => { + await postOnCampusOffer([ + { + salaryId: salaryId, + studentId: studentIds[0], + status: "ACCEPTED", + }, + ]); + toast.success("Made a successful offer!"); + window.location.reload(); + }; + + useEffect(() => { + const fetchSalaries = async () => { + const salaries = await getStudentSalaryOffers( + lastEvent.job.id, + studentIds[0] + ); + const newSalaries = salaries.map((salary) => ({ + select: ( + + ), + ...salary, + })); + console.log(newSalaries); + setSalaries(newSalaries); + }; + fetchSalaries(); + }, []); + + return ( + +
+
+ + Select Salary + + {salaries ? ( +
+ + + ) : ( +
+ +
+ )} + + + + ); +}; + export const JobEvents = ({ events }: { events: [EventFC] }) => { const [eventId, setEventId] = useState(null); @@ -338,6 +448,16 @@ export const Applications = ({ events: EventFC[]; }) => { const [applications, setApplications] = useState<[ApplicationFC]>(null); + var lastEvent: EventFC; + events.forEach((event) => { + if (lastEvent) { + if (lastEvent.roundNumber < event.roundNumber) { + lastEvent = event; + } + } else { + lastEvent = event; + } + }); const [loading, setLoading] = useState(true); const [promoteStudents, setPromoteStudents] = useState([]); const [seed, setSeed] = useState(0); @@ -361,15 +481,28 @@ export const Applications = ({ return (
- 0} - students={promoteStudents} - onClose={() => { - setPromoteStudents([]); - setSeed(seed + 1); - }} - events={events} - /> + {lastEvent.id == eventId && promoteStudents.length > 0 ? ( + 0} + students={promoteStudents} + onClose={() => { + setPromoteStudents([]); + setSeed(seed + 1); + }} + events={events} + lastEvent={lastEvent} + /> + ) : ( + 0} + students={promoteStudents} + onClose={() => { + setPromoteStudents([]); + setSeed(seed + 1); + }} + events={events} + /> + )} {loading && (
@@ -418,19 +551,35 @@ export const Applications = ({ {application.resume.verified && }
))} diff --git a/src/dto/SalaryDto.ts b/src/dto/SalaryDto.ts new file mode 100644 index 00000000..06b5d22d --- /dev/null +++ b/src/dto/SalaryDto.ts @@ -0,0 +1,38 @@ +const salaryDto = { + id: "string", + baseSalary: 0, + totalCTC: 0, + takeHomeSalary: 0, + grossSalary: 0, + otherCompensations: 0, + salaryPeriod: "string", + job: { + id: "string", + role: "string", + company: { + id: "string", + name: "string", + }, + season: { + id: "string", + year: "string", + type: "INTERN", + }, + salaries: [ + { + id: "string", + totalCTC: 0, + salaryPeriod: "string", + genders: ["MALE"], + programs: ["string"], + facultyApprovals: ["Astronomy, Astrophysics and Space Engineering"], + categories: ["GENERAL"], + minCPI: 0, + tenthMarks: 0, + twelthMarks: 0, + }, + ], + }, +}; + +export { salaryDto }; diff --git a/src/helpers/api.ts b/src/helpers/api.ts index eeddb773..0a6c862b 100644 --- a/src/helpers/api.ts +++ b/src/helpers/api.ts @@ -328,3 +328,23 @@ export const patchResumeVerify = async (changes: ResumePatchData[]) => { body: changes, }); }; + +export const getStudentSalaryOffers = async ( + jobId: string, + studentId: string +) => { + return apiCall(`/on-campus-offers/salaries/${jobId}/student/${studentId}`); +}; + +export const postOnCampusOffer = async ( + body: { + salaryId: string; + studentId: string; + status: string; + }[] +) => { + return apiCall(`/on-campus-offers/`, { + method: "POST", + body: body, + }); +}; diff --git a/src/helpers/recruiter/types.ts b/src/helpers/recruiter/types.ts index 96123561..4ca85ad7 100644 --- a/src/helpers/recruiter/types.ts +++ b/src/helpers/recruiter/types.ts @@ -32,6 +32,7 @@ export interface EventFC { startDateTime: string; endDateTime: string; applications?: [ApplicationFC]; + job?: JobDetailFC; } export interface JAFdetailsFC {
- + {lastEvent.id == eventId ? ( + + ) : ( + + )}