Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 81 additions & 18 deletions app/dashboard/admin/company/[companyId]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import secureLocalStorage from "react-secure-storage";
import { Toast } from "primereact/toast";
import { Dialog, Transition } from "@headlessui/react";
import { Chart } from "primereact/chart";
import { MultiSelect } from "primereact/multiselect";
import { campusNames, campuses } from "@/util/config";

export default function CompanyPage() {
const [allHiredStudents, setAllHiredStudents] = useState([]);
const [filteredHiredStudents, setFilteredHiredStudents] = useState([]);
const [deptSectionWiseHiredStudents, setDeptSectionWiseHiredStudents] =
useState([]);
const [
Expand All @@ -27,6 +30,11 @@ export default function CompanyPage() {
const [_, setUserAccess] = useState({});

const [companyName, setCompanyName] = useState("");
const [selectedCampuses, setSelectedCampuses] = useState(null);
const campusList = campuses.map((campus) => ({

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why define it again? Can't we simply reuse the imported var?

id: campus,
campus: campusNames[campus],
}));
const router = useRouter();

const toast = useRef(null);
Expand Down Expand Up @@ -101,6 +109,7 @@ export default function CompanyPage() {
res.json().then((data) => {
setCompanyName(data.companyName);
setAllHiredStudents(data.allHiredStudents);
setFilteredHiredStudents(data.allHiredStudents);
setDeptSectionWiseHiredStudents(
data.deptSectionWiseHires,
);
Expand Down Expand Up @@ -154,12 +163,39 @@ export default function CompanyPage() {
}

useEffect(() => {
const tempArray = [...deptSectionWiseHiredStudents];
tempArray.sort((a, b) =>
const selectedCampusSet = new Set(selectedCampuses ?? []);
const hasCampusFilter = selectedCampusSet.size > 0;
const nextFilteredStudents = hasCampusFilter
? allHiredStudents.filter((student) =>
selectedCampusSet.has(
(student.studentRollNo ?? "").slice(0, 2).toUpperCase(),
),
)
: allHiredStudents;

const nextDeptSectionHires = hasCampusFilter
? Object.values(
nextFilteredStudents.reduce((acc, student) => {
const key = `${student.studentDept}-${student.studentSection}`;
if (!acc[key]) {
acc[key] = {
studentDept: student.studentDept,
studentSection: student.studentSection,
totalHires: 0,
};
}
acc[key].totalHires += 1;
return acc;
}, {}),
)
: [...deptSectionWiseHiredStudents];

nextDeptSectionHires.sort((a, b) =>
a.studentSection.localeCompare(b.studentSection),
);
setSortedDeptSectionWiseHiredStudents(tempArray);
}, [deptSectionWiseHiredStudents]);
setFilteredHiredStudents(nextFilteredStudents);
setSortedDeptSectionWiseHiredStudents(nextDeptSectionHires);
}, [allHiredStudents, deptSectionWiseHiredStudents, selectedCampuses]);

const getBatchData = (e, mode) => {
setIsLoading(true);
Expand All @@ -175,6 +211,7 @@ export default function CompanyPage() {
setStudentBatch("");
setCurrentBatch("");
}
setSelectedCampuses(null);

fetchWithRetry(GET_COMPANY_HIRE_DATA_URL, {
headers: {
Expand All @@ -192,6 +229,7 @@ export default function CompanyPage() {
res.json().then((data) => {
setCompanyName(data.companyName);
setAllHiredStudents(data.allHiredStudents);
setFilteredHiredStudents(data.allHiredStudents);
setDeptSectionWiseHiredStudents(
data.deptSectionWiseHires,
);
Expand Down Expand Up @@ -357,10 +395,35 @@ export default function CompanyPage() {
}
*/}

{allHiredStudents.length === 0 ? (
{allHiredStudents.length > 0 ? (
<div className="flex justify-center mb-8">
<div className="border border-bGray rounded-xl bg-white/80 p-4 shadow-sm">
<MultiSelect
value={selectedCampuses}
onChange={(e) => {
setSelectedCampuses(e.value);
}}
options={campusList}
filter
filterPlaceholder="Enter Campus Name"
optionLabel="campus"
optionValue="id"
display="chip"
showClear={true}
placeholder="Select Campuses"
maxSelectedLabels={2}
className="w-full md:w-20rem"
/>
</div>
</div>
) : null}

{filteredHiredStudents.length === 0 ? (
<div className="border border-red-50 rounded-2xl mx-auto w-11/12 sm:max-w-11/12 md:max-w-md lg:max-w-md backdrop-blur-xl bg-red-200">
<p className="p-8 text-center text-red-900">
No hires yet
{allHiredStudents.length === 0
? "No hires yet"
: "No hires match the selected campus filter"}
</p>
</div>
) : (
Expand Down Expand Up @@ -468,51 +531,51 @@ export default function CompanyPage() {
</thead>

<tbody>
{allHiredStudents.map(
{filteredHiredStudents.map(
(student, index) => {
return (
<tr key={index}>
<td
className={
"border border-gray-200 px-2 py-1" +
(index ===
allHiredStudents.length -
filteredHiredStudents.length -
1
? "border-separate rounded-bl-2xl"
: "")
}
>
{
student[
"studentRollNo"
"studentRollNo"
]
}
</td>
<td className="border border-gray-200 px-2 py-1">
{
student[
"studentName"
"studentName"
]
}
</td>
<td className="border border-gray-200 px-2 py-1">
{
student[
"studentGender"
"studentGender"
]
}
</td>
<td className="border border-gray-200 px-2 py-1">
{
student[
"studentDept"
"studentDept"
]
}
</td>
<td className="border border-gray-200 px-2 py-1">
{
student[
"studentSection"
"studentSection"
]
}
</td>
Expand All @@ -523,7 +586,7 @@ export default function CompanyPage() {
<td className="border border-gray-200 px-2 py-1">
{
student[
"studentBatch"
"studentBatch"
]
}
</td>
Expand Down Expand Up @@ -556,7 +619,7 @@ export default function CompanyPage() {
className={
"border border-gray-200 px-2 py-1" +
(index ===
allHiredStudents.length -
filteredHiredStudents.length -
1
? " border-separate rounded-br-2xl"
: "")
Expand Down Expand Up @@ -686,12 +749,12 @@ export default function CompanyPage() {
className={
"block text-lg w-full rounded-md py-2 px-2 text-black ring-1 ring-inset ring-bGray placeholder:text-gray-400 sm:text-md sm:leading-6 outline-none! normal-nums" +
(!isValidBatch &&
studentBatch
studentBatch
? " ring-red-500"
: isValidBatch &&
studentBatch
? " ring-green-500"
: " ring-bGray")
? " ring-green-500"
: " ring-bGray")
}
required
/>
Expand Down
Loading