view table alarm-center

This commit is contained in:
pajri
2023-05-04 16:59:18 +07:00
parent 12fbef2a12
commit 49f3a8558d

View File

@@ -15,9 +15,10 @@ import {
} from '@mui/material'; } from '@mui/material';
import { visuallyHidden } from '@mui/utils'; import { visuallyHidden } from '@mui/utils';
/* ---------------------------------- axios --------------------------------- */ /* ---------------------------------- axios --------------------------------- */
import axios from 'axios'; // import axios from 'axios';
import axios from '../../utils/axios';
/* ---------------------------------- react --------------------------------- */ /* ---------------------------------- react --------------------------------- */
import { useEffect, useState } from 'react'; import { useContext, useEffect, useState } from 'react';
/* -------------------------------- component ------------------------------- */ /* -------------------------------- component ------------------------------- */
import Iconify from '../../components/Iconify'; import Iconify from '../../components/Iconify';
import BaseTablePagination from '../../components/BaseTablePagination'; import BaseTablePagination from '../../components/BaseTablePagination';
@@ -25,6 +26,7 @@ import BaseTablePagination from '../../components/BaseTablePagination';
import useMap from '../../hooks/useMap'; import useMap from '../../hooks/useMap';
/* ---------------------------------- theme --------------------------------- */ /* ---------------------------------- theme --------------------------------- */
import palette from '../../theme/palette'; import palette from '../../theme/palette';
import { UserCurrentCorporateContext } from '../../contexts/UserCurrentCorporate';
/* ---------------------------------- types --------------------------------- */ /* ---------------------------------- types --------------------------------- */
@@ -40,12 +42,12 @@ type PaginationTableProps = {
}; };
type DataTableProps = { type DataTableProps = {
name: string; fullName: string;
member_id: string; memberId: string;
service: string; service: string;
start_date: string; start_date: string;
end_date: string; end_date: string;
status: string; status: boolean | number;
}; };
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@@ -130,8 +132,9 @@ function EnhancedTableHead(props: EnhancedTableProps) {
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
export default function List() { export default function List() {
const { corporateValue } = useContext(UserCurrentCorporateContext);
const [order, setOrder] = useState<Order>('asc'); const [order, setOrder] = useState<Order>('asc');
const [orderBy, setOrderBy] = useState('name'); const [orderBy, setOrderBy] = useState('');
const [customSearchParams, setCustomSearchParams] = useMap<string, any>(); const [customSearchParams, setCustomSearchParams] = useMap<string, any>();
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [dataTable, setDataTable] = useState([]); const [dataTable, setDataTable] = useState([]);
@@ -147,7 +150,6 @@ export default function List() {
to: 0, to: 0,
total: 0, total: 0,
}); });
/* ------------------------------- handle sort ------------------------------ */ /* ------------------------------- handle sort ------------------------------ */
const handleRequestSort = async (event: React.MouseEvent<unknown>, property: string) => { const handleRequestSort = async (event: React.MouseEvent<unknown>, property: string) => {
const isAsc = orderBy === property && order === 'asc'; const isAsc = orderBy === property && order === 'asc';
@@ -155,8 +157,8 @@ export default function List() {
setOrderBy(property); setOrderBy(property);
const params = Object.fromEntries([ const params = Object.fromEntries([
...customSearchParams.entries(), ...customSearchParams.entries(),
['order', isAsc ? 'desc' : 'asc'], // ['order', isAsc ? 'desc' : 'asc'],
['orderBy', property], // ['orderBy', property],
]); ]);
setIsLoading(true); setIsLoading(true);
await new Promise((resolve) => setTimeout(resolve, 500)); await new Promise((resolve) => setTimeout(resolve, 500));
@@ -190,14 +192,15 @@ export default function List() {
? appliedParams ? appliedParams
: Object.fromEntries([ : Object.fromEntries([
...customSearchParams.entries(), ...customSearchParams.entries(),
['order', order], // ['order', order],
['orderBy', orderBy], // ['orderBy', orderBy],
]); ]);
const response = await axios.get('http://localhost:8001/api/alarm-center', { params: params }); const response = await axios.get(`/${corporateValue}/members?type=alarm-center`, {
params: params,
});
setDataTable(response.data.data); setDataTable(response.data.data);
setPaginationTable(response.data.meta); setPaginationTable(response.data);
setRowsPerPage(response.data.meta.per_page); setRowsPerPage(response.data.per_page);
setIsLoading(false); setIsLoading(false);
}; };
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@@ -264,13 +267,13 @@ export default function List() {
dataTable.map((row: DataTableProps, index) => ( dataTable.map((row: DataTableProps, index) => (
<TableRow key={index}> <TableRow key={index}>
<TableCell align="center">{paginationTable.from + index++}</TableCell> <TableCell align="center">{paginationTable.from + index++}</TableCell>
<TableCell align="center">{row.name}</TableCell> <TableCell align="center">{row.fullName}</TableCell>
<TableCell align="center">{row.member_id}</TableCell> <TableCell align="center">{row.memberId}</TableCell>
<TableCell align="center">{row.service}</TableCell> <TableCell align="center">{row.service}</TableCell>
<TableCell align="center">{row.start_date}</TableCell> <TableCell align="center">{row.start_date}</TableCell>
<TableCell align="center">{row.end_date}</TableCell> <TableCell align="center">{row.end_date}</TableCell>
<TableCell align="center"> <TableCell align="center">
{row.status.toLowerCase() === 'done' ? ( {row.status === 1 ? (
<Button <Button
startIcon={<Iconify icon="ic:round-check" />} startIcon={<Iconify icon="ic:round-check" />}
sx={{ sx={{
@@ -284,7 +287,7 @@ export default function List() {
}, },
}} }}
> >
{row.status} done
</Button> </Button>
) : ( ) : (
<Button <Button
@@ -300,7 +303,7 @@ export default function List() {
}, },
}} }}
> >
{row.status} Ongoing
</Button> </Button>
)} )}
</TableCell> </TableCell>