2024-03-04 13:52:20 +01:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { FC } from "react";
|
|
|
|
|
import { Grid, Box } from "@mui/material";
|
|
|
|
|
import { DataGridPro, GridColDef } from "@mui/x-data-grid-pro";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
2024-03-16 19:39:20 +01:00
|
|
|
import { typography } from "@/app/_styles/theme";
|
2024-03-04 13:52:20 +01:00
|
|
|
|
|
|
|
|
interface ListProps {
|
|
|
|
|
title: string;
|
|
|
|
|
entity: string;
|
|
|
|
|
rows: any;
|
|
|
|
|
columns: GridColDef<any>[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const List: FC<ListProps> = ({ title, entity, rows, columns }) => {
|
|
|
|
|
const router = useRouter();
|
2024-03-16 19:39:20 +01:00
|
|
|
const { h3 } = typography;
|
2024-03-04 13:52:20 +01:00
|
|
|
|
|
|
|
|
const onRowClick = (id: string) => {
|
|
|
|
|
router.push(`/${entity}/${id}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box sx={{ height: "100vh", backgroundColor: "#ddd", p: 3 }}>
|
|
|
|
|
<Grid container direction="column">
|
|
|
|
|
<Grid item>
|
2024-03-16 19:39:20 +01:00
|
|
|
<Box sx={h3}>{title}</Box>
|
2024-03-04 13:52:20 +01:00
|
|
|
</Grid>
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
backgroundColor: "#ddd",
|
|
|
|
|
border: 0,
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100vh",
|
|
|
|
|
".MuiDataGrid-row": {
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
"&:hover": {
|
|
|
|
|
backgroundColor: "#1982fc33 !important",
|
|
|
|
|
fontWeight: "bold",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
".MuiDataGrid-row:nth-of-type(1n)": {
|
|
|
|
|
backgroundColor: "#f3f3f3",
|
|
|
|
|
},
|
|
|
|
|
".MuiDataGrid-row:nth-of-type(2n)": {
|
|
|
|
|
backgroundColor: "#fff",
|
|
|
|
|
},
|
|
|
|
|
".MuiDataGrid-columnHeaderTitle": {
|
|
|
|
|
color: "#333",
|
|
|
|
|
fontWeight: "bold",
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
margin: "0 auto",
|
|
|
|
|
},
|
|
|
|
|
".MuiDataGrid-columnHeader": {
|
|
|
|
|
backgroundColor: "#ccc",
|
|
|
|
|
border: 0,
|
|
|
|
|
borderBottom: "3px solid #ddd",
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DataGridPro
|
|
|
|
|
rows={rows}
|
|
|
|
|
columns={columns}
|
|
|
|
|
density="compact"
|
|
|
|
|
pagination
|
|
|
|
|
initialState={{
|
|
|
|
|
pagination: { paginationModel: { pageSize: 25 } },
|
|
|
|
|
}}
|
|
|
|
|
pageSizeOptions={[5, 10, 25]}
|
|
|
|
|
paginationMode="client"
|
|
|
|
|
sx={{ height: "100vh" }}
|
2024-04-21 08:11:24 +02:00
|
|
|
// rowBuffer={30}
|
2024-03-04 13:52:20 +01:00
|
|
|
rowHeight={46}
|
|
|
|
|
scrollbarSize={0}
|
|
|
|
|
disableVirtualization
|
|
|
|
|
disableColumnMenu
|
|
|
|
|
onRowClick={(row: any) => onRowClick(row.id)}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|