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

Updated admin pages to stop reload on state change #283

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
10 changes: 8 additions & 2 deletions components/Modals/AddCompanyAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ const boxStyle = {
alignItems: "center",
};

function AddCompany({ handleCloseNew }: { handleCloseNew: () => void }) {
function AddCompany({
handleCloseNew,
updateCompany,
}: {
handleCloseNew: () => void;
updateCompany: () => Promise<void>;
}) {
const {
register,
handleSubmit,
Expand Down Expand Up @@ -68,7 +74,7 @@ function AddCompany({ handleCloseNew }: { handleCloseNew: () => void }) {
});
handleCloseNew();
}
window.location.reload();
updateCompany();
};
return (
<Box sx={boxStyle}>
Expand Down
10 changes: 8 additions & 2 deletions components/Modals/AddCompanyAdminMD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ const boxStyle = {
alignItems: "center",
};

function AddCompanyMD({ handleCloseNew }: { handleCloseNew: () => void }) {
function AddCompanyMD({
handleCloseNew,
updateCompanies,
}: {
handleCloseNew: () => void;
updateCompanies: () => Promise<void>;
}) {
const {
register,
handleSubmit,
Expand All @@ -39,8 +45,8 @@ function AddCompanyMD({ handleCloseNew }: { handleCloseNew: () => void }) {
description: "",
});
handleCloseNew();
window.location.reload();
}
updateCompanies();
};

return (
Expand Down
4 changes: 3 additions & 1 deletion components/Modals/AddCompanyHR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ const boxStyle = {

function AddHRMD({
handleCloseNew,
updateHR,
}: {
handleCloseNew: () => void;
updateHR: () => Promise<void>;
}): JSX.Element {
const {
register,
Expand Down Expand Up @@ -54,7 +56,7 @@ function AddHRMD({
designation: "",
});
handleCloseNew();
window.location.reload();
updateHR();
}
};

Expand Down
4 changes: 3 additions & 1 deletion components/Modals/AddHRAdminMD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ const boxStyle = {

function AddHRMD({
handleCloseNew,
updateHR,
}: {
handleCloseNew: () => void;
updateHR: () => Promise<void>;
}): JSX.Element {
const {
register,
Expand Down Expand Up @@ -54,7 +56,7 @@ function AddHRMD({
designation: "",
});
handleCloseNew();
window.location.reload();
updateHR();
}
};

Expand Down
120 changes: 64 additions & 56 deletions pages/admin/company/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import React, { useCallback, useEffect, useRef, useState } from "react";
import { GridColDef } from "@mui/x-data-grid";
import Grid from "@mui/material/Grid";
import { IconButton, Modal, Stack, Tooltip } from "@mui/material";
// eslint-disable-next-line import/order
import AddIcon from "@mui/icons-material/Add";
// import { set } from "date-fns";

import { useRouter } from "next/router";

import DataGrid from "@components/DataGrid";
import ActiveButton from "@components/Buttons/ActiveButton";
import Meta from "@components/Meta";
Expand All @@ -14,63 +17,65 @@ import AddCompanyMD from "@components/Modals/AddCompanyAdminMD";

const batchSize = 100;

const columns: GridColDef[] = [
{ field: "ID", headerName: "ID" },
{
field: "name",
headerName: "Company Name",
renderCell: (params) => (
<Tooltip title={params.value}>
<div>{params.value}</div>
</Tooltip>
),
},
{
field: "CreatedAt",
headerName: "Created At",
hide: true,
},
{
field: "UpdatedAt",
headerName: "Updated At",
hide: true,
},
{
field: "tags",
headerName: "Tags",
},
{
field: "website",
headerName: "Website",
},
{
field: "description",
headerName: "Description",
hide: true,
},
{
field: "view_details",
headerName: "View Details",
function Index() {
const router = useRouter();
const columns: GridColDef[] = [
{ field: "ID", headerName: "ID" },
{
field: "name",
headerName: "Company Name",
renderCell: (params) => (
<Tooltip title={params.value}>
<div>{params.value}</div>
</Tooltip>
),
},
{
field: "CreatedAt",
headerName: "Created At",
hide: true,
},
{
field: "UpdatedAt",
headerName: "Updated At",
hide: true,
},
{
field: "tags",
headerName: "Tags",
},
{
field: "website",
headerName: "Website",
},
{
field: "description",
headerName: "Description",
hide: true,
},
{
field: "view_details",
headerName: "View Details",

renderCell: (params) => (
<Stack
direction="row"
alignItems="center"
width="100%"
justifyContent="space-between"
>
<ActiveButton
href={`/admin/company/${params.row.ID}`}
sx={{ height: 30 }}
renderCell: (params) => (
<Stack
direction="row"
alignItems="center"
width="100%"
justifyContent="space-between"
>
CLICK HERE
</ActiveButton>
</Stack>
),
},
];

function Index() {
<ActiveButton
onClick={() => {
router.push(`/admin/company/${params.row.ID}`);
}}
sx={{ height: 30 }}
>
CLICK HERE
</ActiveButton>
</Stack>
),
},
];
const { token } = useStore();
const [rows, setRows] = useState<Company[]>([]);
const [loading, setLoading] = useState(true);
Expand Down Expand Up @@ -148,7 +153,10 @@ function Index() {
/>
</Grid>
<Modal open={openNew} onClose={handleCloseNew}>
<AddCompanyMD handleCloseNew={handleCloseNew} />
<AddCompanyMD
handleCloseNew={handleCloseNew}
updateCompanies={getAllCompanies}
/>
</Modal>
</div>
);
Expand Down
1 change: 0 additions & 1 deletion pages/admin/companyHR/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ function Index() {
const fetch = async () => {
const companyHR = await CompanyHRRequest.getAll(token).catch(() => []);
setRows(companyHR);
console.log(companyHR);
setLoading(false);
};
fetch();
Expand Down
138 changes: 71 additions & 67 deletions pages/admin/rc/[rcid]/calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,6 @@ import useStore from "@store/store";
import calendarLinks from "@components/Utils/calendarUtils";
import { errorNotification } from "@callbacks/notifcation";

const columns: GridColDef[] = [
{
field: "ID",
headerName: "ID",
hide: true,
},
{
field: "company_name",
headerName: "Company Name",
},
{
field: "role",
headerName: "Role",
hide: true,
},
{
field: "profile",
headerName: "Profile",
},
{
field: "name",
headerName: "Event Name",
},
{
field: "CreatedAt",
headerName: "Created At",
renderCell: (params) =>
new Date(params.row.CreatedAt).toLocaleDateString("en-GB"),
hide: true,
},
{
field: "UpdatedAt",
headerName: "Updated At",
renderCell: (params) =>
new Date(params.row.UpdatedAt).toLocaleDateString("en-GB"),
hide: true,
},
{
field: "duration",
headerName: "Event Duration",
hide: true,
},
{
field: "start_time",
headerName: "Start Time",
renderCell: (params) =>
new Date(params.row.start_time).toLocaleTimeString(),
},
{
field: "sequence",
headerName: "Sequence",
hide: true,
},
{
field: "View Details",
renderCell: (params) => (
<Button
href={`/admin/rc/${params.row.recruitment_cycle_id}/event/${params.row.ID}`}
variant="contained"
style={{ width: "100%" }}
>
View Details
</Button>
),
},
];

function Calendar() {
const [value, setValue] = useState<Date | null>(new Date());
const [activity, setActivity] = useState<Event[]>([]);
Expand All @@ -93,6 +26,77 @@ function Calendar() {

const { token, rcName } = useStore();

const columns: GridColDef[] = [
{
field: "ID",
headerName: "ID",
hide: true,
},
{
field: "company_name",
headerName: "Company Name",
},
{
field: "role",
headerName: "Role",
hide: true,
},
{
field: "profile",
headerName: "Profile",
},
{
field: "name",
headerName: "Event Name",
},
{
field: "CreatedAt",
headerName: "Created At",
renderCell: (params) =>
new Date(params.row.CreatedAt).toLocaleDateString("en-GB"),
hide: true,
},
{
field: "UpdatedAt",
headerName: "Updated At",
renderCell: (params) =>
new Date(params.row.UpdatedAt).toLocaleDateString("en-GB"),
hide: true,
},
{
field: "duration",
headerName: "Event Duration",
hide: true,
},
{
field: "start_time",
headerName: "Start Time",
renderCell: (params) =>
new Date(params.row.start_time).toLocaleTimeString(),
},
{
field: "sequence",
headerName: "Sequence",
hide: true,
},
{
field: "View Details",
renderCell: (params) => (
<Button
onClick={() => {
router.push(
`/admin/rc/${params.row.recruitment_cycle_id}/event/${params.row.ID}`
);
}}
variant="contained"
style={{ width: "100%" }}
>
View Details
</Button>
),
},
];

const handleClick = () => {
if (calendarLinks.get(rid) !== undefined) {
window.open(calendarLinks.get(rid) as string, "_blank");
Expand Down
Loading