From 7dcd351e3473d584b2e15ece8c616364beaaf535 Mon Sep 17 00:00:00 2001 From: Jai Pannu <142983705+JaiPannu-IITI@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:06:29 +0530 Subject: [PATCH] Api fix (#118) Co-authored-by: Ishaan Mittal --- src/app/(authroutes)/login/layout.tsx | 6 - .../passwordless/[token]/page.tsx | 2 - .../admin/companies/allcompanies/page.tsx | 3 +- .../(routes)/admin/jobs/[...filter]/page.tsx | 4 +- src/app/(routes)/admin/jobs/[jobId]/page.tsx | 15 +- src/app/(routes)/admin/jobs/loading.tsx | 1 - src/app/(routes)/admin/jobs/page.tsx | 8 +- src/app/(routes)/admin/recruiters/page.tsx | 11 +- src/app/(routes)/admin/resumes/page.tsx | 1 - .../admin/students/[...filter]/page.tsx | 3 +- src/app/(routes)/admin/students/page.tsx | 15 +- src/app/layout.tsx | 3 +- src/components/NewTableComponent/JobModal.jsx | 4 +- .../NewTableComponent/NewJobModal.tsx | 9 +- .../NewTableComponent/PenaltyModal.jsx | 10 +- .../NewTableComponent/RecruiterModal.jsx | 6 +- .../NewTableComponent/StudentModal.tsx | 87 ++--- src/components/SideBar/Roles/admin.tsx | 6 +- src/components/SideBar/Roles/student.tsx | 5 +- .../TableComponent/TableComponent.tsx | 2 - .../company/AllCompaniesComponent.tsx | 7 +- src/components/jobs/AddEventDialog.tsx | 26 +- src/components/jobs/JobDeleteModal.tsx | 32 +- src/components/loginForms/loginForm.tsx | 48 +-- src/components/loginForms/loginWithEmail.tsx | 35 +- src/helpers/api.ts | 350 ++++++++---------- src/helpers/auth.ts | 1 - 27 files changed, 264 insertions(+), 436 deletions(-) diff --git a/src/app/(authroutes)/login/layout.tsx b/src/app/(authroutes)/login/layout.tsx index e9f47ab6..92081d42 100644 --- a/src/app/(authroutes)/login/layout.tsx +++ b/src/app/(authroutes)/login/layout.tsx @@ -4,12 +4,6 @@ interface Props { children: React.ReactNode; } -async function getAuth() { - const res = await fetch("/api/auth"); - const json = await res.json(); - return json; -} - const LoginModalLayout = ({ children }: Props) => { return ( <> diff --git a/src/app/(authroutes)/passwordless/[token]/page.tsx b/src/app/(authroutes)/passwordless/[token]/page.tsx index 9514eb0d..a5657904 100644 --- a/src/app/(authroutes)/passwordless/[token]/page.tsx +++ b/src/app/(authroutes)/passwordless/[token]/page.tsx @@ -5,9 +5,7 @@ import React, { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import Cookies from "js-cookie"; import { jwtDecode } from "jwt-decode"; -import loadingImg from "@/components/Faculty/loadingSpinner.svg"; import Loader from "@/components/Loader/loader"; -interface Props {} const LoginPage = ({ params, diff --git a/src/app/(routes)/admin/companies/allcompanies/page.tsx b/src/app/(routes)/admin/companies/allcompanies/page.tsx index e4118dd0..18ae5ba3 100644 --- a/src/app/(routes)/admin/companies/allcompanies/page.tsx +++ b/src/app/(routes)/admin/companies/allcompanies/page.tsx @@ -1,5 +1,4 @@ import CompanyCard from "@/components/company/CompanyCard"; -import { cookies } from "next/headers"; import { fetchCompany } from "@/helpers/api"; import { ChevronRight } from "lucide-react"; import { ChevronLeft } from "lucide-react"; @@ -15,7 +14,7 @@ interface company { } const CompanyPage = async () => { - const Companies = await fetchCompany(cookies()?.get("accessToken")?.value); + const Companies = await fetchCompany(); if (Companies?.length === 0) { return ( diff --git a/src/app/(routes)/admin/jobs/[...filter]/page.tsx b/src/app/(routes)/admin/jobs/[...filter]/page.tsx index b827f354..90232d89 100644 --- a/src/app/(routes)/admin/jobs/[...filter]/page.tsx +++ b/src/app/(routes)/admin/jobs/[...filter]/page.tsx @@ -1,9 +1,7 @@ "use client"; import { fetchAllJobs } from "@/helpers/api"; -import Cookies from "js-cookie"; import TableComponent from "@/components/TableComponent/TableComponent"; import generateColumns from "@/components/TableComponent/ColumnMapping"; -import { useRouter } from "next/router"; import { useEffect, useState } from "react"; @@ -39,7 +37,7 @@ const StudentPage = ({ params }: any) => { const decodedParams = decodeURIComponent(params.filter[0]); console.log(decodedParams) const AllFilteredJobs = await fetchAllJobs( - Cookies.get("accessToken"), + decodedParams, ); setJobs(AllFilteredJobs); diff --git a/src/app/(routes)/admin/jobs/[jobId]/page.tsx b/src/app/(routes)/admin/jobs/[jobId]/page.tsx index 5057bba0..ecc4001f 100644 --- a/src/app/(routes)/admin/jobs/[jobId]/page.tsx +++ b/src/app/(routes)/admin/jobs/[jobId]/page.tsx @@ -14,8 +14,7 @@ import { CategorySelectList, GenderSelectList, } from "@/components/Recruiters/jobEdit"; -import { fetchEachJob } from "@/helpers/api"; -import Cookies from "js-cookie"; +import { fetchJobById } from "@/helpers/api"; import Loader from "@/components/Loader/loader"; import toast from "react-hot-toast"; import JobCoordinatorForm from "@/components/Admin/AddForms"; @@ -23,7 +22,7 @@ import { fetchCompany,fetchRecruiterData } from "@/helpers/api"; import { assignCompany,assignRecruiter } from "@/helpers/api"; const JobDetailPage = ({ params }: { params: { jobId: string } }) => { - const accessToken = Cookies.get("accessToken"); + const [job, setData] = useState(null); const [loading, setLoading] = useState(true); const [editMode, setEditMode] = useState(false); @@ -40,10 +39,10 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => { const fetchData = async () => { try { const [jobDetailData, jafDetailsData, companyData, recruiterData] = await Promise.all([ - fetchEachJob(accessToken, params.jobId), + fetchJobById(params.jobId), getJafDetails(), - fetchCompany(accessToken), - fetchRecruiterData(accessToken, null), + fetchCompany(), + fetchRecruiterData(), ]); setJafDetails(jafDetailsData); @@ -334,7 +333,7 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => {