Skip to content

Commit

Permalink
add userID along with name in metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
qu-bit1 committed Feb 12, 2024
1 parent d1ada67 commit bb0f584
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
6 changes: 3 additions & 3 deletions components/DataGrid/excelUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ function downloadExcel(
rows: any[],
columns: any[],
name: string,
rcname: string
user_id: string
) {
const wb = new ExcelJS.Workbook();
wb.creator = name;
wb.creator = `${name} | ${user_id}`;
wb.lastModifiedBy = name;
wb.created = new Date();
wb.lastPrinted = new Date();
Expand All @@ -29,7 +29,7 @@ function downloadExcel(
});

wb.xlsx.writeBuffer().then((excelBuffer) => {
saveAs(new Blob([excelBuffer]), `${rcname}.xlsx`);
saveAs(new Blob([excelBuffer]), `data.xlsx`);
});
}

Expand Down
48 changes: 44 additions & 4 deletions components/DataGrid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ import {
} 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 { useState } 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";
Expand Down Expand Up @@ -87,12 +91,48 @@ function Index({
heighted = false,
}: paramsType) {
const [pageSize, setPageSize] = useState<number>(25);
const { name, rcName } = useStore();
const { name, role, token, setToken } = useStore();
const router = useRouter();
const [userId, setUserId] = useState("");

useEffect(() => {
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, rcName);
downloadExcel(rows, columns, name, userId);
};

const cols = columns.map((col) => ({
...col,
flex: 1,
Expand Down

0 comments on commit bb0f584

Please sign in to comment.