Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert excel file changes #268

Merged
merged 2 commits into from
Apr 9, 2024
Merged
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
37 changes: 0 additions & 37 deletions components/DataGrid/excelUtils.tsx

This file was deleted.

85 changes: 9 additions & 76 deletions components/DataGrid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,12 @@ import {
GridCellParams,
GridColDef,
// GridRowHeightParams,
GridToolbarColumnsButton,
GridToolbarContainer,
GridToolbarFilterButton,
GridToolbarQuickFilter,
GridToolbar,
MuiEvent,
} from "@mui/x-data-grid";
import Button from "@mui/material/Button";
import Image from "next/image";
import { useRouter } from "next/router";
import * as React from "react";
import { useEffect, useState } from "react";
import DownloadIcon from "@mui/icons-material/Download";

import companyRequest from "@callbacks/company/company";
import studentRequest from "@callbacks/student/student";
import whoami from "@callbacks/auth/whoami";
import useStore from "@store/store";

import downloadExcel from "./excelUtils";
import { useState } from "react";

const StyledGridOverlay = styled("div")(({ theme }) => ({
display: "flex",
Expand Down Expand Up @@ -58,21 +45,6 @@ function CustomNoRowsOverlay() {
</StyledGridOverlay>
);
}

function CustomToolbar({ handleDownload }: { handleDownload: () => void }) {
return (
<GridToolbarContainer>
<GridToolbarColumnsButton />
<GridToolbarFilterButton />
<Button startIcon={<DownloadIcon />} onClick={handleDownload} />
<Box flexGrow={1} />
<GridToolbarQuickFilter
showQuickFilter
quickFilterProps={{ debounceMs: 500 }}
/>
</GridToolbarContainer>
);
}
interface paramsType {
rows: any[];
columns: GridColDef[];
Expand All @@ -97,51 +69,7 @@ function Index({
heighted = false,
}: paramsType) {
const [pageSize, setPageSize] = useState<number>(25);
const { name, role, token, setToken } = useStore();
const router = useRouter();
const [userId, setUserId] = useState("");
const [pageName, setPageName] = useState("");

useEffect(() => {
setPageName(document.title);

const getCompany = async () => {
const response = await companyRequest.get(token);
if (response.name === "error401" && response.email === "error401") {
router.push("/login");
setToken("");
}
setUserId(response.email.split("@")[0]);
};

const getStudent = async () => {
const response = await studentRequest.get(token);
if (response.ID === -1) {
router.push("/login");
setToken("");
}
setUserId(response.iitk_email.split("@")[0]);
};

const getAdmin = async () => {
const response = await whoami.get(token);
if (response.name === "error401" && response.user_id === "error401") {
router.push("/login");
setToken("");
}
setUserId(response.user_id.split("@")[0]);
};
if (token !== "") {
if (role === 2) getCompany();
if (role === 1) getStudent();
if (role === 100 || role === 101 || role === 102 || role === 103)
getAdmin();
}
}, [role, userId, router, token, setToken]);

const handleDownload = () => {
downloadExcel(rows, columns, name, userId, pageName);
};
const cols = columns.map((col) => ({
...col,
flex: 1,
Expand All @@ -154,10 +82,15 @@ function Index({
rows={rows}
columns={cols}
components={{
// eslint-disable-next-line react/no-unstable-nested-components
Toolbar: () => <CustomToolbar handleDownload={handleDownload} />,
Toolbar: GridToolbar,
NoRowsOverlay: CustomNoRowsOverlay,
}}
componentsProps={{
toolbar: {
showQuickFilter: true,
quickFilterProps: { debounceMs: 500 },
},
}}
disableDensitySelector
pageSize={pageSize}
onPageSizeChange={(newPageSize) => setPageSize(newPageSize)}
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
"@types/date-fns": "^2.6.0",
"axios": "^0.27.2",
"date-fns": "^2.28.0",
"exceljs": "^4.4.0",
"file-saver": "^2.0.5",
"next": "12.1.5",
"react": "18.0.0",
"react-dom": "18.0.0",
Expand All @@ -38,7 +36,6 @@
"devDependencies": {
"@babel/core": "^7.18.5",
"@next/eslint-plugin-next": "^12.1.6",
"@types/file-saver": "^2.0.7",
"@types/node": "^17.0.23",
"@types/react": "^18.0.4",
"@types/react-dom": "18.0.0",
Expand Down
Loading
Loading