From 130b39d7266a13f2a537e2c7c1e09ac0de744cf0 Mon Sep 17 00:00:00 2001 From: JaiPannu-IITI Date: Sat, 13 Jul 2024 22:22:09 +0530 Subject: [PATCH 01/18] Api fix --- src/helpers/api.ts | 174 +++++++++++---------------------------------- 1 file changed, 40 insertions(+), 134 deletions(-) diff --git a/src/helpers/api.ts b/src/helpers/api.ts index 67b390fd..81a52ae9 100644 --- a/src/helpers/api.ts +++ b/src/helpers/api.ts @@ -1,10 +1,10 @@ -const redirect = () => {}; -const baseUrl = process.env.NEXT_PUBLIC_BACKEND_URL; -process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; import qs from "qs"; import Cookies from "js-cookie"; import { ResumePatchData } from "./types"; +const baseUrl = process.env.NEXT_PUBLIC_BACKEND_URL; +process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; + interface ApiCallOptions { method?: string; isAuth?: boolean; @@ -14,14 +14,13 @@ interface ApiCallOptions { formData?: FormData; } -export const url = (NextUrl: string) => { - return `${baseUrl}/api/v1${NextUrl}`; -}; +const redirect = () => { -export const getUrl = (NextUrl: string) => { - return `${baseUrl}/api/v1${NextUrl}`; }; +export const url = (NextUrl: string) => { return `${baseUrl}/api/v1${NextUrl}`; }; +export const getUrl = (NextUrl: string) => { return `${baseUrl}/api/v1${NextUrl}`;}; + export const apiCall = async ( path: string, { @@ -39,7 +38,7 @@ export const apiCall = async ( return; } - let url = getUrl(path); + let requestUrl = getUrl(path); const headers: HeadersInit = {}; @@ -64,7 +63,7 @@ export const apiCall = async ( encodeValuesOnly: true, encode: false, }); - url += `?${encodedQueryString}`; + requestUrl += `?${encodedQueryString}`; } if (isAuth) { @@ -77,22 +76,25 @@ export const apiCall = async ( req["next"] = next; } - const res = await fetch(url, req); + const res = await fetch(requestUrl, req); + if (method === "GET") { return await res.json(); - } else return res.ok; + } else{ + return res.ok + }; }; -export const OpenFile = async ( - path: string, - { method = "GET", isAuth = true, next = null }: ApiCallOptions = {} -) => { + +export const OpenFile = async (path: string, options: ApiCallOptions = {}) => { + const { method = "GET", isAuth = true, next = null } = options; + const accessToken = Cookies.get("accessToken"); if ((!accessToken || accessToken === undefined) && isAuth) { redirect(); return; } - let url = getUrl(path); + let requestUrl = getUrl(path); const headers: HeadersInit = {}; @@ -110,11 +112,11 @@ export const OpenFile = async ( req["next"] = next; } - fetch(url, req) + fetch(requestUrl, req) .then((response) => response.blob()) .then((blob) => { - const url = window.URL.createObjectURL(blob); - window.open(url); + const fileUrl = window.URL.createObjectURL(blob); + window.open(fileUrl); }) .catch((error) => console.error("Error:", error)); }; @@ -136,169 +138,73 @@ export const PasswordlessLogin = async (accessToken: string | undefined) => { }; export const fetchAllSeasons = async (accessToken: string | undefined) => { - if (!accessToken || accessToken === undefined) { - redirect(); - return; - } - const res = await fetch(url("/seasons"), { - headers: { - Authorization: `Bearer ${accessToken}`, - }, - }); - const json = await res.json(); - return json; + return apiCall("/seasons"); }; export const fetchCompany = async (accessToken: string | undefined) => { - if (!accessToken || accessToken === undefined) { - redirect(); - return; - } - const res = await fetch(url("/companies"), { - headers: { - Authorization: `Bearer ${accessToken}`, - }, - }); - const json = await res.json(); - return json; + return apiCall("/companies"); }; export const fetchAllJobs = async ( accessToken: string | undefined, filter: string | undefined ) => { - if (!accessToken || accessToken === undefined) { - redirect(); - return; - } - const res = await fetch(filter ? url(`/jobs?${filter}`) : url("/jobs"), { + return apiCall(filter ? `/jobs?${filter}` : "/jobs", { + next: { tags: ["AllJobs"] }, - headers: { - Authorization: `Bearer ${accessToken}`, - }, }); - const json = await res.json(); - return json; - // return SampleJobData }; export const fetchStudentData = async ( accessToken: string | undefined, filter: string | undefined ) => { - if (!accessToken || accessToken === undefined) { - redirect(); - return; - } - const res = await fetch( - filter ? url(`/students?${filter}`) : url("/students"), - { - next: { tags: ["AllStudents"] }, - headers: { - Authorization: `Bearer ${accessToken}`, - }, - } - ); - const json = await res.json(); - return json; + return apiCall(filter ? `/students?${filter}` : "/students", { + + next: { tags: ["AllStudents"] }, + }); }; export const fetchCompanyRecruiters = async ( accessToken: string | undefined, companyId: string | undefined ) => { - if (!accessToken || accessToken === undefined) { - redirect(); - return; - } - const res = await fetch(`${url("/companies")}/${companyId}/recruiters/`, { - next: { - tags: ["AllRecruiters"], - }, - headers: { - Authorization: `Bearer ${accessToken}`, - }, + return apiCall(`/companies/${companyId}/recruiters/`, { + + next: { tags: ["AllRecruiters"] }, }); - const json = await res.json(); - return json; }; export const fetchJobSalary = async ( accessToken: string | undefined, jobId: string | undefined ) => { - if (!accessToken || accessToken === undefined) { - redirect(); - return; - } - const res = await fetch(`${url("/jobs")}/${jobId}/salary/`, { - headers: { - Authorization: `Bearer ${accessToken}`, - }, - }); - const json = await res.json(); - return json; + return apiCall(`/jobs/${jobId}/salary/`); }; export const fetchEachJob = async ( accessToken: string | undefined, jobId: any ) => { - if (!accessToken || accessToken === undefined) { - redirect(); - return; - } - const res = await fetch(`${url("/jobs")}/${jobId}`, { - headers: { - Authorization: `Bearer ${accessToken}`, - }, - }); - - const json = await res.json(); - return json; + return apiCall(`/jobs/${jobId}`); }; export const fetchJobEvents = async ( accessToken: string | undefined, jobId: any ) => { - if (!accessToken || accessToken === undefined) { - redirect(); - return; - } - const res = await fetch(`${url("/jobs")}/${jobId}/events`, { - next: { - tags: ["AllEvents"], - }, - headers: { - Authorization: `Bearer ${accessToken}`, - }, + return apiCall(`/jobs/${jobId}/events`, { + next: { tags: ["AllEvents"] }, }); - - const json = await res.json(); - return json; }; export const fetchRecruiterData = async ( accessToken: string | undefined, filter: string | undefined ) => { - if (!accessToken || accessToken === undefined) { - redirect(); - return; - } - console.log("filter", filter); - const res = await fetch( - filter ? url(`/recruiters?${filter}`) : url("/recruiters"), - { - next: { tags: ["AllRecruiters"] }, - headers: { - Authorization: `Bearer ${accessToken}`, - }, - } - ); - const json = await res.json(); - return json; + return apiCall(filter ? `/recruiters?${filter}` : "/recruiters", { + next: { tags: ["AllRecruiters"] }, + }); }; export const fetchResumes = async () => { From cb98f90bc1ec4a47b7270d2944312f1ed02de07c Mon Sep 17 00:00:00 2001 From: JaiPannu-IITI Date: Sat, 13 Jul 2024 22:52:58 +0530 Subject: [PATCH 02/18] Used helper to make calls in pages --- src/app/(authroutes)/login/layout.tsx | 11 ++++-- src/components/NewTableComponent/JobModal.jsx | 4 +-- .../NewTableComponent/PenaltyModal.jsx | 9 ++--- .../NewTableComponent/RecruiterModal.jsx | 6 ++-- src/components/loginForms/loginWithEmail.tsx | 35 +++++++++++-------- 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/app/(authroutes)/login/layout.tsx b/src/app/(authroutes)/login/layout.tsx index e9f47ab6..14cae792 100644 --- a/src/app/(authroutes)/login/layout.tsx +++ b/src/app/(authroutes)/login/layout.tsx @@ -1,13 +1,18 @@ import React from "react"; +import { apiCall } from '@/helpers/api'; +import toast from "react-hot-toast"; interface Props { children: React.ReactNode; } async function getAuth() { - const res = await fetch("/api/auth"); - const json = await res.json(); - return json; + try { + const response = await apiCall("/auth"); + return response; + } catch (error) { + toast.error("Error Authenticating"); + } } const LoginModalLayout = ({ children }: Props) => { diff --git a/src/components/NewTableComponent/JobModal.jsx b/src/components/NewTableComponent/JobModal.jsx index 696992e0..2b0114ed 100644 --- a/src/components/NewTableComponent/JobModal.jsx +++ b/src/components/NewTableComponent/JobModal.jsx @@ -15,6 +15,7 @@ import CircularProgress from '@mui/material/CircularProgress'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import { grey } from '@mui/material/colors'; import Loader from '@/components/Loader/loader'; +import {fetchEachJob} from "@/helpers/api" const theme = createTheme({ palette: { primary: { @@ -56,8 +57,7 @@ export default function ViewJobModal({ open, setOpen, id }) { const fetchJobData = async () => { setLoading(true); try { - const response = await fetch(`${baseUrl}/api/v1/jobs/${id}`); - const data = await response.json(); + const data = await fetchEachJob(id); setJobData(data); } catch (error) { console.error('Error fetching job data:', error); diff --git a/src/components/NewTableComponent/PenaltyModal.jsx b/src/components/NewTableComponent/PenaltyModal.jsx index 1167d49e..3615122f 100644 --- a/src/components/NewTableComponent/PenaltyModal.jsx +++ b/src/components/NewTableComponent/PenaltyModal.jsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { Box, Button, Modal, TextField, Typography } from '@mui/material'; - +import {apiCall} from "@/helpers/api" const style = { position: 'absolute', top: '50%', @@ -29,12 +29,9 @@ const PenaltyModal = ({ isOpen, onClose, studentId }) => { ]; try { - const response = await fetch(`${baseUrl}/api/v1/penalties`, { + const response = await apiCall('/penalties', { method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(requestBody), + body: requestBody, }); if (response.ok) { diff --git a/src/components/NewTableComponent/RecruiterModal.jsx b/src/components/NewTableComponent/RecruiterModal.jsx index 7f8f0fff..ff483916 100644 --- a/src/components/NewTableComponent/RecruiterModal.jsx +++ b/src/components/NewTableComponent/RecruiterModal.jsx @@ -15,6 +15,7 @@ import CircularProgress from '@mui/material/CircularProgress'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import { grey } from '@mui/material/colors'; import Loader from '@/components/Loader/loader'; +import {apiCall} from "@/helpers/api" const theme = createTheme({ palette: { primary: { @@ -56,9 +57,8 @@ export default function RecruiterModal({ open, setOpen, id }) { const fetchRecruiterData = async () => { setLoading(true); try { - const response = await fetch(`${baseUrl}/api/v1/recruiters/${id}`); - const data = await response.json(); - setRecruiterData(data); + const data = await apiCall(`/recruiters/${id}`); + setRecruiterData(data); } catch (error) { console.error('Error fetching recruiter data:', error); } diff --git a/src/components/loginForms/loginWithEmail.tsx b/src/components/loginForms/loginWithEmail.tsx index 211e945b..f498a639 100644 --- a/src/components/loginForms/loginWithEmail.tsx +++ b/src/components/loginForms/loginWithEmail.tsx @@ -2,22 +2,29 @@ import React from "react"; import { url } from "../../helpers/api"; import LockImg from "@/../public/icons/lock.svg"; import toast from "react-hot-toast"; - +import { apiCall } from "@/helpers/api"; export const LoginWithEmail = (params: { email: String }) => { const onClick = async () => { - const res = await fetch(url("/auth/passwordless"), { - method: "POST", - cache: "no-store", - headers: { - "Content-type": "application/json", - }, - body: JSON.stringify({ email: params.email }), - }); - console.log(res); - const resOk = res.ok; - if (resOk) toast.success("Email Has Been Sent"); - else toast.error("Cannot Login") - return resOk; + try { + const { email } = params; + const response = await apiCall("/auth/passwordless", { + method: "POST", + body: { email }, + }); + + if (response.ok) { + toast.success("Email has been sent"); + // Optionally handle further actions upon successful response + } else { + toast.error("Cannot login"); + } + + return response.ok; + } catch (error) { + console.error("Error:", error); + toast.error("An error occurred while sending the email"); + return false; + } }; return ( From 7e84b2b539b3e15fc502bb680424e8c67a4ad7d3 Mon Sep 17 00:00:00 2001 From: JaiPannu-IITI Date: Sun, 14 Jul 2024 17:00:56 +0530 Subject: [PATCH 03/18] replaced onpage apiCalls with helpers --- src/components/NewTableComponent/JobModal.jsx | 4 +-- .../NewTableComponent/NewJobModal.tsx | 4 +-- .../NewTableComponent/PenaltyModal.jsx | 7 ++--- .../NewTableComponent/RecruiterModal.jsx | 4 +-- .../NewTableComponent/StudentModal.tsx | 30 +++++-------------- src/helpers/api.ts | 26 +++++++++++++++- 6 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/components/NewTableComponent/JobModal.jsx b/src/components/NewTableComponent/JobModal.jsx index 2b0114ed..3f4f9bda 100644 --- a/src/components/NewTableComponent/JobModal.jsx +++ b/src/components/NewTableComponent/JobModal.jsx @@ -15,7 +15,7 @@ import CircularProgress from '@mui/material/CircularProgress'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import { grey } from '@mui/material/colors'; import Loader from '@/components/Loader/loader'; -import {fetchEachJob} from "@/helpers/api" +import {fetchJobById} from "@/helpers/api" const theme = createTheme({ palette: { primary: { @@ -57,7 +57,7 @@ export default function ViewJobModal({ open, setOpen, id }) { const fetchJobData = async () => { setLoading(true); try { - const data = await fetchEachJob(id); + const data = await fetchJobById(id); setJobData(data); } catch (error) { console.error('Error fetching job data:', error); diff --git a/src/components/NewTableComponent/NewJobModal.tsx b/src/components/NewTableComponent/NewJobModal.tsx index 9e02fa82..4d208b2d 100644 --- a/src/components/NewTableComponent/NewJobModal.tsx +++ b/src/components/NewTableComponent/NewJobModal.tsx @@ -14,7 +14,7 @@ import { CategorySelectList, GenderSelectList, } from "@/components/Recruiters/jobEdit"; -import { fetchEachJob } from "@/helpers/api"; +import { fetchJobById } from "@/helpers/api"; import Cookies from "js-cookie"; import Modal from "@mui/material/Modal"; import { CircularProgress } from "@mui/material"; @@ -44,7 +44,7 @@ const JobModal = ({ const fetchData = async () => { try { const [jobDetailData, jafDetailsData] = await Promise.all([ - fetchEachJob(Cookies.get("accessToken"), jobID), + fetchJobById(Cookies.get("accessToken"), jobID), getJafDetails(), ]); diff --git a/src/components/NewTableComponent/PenaltyModal.jsx b/src/components/NewTableComponent/PenaltyModal.jsx index 3615122f..6f69691e 100644 --- a/src/components/NewTableComponent/PenaltyModal.jsx +++ b/src/components/NewTableComponent/PenaltyModal.jsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { Box, Button, Modal, TextField, Typography } from '@mui/material'; -import {apiCall} from "@/helpers/api" +import {fetchPenalties} from "@/helpers/api" const style = { position: 'absolute', top: '50%', @@ -29,10 +29,7 @@ const PenaltyModal = ({ isOpen, onClose, studentId }) => { ]; try { - const response = await apiCall('/penalties', { - method: 'POST', - body: requestBody, - }); + const response = await fetchPenalties(requestBody); if (response.ok) { console.log('Penalty submitted successfully'); diff --git a/src/components/NewTableComponent/RecruiterModal.jsx b/src/components/NewTableComponent/RecruiterModal.jsx index ff483916..22717e07 100644 --- a/src/components/NewTableComponent/RecruiterModal.jsx +++ b/src/components/NewTableComponent/RecruiterModal.jsx @@ -15,7 +15,7 @@ import CircularProgress from '@mui/material/CircularProgress'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import { grey } from '@mui/material/colors'; import Loader from '@/components/Loader/loader'; -import {apiCall} from "@/helpers/api" +import {fetchRecruiterById} from "@/helpers/api" const theme = createTheme({ palette: { primary: { @@ -57,7 +57,7 @@ export default function RecruiterModal({ open, setOpen, id }) { const fetchRecruiterData = async () => { setLoading(true); try { - const data = await apiCall(`/recruiters/${id}`); + const data = await fetchRecruiterById(id); setRecruiterData(data); } catch (error) { console.error('Error fetching recruiter data:', error); diff --git a/src/components/NewTableComponent/StudentModal.tsx b/src/components/NewTableComponent/StudentModal.tsx index 4c572108..d3b64e33 100644 --- a/src/components/NewTableComponent/StudentModal.tsx +++ b/src/components/NewTableComponent/StudentModal.tsx @@ -15,7 +15,7 @@ import CircularProgress from '@mui/material/CircularProgress'; import { createTheme, ThemeProvider } from '@mui/material/styles'; import { grey } from '@mui/material/colors'; import { Button } from '@mui/material'; - +import {fetchRegistrations} from '@/helpers/api'; import Cookies from 'js-cookie'; import Loader from '@/components/Loader/loader'; const redirect = () => {}; @@ -52,30 +52,14 @@ const style = { const baseUrl = process.env.NEXT_PUBLIC_BACKEND_URL; -const handleRegistration = async (accessToken, studentId, seasonId, currentStatus) => { - if (!accessToken) { - console.error('No access token provided'); - return; - } - +const handleRegistration = async (accessToken:any, studentId:any, seasonId:any, currentStatus:any) => { + try { - const res = await fetch(`${baseUrl}/api/v1/registrations`, { - method: 'POST', - headers: { - 'Authorization': `Bearer ${accessToken}`, - 'Content-Type': 'application/json', - }, - body: JSON.stringify([{ - studentId, - seasonId, - registered: !currentStatus - }]), - }); + const response = await fetchRegistrations(studentId, seasonId, currentStatus); - if (!res.ok) { - const errorDetails = await res.json(); - console.error(`Failed to update registration status: ${errorDetails.message}`); - throw new Error(`Failed to update registration status: ${errorDetails.message}`); + if (!response) { + console.error('Failed to update registration status'); + throw new Error('Failed to update registration status'); //Will change it in a separate console removal PR } diff --git a/src/helpers/api.ts b/src/helpers/api.ts index 230e6b70..e2a40cd2 100644 --- a/src/helpers/api.ts +++ b/src/helpers/api.ts @@ -203,7 +203,7 @@ export const fetchJobSalary = async ( return apiCall(`/jobs/${jobId}/salary/`); }; -export const fetchEachJob = async ( +export const fetchJobById = async ( accessToken: string | undefined, jobId: any ) => { @@ -307,3 +307,27 @@ export const postJobCoordinator = async ( body: body, }); }; + + +export const fetchPenalties = async (body: any) => { + return apiCall('/penalties', { + method: 'POST', + body: body, + }); +}; + +export const fetchRecruiterById = async (id: string | undefined) => { + return apiCall(`/recruiters/${id}`); +}; + +export const fetchRegistrations = async (studentId:any, seasonId:any, currentStatus:any) => { + return apiCall('/registrations', { + method: 'POST', + isAuth: true, + body: [{ + studentId, + seasonId, + registered: !currentStatus + }] + }); +}; \ No newline at end of file From 9e31cf881335823702ec4d7068a2e26b56555ba8 Mon Sep 17 00:00:00 2001 From: JaiPannu-IITI Date: Sun, 14 Jul 2024 17:32:01 +0530 Subject: [PATCH 04/18] build error fix --- src/app/(routes)/admin/jobs/[jobId]/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/(routes)/admin/jobs/[jobId]/page.tsx b/src/app/(routes)/admin/jobs/[jobId]/page.tsx index 5057bba0..4a3c0421 100644 --- a/src/app/(routes)/admin/jobs/[jobId]/page.tsx +++ b/src/app/(routes)/admin/jobs/[jobId]/page.tsx @@ -14,7 +14,7 @@ import { CategorySelectList, GenderSelectList, } from "@/components/Recruiters/jobEdit"; -import { fetchEachJob } from "@/helpers/api"; +import { fetchJobById } from "@/helpers/api"; import Cookies from "js-cookie"; import Loader from "@/components/Loader/loader"; import toast from "react-hot-toast"; @@ -40,7 +40,7 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => { const fetchData = async () => { try { const [jobDetailData, jafDetailsData, companyData, recruiterData] = await Promise.all([ - fetchEachJob(accessToken, params.jobId), + fetchJobById(accessToken, params.jobId), getJafDetails(), fetchCompany(accessToken), fetchRecruiterData(accessToken, null), From e50b3868f3d3119f2673a2bad347490a75544cc4 Mon Sep 17 00:00:00 2001 From: JaiPannu-IITI Date: Sun, 14 Jul 2024 17:48:13 +0530 Subject: [PATCH 05/18] removed tokens from correct api calls --- .../admin/companies/allcompanies/page.tsx | 2 +- src/app/(routes)/admin/jobs/[...filter]/page.tsx | 2 +- src/app/(routes)/admin/jobs/[jobId]/page.tsx | 6 +++--- src/app/(routes)/admin/jobs/page.tsx | 2 +- src/app/(routes)/admin/recruiters/page.tsx | 2 +- .../(routes)/admin/students/[...filter]/page.tsx | 2 +- src/app/(routes)/admin/students/page.tsx | 2 +- src/components/NewTableComponent/NewJobModal.tsx | 2 +- .../NewTableComponent/StudentModal.tsx | 14 +++++++------- src/components/company/AllCompaniesComponent.tsx | 3 +-- src/helpers/api.ts | 16 ++++++++-------- 11 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/app/(routes)/admin/companies/allcompanies/page.tsx b/src/app/(routes)/admin/companies/allcompanies/page.tsx index e4118dd0..b3df7296 100644 --- a/src/app/(routes)/admin/companies/allcompanies/page.tsx +++ b/src/app/(routes)/admin/companies/allcompanies/page.tsx @@ -15,7 +15,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..2535f4c9 100644 --- a/src/app/(routes)/admin/jobs/[...filter]/page.tsx +++ b/src/app/(routes)/admin/jobs/[...filter]/page.tsx @@ -39,7 +39,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 4a3c0421..ae28bf65 100644 --- a/src/app/(routes)/admin/jobs/[jobId]/page.tsx +++ b/src/app/(routes)/admin/jobs/[jobId]/page.tsx @@ -40,10 +40,10 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => { const fetchData = async () => { try { const [jobDetailData, jafDetailsData, companyData, recruiterData] = await Promise.all([ - fetchJobById(accessToken, params.jobId), + fetchJobById(params.jobId), getJafDetails(), - fetchCompany(accessToken), - fetchRecruiterData(accessToken, null), + fetchCompany(), + fetchRecruiterData( null), ]); setJafDetails(jafDetailsData); diff --git a/src/app/(routes)/admin/jobs/page.tsx b/src/app/(routes)/admin/jobs/page.tsx index b6302367..117e3177 100644 --- a/src/app/(routes)/admin/jobs/page.tsx +++ b/src/app/(routes)/admin/jobs/page.tsx @@ -34,7 +34,7 @@ const JobPage = () => { useEffect(() => { const getData = async () => { - const data = await fetchAllJobs(Cookies.get("accessToken"), undefined); + const data = await fetchAllJobs( undefined); setAllJobs(data); setLoading(false); }; diff --git a/src/app/(routes)/admin/recruiters/page.tsx b/src/app/(routes)/admin/recruiters/page.tsx index e0b8ef27..3a80c3df 100644 --- a/src/app/(routes)/admin/recruiters/page.tsx +++ b/src/app/(routes)/admin/recruiters/page.tsx @@ -19,7 +19,7 @@ const hiddenColumns = ['id','user.id','company.id']; const StudentPage = async () => { const columns = generateColumns(recruiterdto) console.log(columns) - const AllRecruiters = await fetchRecruiterData(Cookies.get("accessToken"),null); + const AllRecruiters = await fetchRecruiterData(null); const visibleColumns = columns.filter( (column:any) => !hiddenColumns.includes(column?.accessorKey) ); diff --git a/src/app/(routes)/admin/students/[...filter]/page.tsx b/src/app/(routes)/admin/students/[...filter]/page.tsx index 3817a2ae..ca4ac4f7 100644 --- a/src/app/(routes)/admin/students/[...filter]/page.tsx +++ b/src/app/(routes)/admin/students/[...filter]/page.tsx @@ -35,7 +35,7 @@ const StudentPage = ({ params }: any) => { const decodedParams = decodeURIComponent(params.filter[0]); console.log(decodedParams) const AllStudents = await fetchStudentData( - Cookies.get("accessToken"), + decodedParams ); setStudents(AllStudents); diff --git a/src/app/(routes)/admin/students/page.tsx b/src/app/(routes)/admin/students/page.tsx index 416435c9..0165adbd 100644 --- a/src/app/(routes)/admin/students/page.tsx +++ b/src/app/(routes)/admin/students/page.tsx @@ -27,7 +27,7 @@ const StudentPage = () => { useEffect(() => { const fetchData = async () => { - const data = await fetchStudentData(Cookies.get("accessToken"), null); + const data = await fetchStudentData(null); setStudents(data); console.log(data); }; diff --git a/src/components/NewTableComponent/NewJobModal.tsx b/src/components/NewTableComponent/NewJobModal.tsx index 4d208b2d..8bdde018 100644 --- a/src/components/NewTableComponent/NewJobModal.tsx +++ b/src/components/NewTableComponent/NewJobModal.tsx @@ -44,7 +44,7 @@ const JobModal = ({ const fetchData = async () => { try { const [jobDetailData, jafDetailsData] = await Promise.all([ - fetchJobById(Cookies.get("accessToken"), jobID), + fetchJobById( jobID), getJafDetails(), ]); diff --git a/src/components/NewTableComponent/StudentModal.tsx b/src/components/NewTableComponent/StudentModal.tsx index d3b64e33..bff30942 100644 --- a/src/components/NewTableComponent/StudentModal.tsx +++ b/src/components/NewTableComponent/StudentModal.tsx @@ -52,7 +52,7 @@ const style = { const baseUrl = process.env.NEXT_PUBLIC_BACKEND_URL; -const handleRegistration = async (accessToken:any, studentId:any, seasonId:any, currentStatus:any) => { +const handleRegistration = async (studentId:any, seasonId:any, currentStatus:any) => { try { const response = await fetchRegistrations(studentId, seasonId, currentStatus); @@ -77,7 +77,7 @@ export default function StudentModal({ open, setOpen, id }) { const [registrationData, setRegistrationData] = useState(null); const [loading, setLoading] = useState(true); - const fetchStudentData = async (accessToken, id) => { + const fetchStudentData = async (accessToken:any, id:any) => { if (!accessToken) { console.error('No access token provided'); return; @@ -102,7 +102,7 @@ export default function StudentModal({ open, setOpen, id }) { } }; - const fetchRegistrationData = async (accessToken, studentId) => { + const fetchRegistrationData = async (accessToken:any, studentId:any) => { if (!accessToken) { console.error('No access token provided'); return; @@ -139,11 +139,11 @@ export default function StudentModal({ open, setOpen, id }) { const handleClose = () => setOpen(false); - const handleStatusChange = async (studentId, seasonId, currentStatus) => { - const success = await handleRegistration(Cookies.get("accessToken"), studentId, seasonId, currentStatus); + const handleStatusChange = async (studentId:any, seasonId:any, currentStatus:any) => { + const success = await handleRegistration(studentId, seasonId, currentStatus); if (success) { - setRegistrationData((prevData) => - prevData.map((registration) => + setRegistrationData((prevData:any) => + prevData.map((registration:any) => registration.season.id === seasonId ? { ...registration, registered: !currentStatus } : registration ) ); diff --git a/src/components/company/AllCompaniesComponent.tsx b/src/components/company/AllCompaniesComponent.tsx index 260b2b60..3e034abb 100644 --- a/src/components/company/AllCompaniesComponent.tsx +++ b/src/components/company/AllCompaniesComponent.tsx @@ -19,7 +19,7 @@ interface company { } const AllCompaniesComponent = async () => { - const Companies = await fetchCompany(cookies()?.get("accessToken")?.value); + const Companies = await fetchCompany(); if (Companies?.companies?.length === 0) { return ( @@ -29,7 +29,6 @@ const AllCompaniesComponent = async () => { ); } const Recruiters = await fetchCompanyRecruiters( - cookies()?.get("accessToken")?.value, cookies()?.get("companyId")?.value, ); console.log("Recruiters", Recruiters); diff --git a/src/helpers/api.ts b/src/helpers/api.ts index 22ced491..237e664c 100644 --- a/src/helpers/api.ts +++ b/src/helpers/api.ts @@ -137,11 +137,11 @@ export const PasswordlessLogin = async (accessToken: string | undefined) => { return { status: res.status, body }; }; -export const fetchAllSeasons = async (accessToken: string | undefined) => { +export const fetchAllSeasons = async () => { return apiCall("/seasons"); }; -export const fetchCompany = async (accessToken: string | undefined) => { +export const fetchCompany = async () => { return apiCall("/companies"); }; @@ -198,7 +198,7 @@ export const assignRecruiter = async ( }; export const fetchAllJobs = async ( - accessToken: string | undefined, + filter: string | undefined ) => { return apiCall(filter ? `/jobs?${filter}` : "/jobs", { @@ -208,7 +208,7 @@ export const fetchAllJobs = async ( }; export const fetchStudentData = async ( - accessToken: string | undefined, + filter: string | undefined ) => { return apiCall(filter ? `/students?${filter}` : "/students", { @@ -238,7 +238,7 @@ export const fetchSeasonData = async ( return json; }; export const fetchCompanyRecruiters = async ( - accessToken: string | undefined, + companyId: string | undefined ) => { return apiCall(`/companies/${companyId}/recruiters/`, { @@ -249,14 +249,14 @@ export const fetchCompanyRecruiters = async ( export const fetchJobSalary = async ( - accessToken: string | undefined, + jobId: string | undefined ) => { return apiCall(`/jobs/${jobId}/salary/`); }; export const fetchJobById = async ( - accessToken: string | undefined, + jobId: any ) => { return apiCall(`/jobs/${jobId}`); @@ -298,7 +298,7 @@ export const promoteStudent = async (body: any, eventId: string) => { }; export const fetchRecruiterData = async ( - accessToken: string | undefined, + filter: string | undefined ) => { From 99bb158dcb0a3512b7a33e6c4fbe683bcffcc310 Mon Sep 17 00:00:00 2001 From: JaiPannu-IITI Date: Sun, 14 Jul 2024 18:11:49 +0530 Subject: [PATCH 06/18] fixed api calls and respective token removed --- src/app/(routes)/admin/jobs/[jobId]/page.tsx | 6 +- src/helpers/api.ts | 62 +++----------------- 2 files changed, 11 insertions(+), 57 deletions(-) diff --git a/src/app/(routes)/admin/jobs/[jobId]/page.tsx b/src/app/(routes)/admin/jobs/[jobId]/page.tsx index ae28bf65..ca033f10 100644 --- a/src/app/(routes)/admin/jobs/[jobId]/page.tsx +++ b/src/app/(routes)/admin/jobs/[jobId]/page.tsx @@ -23,7 +23,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); @@ -334,7 +334,7 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => {