Skip to content

Commit 74f0fc9

Browse files
add on campus offers tab (#376) (#377)
2 parents c10663a + e11b5e5 commit 74f0fc9

4 files changed

Lines changed: 190 additions & 0 deletions

File tree

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"use client";
2+
import { fetchAllSeasons, fetchOnCampusOffers } from "@/helpers/api";
3+
import generateColumns from "@/components/NewTableComponent/ColumnMapping";
4+
import { onCampusOfferDTO } from "@/dto/onCampusOfferDTO";
5+
import Table from "@/components/NewTableComponent/Table";
6+
import { useEffect, useState } from "react";
7+
import Loader from "@/components/Loader/loader";
8+
import toast from "react-hot-toast";
9+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
10+
11+
const internHiddenColumns = ["salary.firstYearCTC", "salary.totalCTC", "salary.salaryPeriod"];
12+
const placementHiddenColumns = ["salary.stipend", "salary.otherCompensations", "salary.salaryPeriod"];
13+
14+
const OnCampusOffersPage = () => {
15+
const columns = generateColumns(onCampusOfferDTO);
16+
const [seasons, setSeasons] = useState<{ id: string; name: string, type: string }[]>([]);
17+
const [selectedSeason, setSelectedSeason] = useState<string>("");
18+
const [loading, setLoading] = useState(true);
19+
const [allOffers, setAllOffers] = useState();
20+
const [visibleColumns, setVisibleColumns] = useState<any[]>([]);
21+
22+
useEffect(() => {
23+
const getData = async () => {
24+
try {
25+
const data = await fetchAllSeasons();
26+
if (Array.isArray(data)) {
27+
setSeasons(
28+
data.map((s: any) => ({
29+
id: s.id,
30+
name: `${s.type} - ${s.year}`,
31+
type: s.type,
32+
})),
33+
);
34+
}
35+
setSelectedSeason(data[0]?.id);
36+
} catch (error) {
37+
console.log(error);
38+
toast.error("Failed to select a season");
39+
}
40+
};
41+
getData();
42+
}, []);
43+
44+
useEffect(() => {
45+
if (selectedSeason) {
46+
try {
47+
setLoading(true);
48+
fetchOnCampusOffers(selectedSeason).then((data) => {
49+
setAllOffers(data);
50+
});
51+
if (seasons.find(season => season.id === selectedSeason)?.type === "INTERN") {
52+
setVisibleColumns(columns.filter((column: any) => !internHiddenColumns.includes(column?.accessorKey)));
53+
} else {
54+
setVisibleColumns(columns.filter((column: any) => !placementHiddenColumns.includes(column?.accessorKey)));
55+
}
56+
} catch (error) {
57+
toast.error("Failed to fetch on campus offers");
58+
} finally {
59+
setLoading(false);
60+
}
61+
}
62+
}, [selectedSeason]);
63+
64+
return (
65+
<div className="container mx-auto my-4 md:my-8 px-2 md:px-4">
66+
<h1 className="text-2xl md:text-3xl mb-4 md:mb-8 font-bold mx-auto text-center">
67+
On Campus Offers
68+
</h1>
69+
<div className="flex justify-center">
70+
<Select onValueChange={(value) => setSelectedSeason(value)} value={selectedSeason}>
71+
<SelectTrigger>
72+
<SelectValue>
73+
{seasons.find(season => season.id === selectedSeason)?.name || "Select a season"}
74+
</SelectValue>
75+
</SelectTrigger>
76+
<SelectContent>
77+
{seasons.map((season) => (
78+
<SelectItem key={season.id} value={season.id}>
79+
{season.name}
80+
</SelectItem>
81+
))}
82+
</SelectContent>
83+
</Select>
84+
</div>
85+
{loading && (
86+
<div className="w-full flex justify-center">
87+
<Loader />
88+
</div>
89+
)}
90+
{allOffers && (
91+
<div>
92+
<Table
93+
data={allOffers}
94+
columns={visibleColumns}
95+
type={"on-campus-offers"}
96+
/>
97+
</div>
98+
)}
99+
</div>
100+
);
101+
};
102+
103+
export default OnCampusOffersPage;

src/components/SideBar/Roles/admin.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,47 @@ const AdminDashboard = () => {
404404
{/* <SessionDropDown AllSeasons={AllSeasons} /> */}
405405
</div>
406406
</Link>
407+
<Link href={"/admin/oncampus-offers"}>
408+
<div className="hover:bg-slate-600/50 rounded-md my-2 py-2 px-4 text-white">
409+
<div className="flex justify-start gap-3">
410+
<div className="w-5 flex-shrink-0 text-white">
411+
<svg
412+
width="20"
413+
height="20"
414+
viewBox="0 0 24 24"
415+
fill="none"
416+
xmlns="http://www.w3.org/2000/svg"
417+
className="text-white"
418+
>
419+
<path
420+
d="M12 2L13.09 8.26L20 9L13.09 9.74L12 16L10.91 9.74L4 9L10.91 8.26L12 2Z"
421+
fill="currentColor"
422+
/>
423+
<path
424+
d="M19 15L18.09 19.26L12 20L18.09 20.74L19 25L19.91 20.74L26 20L19.91 19.26L19 15Z"
425+
fill="currentColor"
426+
/>
427+
<path
428+
d="M5 15L4.09 19.26L-2 20L4.09 20.74L5 25L5.91 20.74L12 20L5.91 19.26L5 15Z"
429+
fill="currentColor"
430+
/>
431+
</svg>
432+
</div>
433+
<motion.div
434+
initial={{ opacity: 1 }}
435+
animate={context.isOpen ? "open" : "closed"}
436+
transition={{ duration: 0.1 }}
437+
variants={{
438+
closed: { opacity: 0 },
439+
open: { opacity: 1 },
440+
}}
441+
className={`${context.isOpen ? "visible" : "hidden"} flex-1 text-white`}
442+
>
443+
On Campus Offers
444+
</motion.div>
445+
</div>
446+
</div>
447+
</Link>
407448
<Link href={"/admin/dashboard"}>
408449
<div className="hover:bg-slate-600/50 rounded-md my-2 py-2 px-4 cursor-pointer text-white">
409450
<div className="flex justify-start gap-3">

src/dto/onCampusOfferDTO.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const onCampusOfferDTO = [
2+
{
3+
status: "string",
4+
student: {
5+
rollNo: "string",
6+
user: {
7+
name: "string",
8+
email: "string",
9+
contact: "string",
10+
},
11+
program: {
12+
course: "string",
13+
branch: "string",
14+
department: "string",
15+
year: "string",
16+
},
17+
},
18+
salary: {
19+
job: {
20+
role: "string",
21+
season: {
22+
year: "string",
23+
type: "string",
24+
},
25+
company: {
26+
name: "string",
27+
},
28+
},
29+
totalCTC: "number",
30+
firstYearCTC: "number",
31+
stipend: "number",
32+
otherCompensations: "number",
33+
salaryPeriod: "string",
34+
},
35+
},
36+
];
37+
38+
export { onCampusOfferDTO };

src/helpers/api.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ export const getStudentSalaryOffers = async (
508508
return apiCall(`/on-campus-offers/salaries/${jobId}/student/${studentId}`);
509509
};
510510

511+
export const fetchOnCampusOffers = async (seasonId: string) => {
512+
return apiCall(`/on-campus-offers`, {
513+
queryParam: {
514+
"q[filterBy][salary][job][season][id][eq][]": seasonId,
515+
},
516+
});
517+
};
518+
511519
export const fetchStudentOffers = async (studentId: string) => {
512520
return apiCall(`/on-campus-offers`, {
513521
queryParam: {

0 commit comments

Comments
 (0)