-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.tsx
83 lines (77 loc) · 2.61 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import Container from "@mui/material/Container";
import { useMemo } from "react";
import { ColumnDef } from "@tanstack/react-table";
import Avatar from "@mui/material/Avatar";
import Stack from "@mui/material/Stack";
import Box from "@mui/material/Box";
import TextField from "@mui/material/TextField";
import InputAdornment from "@mui/material/InputAdornment";
import SearchIcon from "@mui/icons-material/Search";
import { Table, TableAction, TableContainer, TableHeader, useTableState } from "@components/Table";
import { usePermission } from "@components/PermissionGuard";
import { Customer, customers } from "./data";
const Customers = () => {
const { pagination, handlePaginationChange } = useTableState();
const canAddCustomer = usePermission(["reaction:legacy:accounts/create"]);
const columns = useMemo((): ColumnDef<Customer>[] => [
{
id: "name",
header: "Name",
cell: (info) =>
<Stack direction="row" gap={2} alignItems="center">
<Avatar alt={info.row.original.name}>{info.row.original.name[0]}</Avatar>
{info.row.original.name}
</Stack>
},
{
accessorKey: "email",
header: "Email"
},
{
id: "location",
header: "Location",
cell: (info) => {
const { state, city, country } = info.row.original.address;
return `${state}, ${city}, ${country}`;
}
},
{
accessorKey: "phone",
header: "Phone"
},
{
accessorKey: "createdAt",
header: "Registration date",
cell: (data) => new Intl.DateTimeFormat("en-US").format(data.getValue())
}
], []);
return (
<Container maxWidth={false} sx={{ padding: "20px 30px" }}>
<TableContainer>
<TableHeader title="Customers" action={canAddCustomer ? <TableAction>Add</TableAction> : undefined}/>
<Box sx={{ maxWidth: 300, pl: 2.5, mt: 1 }}>
<TextField
size="small"
fullWidth
InputProps={{
startAdornment: (
<InputAdornment position="start">
<SearchIcon fontSize="small"/>
</InputAdornment>
)
}}
placeholder="Search customer"
variant="outlined"
/>
</Box>
<Table columns={columns}
data={customers.slice(pagination.pageIndex * pagination.pageSize, pagination.pageSize + pagination.pageIndex * pagination.pageSize)}
totalCount={customers.length}
tableState={{ pagination }}
onPaginationChange={handlePaginationChange}
/>
</TableContainer>
</Container>
);
};
export default Customers;