diff --git a/src/app/(routes)/admin/jobs/[jobId]/page.tsx b/src/app/(routes)/admin/jobs/[jobId]/page.tsx index 8795d2ec..88c1f3b0 100644 --- a/src/app/(routes)/admin/jobs/[jobId]/page.tsx +++ b/src/app/(routes)/admin/jobs/[jobId]/page.tsx @@ -18,8 +18,8 @@ import { fetchJobById } from "@/helpers/api"; import Loader from "@/components/Loader/loader"; import toast from "react-hot-toast"; import JobCoordinatorForm from "@/components/Admin/AddForms"; -import { fetchCompany, fetchRecruiterData, fetchFaculties, postFacultyApproval } from "@/helpers/api"; -import { assignCompany, postCompany, assignRecruiter, postRecruiter, fetchApprovals } from "@/helpers/api"; +import { fetchRecruiterData, fetchFaculties, postFacultyApproval } from "@/helpers/api"; +import { postCompany, postRecruiter, fetchApprovals } from "@/helpers/api"; import Select from "react-select"; const currentStatusOptions = [ "INITIALIZED", @@ -46,14 +46,6 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => { const [facultyApprovals, setFacultyApprovals] = useState([]); const [selectedFaculties, setSelectedFaculties] = useState([]); const [facultyDropDown, setFacultyDropdown] = useState([false]); - const [companyData, setCompanyData] = useState(null); - const [recruiterData, setRecruiterData] = useState(null); - const [companyDropDown, setcompanyDropDown] = useState(false); - const [recruiterDropDown, setrecruiterDropDown] = useState(false); - const [selectedCompany, setSelectedCompany] = useState(null); - const [selectedRecruiter, setSelectedRecruiter] = useState(null); - const [toggleCompanyModal, setToggleCompanyModal] = useState(false); - const [toggleRecruiterModal, setToggleRecruiterModal] = useState(false); const [approvalModal, setApprovalModal] = useState(false); const [companyFormData, setCompanyFormData] = useState({ name: '', @@ -91,11 +83,10 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => { const fetchData = async () => { try { - const [jobDetailData, jafDetailsData, companyData, recruiterData, facultyData] = + const [jobDetailData, jafDetailsData, recruiterData, facultyData] = await Promise.all([ fetchJobById(params.jobId), getJafDetails(), - fetchCompany(), fetchRecruiterData(), fetchFaculties(), ]); @@ -104,44 +95,7 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => { setData(jobDetailData); setFormData(jobDetailData); setFacultyData(facultyData); - setCompanyData(companyData); - setRecruiterData(recruiterData); - setRecruiterFormData({ - designation: jobDetailData.recruiterDetailsFilled.designation, - landline: jobDetailData.recruiterDetailsFilled.landline, - companyId: jobDetailData.company.id, // Assuming you have a companyId in jobDetailData - user: { - name: jobDetailData.recruiterDetailsFilled.name, - email: jobDetailData.recruiterDetailsFilled.email, - contact: jobDetailData.recruiterDetailsFilled.contact - } - }); - setCompanyFormData({ - name: jobDetailData.companyDetailsFilled.name, - size: jobDetailData.companyDetailsFilled.size, - category: jobDetailData.companyDetailsFilled.category, - yearOfEstablishment: jobDetailData.companyDetailsFilled.yearOfEstablishment, - website: jobDetailData.companyDetailsFilled.website, - annualTurnover: jobDetailData.companyDetailsFilled.annualTurnover || '', - socialMediaLink: jobDetailData.companyDetailsFilled.socialMediaLink || '', - address: { - line1: jobDetailData.companyDetailsFilled.address.line1 || '', - line2: jobDetailData.companyDetailsFilled.address.line2 || '', - city: jobDetailData.companyDetailsFilled.address.city || '', - state: jobDetailData.companyDetailsFilled.address.state || '', - country: jobDetailData.companyDetailsFilled.address.country || '' - }, - domains: jobDetailData.companyDetailsFilled.domains || [''] - }); - - const matchedCompany = companyData.find( - (company) => company.id === jobDetailData.company.id, - ); - setSelectedCompany(matchedCompany); - const matchedRecruiter = recruiterData.find( - (recruiter) => recruiter.id === jobDetailData.recruiter.id, - ); - setSelectedRecruiter(matchedRecruiter); + } catch (error) { toast.error("Error fetching data"); } finally { @@ -151,104 +105,6 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => { fetchData(); }, [params.jobId]); - const handleCompanyFormChange = (e) => { - const { name, value } = e.target; - setCompanyFormData((prevFormData) => ({ - ...prevFormData, - [name]: value, - })); - }; - - const handleRecruiterFormChange = (e) => { - const { name, value } = e.target; - const [mainKey, subKey] = name.split('.'); - - if (subKey) { - setRecruiterFormData((prevFormData) => ({ - ...prevFormData, - [mainKey]: { - ...prevFormData[mainKey], - [subKey]: value - } - })); - } else { - setRecruiterFormData((prevFormData) => ({ - ...prevFormData, - [name]: value - })); - } - }; - - const handleCompanyFormSubmit = async () => { - try { - await postCompany([{ - name: companyFormData.name, - category: companyFormData.category, - yearOfEstablishment: companyFormData.yearOfEstablishment, - website: companyFormData.website, - size: companyFormData.size, - annualTurnover: companyFormData.annualTurnover, - socialMediaLink: "companyFormData.socialMediaLink", - domains: companyFormData.domains, - address: { - line1: companyFormData.address.line1, - line2: companyFormData.address.line2, - city: companyFormData.address.city, - state: companyFormData.address.state, - country: companyFormData.address.country - } - }]); - toast.success("Company details updated successfully!"); - window.location.reload(); - } catch (error) { - toast.error("Error updating company details"); - } - }; - - const handleRecruiterFormSubmit = async () => { - try { - await postRecruiter([{ - designation: recruiterFormData.designation, - landline: recruiterFormData.landline, - companyId: recruiterFormData.companyId, - user: { - name: recruiterFormData.user.name, - email: recruiterFormData.user.email, - contact: recruiterFormData.user.contact - } - }]); - toast.success("Recruiter details updated successfully!"); - window.location.reload(); - } catch (error) { - toast.error("Error updating recruiter details"); - } - }; - const handleToggleModal = (type) => { - if (type === "company") { - setToggleCompanyModal(prevState => !prevState); - } else if (type === "recruiter") { - setToggleRecruiterModal(prevState => !prevState); - } - }; - const toggleDropdown = (state: string) => { - if (state === "company") { - setcompanyDropDown(!companyDropDown); - setrecruiterDropDown(false); - } else { - setrecruiterDropDown(!recruiterDropDown); - setcompanyDropDown(false); - } - }; - - const handleCompanySelect = (company) => { - setSelectedCompany(company); - setcompanyDropDown(false); - }; - const handleRecruiterSelect = (recruiter) => { - setSelectedRecruiter(recruiter); - setrecruiterDropDown(false); - }; - const updateFacultyDropDown = (index, value) => { setFacultyDropdown(prevState => { const newState = [...prevState]; @@ -260,7 +116,7 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => { const submitApproval = async (salaryIndex) => { const selected = selectedFaculties[salaryIndex] || []; const res = await postFacultyApproval(job.salaries[salaryIndex].id, selected); - if(res) toast.success("Request Sent"); + if (res) toast.success("Request Sent"); else toast.error("Error Sending Request"); updateFacultyDropDown(salaryIndex, false); }; @@ -358,26 +214,26 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => { )}