Skip to content

Commit

Permalink
Api fix (#118)
Browse files Browse the repository at this point in the history
Co-authored-by: Ishaan Mittal <[email protected]>
  • Loading branch information
JaiPannu-IITI and mittal-ishaan authored Jul 14, 2024
1 parent a47924b commit 7dcd351
Show file tree
Hide file tree
Showing 27 changed files with 264 additions and 436 deletions.
6 changes: 0 additions & 6 deletions src/app/(authroutes)/login/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand Down
2 changes: 0 additions & 2 deletions src/app/(authroutes)/passwordless/[token]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/app/(routes)/admin/companies/allcompanies/page.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 (
Expand Down
4 changes: 1 addition & 3 deletions src/app/(routes)/admin/jobs/[...filter]/page.tsx
Original file line number Diff line number Diff line change
@@ -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";


Expand Down Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions src/app/(routes)/admin/jobs/[jobId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ 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";
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<JobDetailFC>(null);
const [loading, setLoading] = useState(true);
const [editMode, setEditMode] = useState(false);
Expand All @@ -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);
Expand Down Expand Up @@ -334,7 +333,7 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => {
<Button onClick={async () => {
if (selectedCompany) {
try {
await assignCompany(accessToken, [{ id: job.id, companyId: selectedCompany.id }]);
await assignCompany( [{ id: job.id, companyId: selectedCompany.id }]);
toast.success("Company assigned successfully");
} catch (error) {
toast.error("Failed to assign company");
Expand Down Expand Up @@ -424,7 +423,7 @@ const JobDetailPage = ({ params }: { params: { jobId: string } }) => {
onClick={async () => {
if (selectedRecruiter) {
try {
await assignRecruiter(accessToken, [{ id: job.id, recruiterId: selectedRecruiter.id }]);
await assignRecruiter([{ id: job.id, recruiterId: selectedRecruiter.id }]);
toast.success("Recruiter assigned successfully");
} catch (error) {
toast.error("Failed to assign recruiter");
Expand Down
1 change: 0 additions & 1 deletion src/app/(routes)/admin/jobs/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client";

import React, { Component } from "react";
import { CircularProgress } from "@mui/material";
import Loader from "@/components/Loader/loader"

class Loading extends Component {
Expand Down
8 changes: 1 addition & 7 deletions src/app/(routes)/admin/jobs/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
"use client";
import { fetchAllJobs } from "@/helpers/api";
import Cookies from "js-cookie";
import TableComponent from "@/components/TableComponent/TableComponent";
import generateColumns from "@/components/NewTableComponent/ColumnMapping";
import type { RecruitmentDTO } from "@/dto/JobDto";
import { recruitmentDTO } from "@/dto/JobDto";
import {
MaterialReactTable,
useMaterialReactTable,
type MRT_Row,
createMRTColumnHelper,
} from "material-react-table";
import Table from "@/components/NewTableComponent/Table";
Expand All @@ -24,7 +19,6 @@ const hiddenColumns = [
];

const JobPage = () => {
const columnHelper = createMRTColumnHelper<RecruitmentDTO>();
const columns = generateColumns(recruitmentDTO);
const [loading, setLoading] = useState(true);
const [allJobs, setAllJobs] = useState();
Expand All @@ -34,7 +28,7 @@ const JobPage = () => {

useEffect(() => {
const getData = async () => {
const data = await fetchAllJobs(Cookies.get("accessToken"), undefined);
const data = await fetchAllJobs();
setAllJobs(data);
setLoading(false);
};
Expand Down
11 changes: 1 addition & 10 deletions src/app/(routes)/admin/recruiters/page.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
"use client";
import { fetchRecruiterData } from "@/helpers/api";
import Cookies from "js-cookie";
import Table from "@/components/NewTableComponent/Table";
import type {DTO} from '@/dto/StudentDto'
import {
MaterialReactTable,
useMaterialReactTable,
type MRT_Row,
createMRTColumnHelper,
} from 'material-react-table';
import generateColumns from "@/components/NewTableComponent/ColumnMapping";
import { recruiterdto } from "@/dto/RecruiterDto";
import type { RecruiterDTO } from "@/dto/RecruiterDto";

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();
const visibleColumns = columns.filter(
(column:any) => !hiddenColumns.includes(column?.accessorKey)
);
Expand Down
1 change: 0 additions & 1 deletion src/app/(routes)/admin/resumes/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client";
import React, { useEffect, useState } from "react";
import { fetchResumes, getResumeFile, patchResumeVerify } from "@/helpers/api";
import Cookies from "js-cookie";
import generateColumns from "@/components/NewTableComponent/ColumnMapping";
import Table from "@/components/NewTableComponent/Table";
import { resumeDto, Resume, ResumeTableData } from "@/dto/ResumeDto";
Expand Down
3 changes: 1 addition & 2 deletions src/app/(routes)/admin/students/[...filter]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";
import { fetchStudentData } 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";
Expand Down Expand Up @@ -35,7 +34,7 @@ const StudentPage = ({ params }: any) => {
const decodedParams = decodeURIComponent(params.filter[0]);
console.log(decodedParams)
const AllStudents = await fetchStudentData(
Cookies.get("accessToken"),

decodedParams
);
setStudents(AllStudents);
Expand Down
15 changes: 2 additions & 13 deletions src/app/(routes)/admin/students/page.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
"use client";
import { useState, useEffect } from 'react';
import { fetchStudentData, } from "@/helpers/api";
import Cookies from "js-cookie";
import Table from "@/components/NewTableComponent/Table";
import type { DTO } from '@/dto/StudentDto';
import { createMRTColumnHelper } from 'material-react-table';
import generateColumns from "@/components/NewTableComponent/ColumnMapping";
import { jsondto } from "@/dto/StudentDto";
import { Form } from 'antd';
import { cookies } from 'next/headers';

const hiddenColumns = ['userId', 'programId','id'];

const StudentPage = () => {
const [students, setStudents] = useState<DTO[]>([]);
const columnHelper = createMRTColumnHelper<DTO>();
const columns = generateColumns(jsondto);






const visibleColumns = columns.filter(
(column: any) => !hiddenColumns.includes(column?.accessorKey)
);

useEffect(() => {
const fetchData = async () => {
const data = await fetchStudentData(Cookies.get("accessToken"), null);
const data = await fetchStudentData();
setStudents(data);
console.log(data);
};


fetchData();
}, []);

Expand Down
3 changes: 1 addition & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ interface Props {

const RootLayout = async ({ children, auth }: Props) => {
const className = inter.className;
// const AllSeasons = await fetchAllSeasons(cookies()?.get("accessToken")?.value);
// console.log(AllSeasons);

return (
<html lang="en">
<body className={className}>
Expand Down
4 changes: 2 additions & 2 deletions src/components/NewTableComponent/JobModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {fetchJobById} from "@/helpers/api"
const theme = createTheme({
palette: {
primary: {
Expand Down Expand Up @@ -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 fetchJobById(id);
setJobData(data);
} catch (error) {
console.error('Error fetching job data:', error);
Expand Down
9 changes: 4 additions & 5 deletions src/components/NewTableComponent/NewJobModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import {
CategorySelectList,
GenderSelectList,
} from "@/components/Recruiters/jobEdit";
import { fetchEachJob } from "@/helpers/api";
import Cookies from "js-cookie";
import { fetchJobById } from "@/helpers/api";
import Modal from "@mui/material/Modal";
import { CircularProgress } from "@mui/material";
import toast from "react-hot-toast";
import Loader from "../Loader/loader";

const JobModal = ({
jobID,
Expand All @@ -44,7 +43,7 @@ const JobModal = ({
const fetchData = async () => {
try {
const [jobDetailData, jafDetailsData] = await Promise.all([
fetchEachJob(Cookies.get("accessToken"), jobID),
fetchJobById( jobID),
getJafDetails(),
]);

Expand Down Expand Up @@ -114,7 +113,7 @@ const JobModal = ({
{loading && (
<div className="w-full h-full flex justify-center items-center">
<div className="px-28 py-16 bg-white">
<CircularProgress />
<Loader />
</div>
</div>
)}
Expand Down
10 changes: 2 additions & 8 deletions src/components/NewTableComponent/PenaltyModal.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { Box, Button, Modal, TextField, Typography } from '@mui/material';

import {fetchPenalties} from "@/helpers/api"
const style = {
position: 'absolute',
top: '50%',
Expand Down Expand Up @@ -29,13 +29,7 @@ const PenaltyModal = ({ isOpen, onClose, studentId }) => {
];

try {
const response = await fetch(`${baseUrl}/api/v1/penalties`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),
});
const response = await fetchPenalties(requestBody);

if (response.ok) {
console.log('Penalty submitted successfully');
Expand Down
6 changes: 3 additions & 3 deletions src/components/NewTableComponent/RecruiterModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {fetchRecruiterById} from "@/helpers/api"
const theme = createTheme({
palette: {
primary: {
Expand Down Expand Up @@ -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 fetchRecruiterById(id);
setRecruiterData(data);
} catch (error) {
console.error('Error fetching recruiter data:', error);
}
Expand Down
Loading

0 comments on commit 7dcd351

Please sign in to comment.