diff --git a/frontend/client-portal/src/sections/dashboard/TableList.tsx b/frontend/client-portal/src/sections/dashboard/TableList.tsx deleted file mode 100755 index a077b4c4..00000000 --- a/frontend/client-portal/src/sections/dashboard/TableList.tsx +++ /dev/null @@ -1,443 +0,0 @@ -/* ---------------------------------- @mui ---------------------------------- */ -import { styled } from '@mui/material/styles'; -import { - Paper, - Table, - TableBody, - TableCell, - TableContainer, - TableHead, - TableRow, - TextField, - Button, - TableSortLabel, - Box, - IconButton, - Card, - Grid, - FormControl, - InputLabel, - Select, - MenuItem, - SelectChangeEvent, - Stack, - Typography, - LinearProgress, - linearProgressClasses, -} from '@mui/material'; -import { visuallyHidden } from '@mui/utils'; -/* ---------------------------------- axios --------------------------------- */ -import axios from '../../utils/axios'; -/* ---------------------------------- react --------------------------------- */ -import { useContext, useEffect, useState } from 'react'; -/* -------------------------------- component ------------------------------- */ -import Iconify from '../../components/Iconify'; -import BaseTablePagination from '../../components/BaseTablePagination'; -/* ---------------------------------- theme --------------------------------- */ -import palette from '../../theme/palette'; -import { useSearchParams } from 'react-router-dom'; -import { UserCurrentCorporateContext } from '../../contexts/UserCurrentCorporate'; -import { fSplit } from '../../utils/formatNumber'; - -/* ---------------------------------- types --------------------------------- */ -type PaginationTableProps = { - current_page: number; - from: number; - last_page: number; - links: []; - path: string; - per_page: number; - to: number; - total: number; -}; - -type DataTableProps = { - fullName: string; - memberId: string; - division: string; - limit: { - current: number; - total: number; - percentage: number; - }; - status: number; -}; - -type Order = 'asc' | 'desc'; - -interface HeadCell { - id: string; - align: string; - label: string; - isSort: boolean; -} - -interface EnhancedTableProps { - onRequestSort: (event: React.MouseEvent, property: string) => void; - order: Order; - orderBy: string; -} - -type DivisionDataProps = { - id: number; - name: string; -}; -/* -------------------------------------------------------------------------- */ - -/* --------------------------------- styled --------------------------------- */ -const BorderLinearProgress = styled(LinearProgress)(({ theme }) => ({ - height: 10, - borderRadius: 6, - [`&.${linearProgressClasses.colorPrimary}`]: { - backgroundColor: '#D1F1F1', - }, - [`& .${linearProgressClasses.bar}`]: { - borderRadius: 6, - backgroundColor: theme.palette.primary.main, - }, -})); -/* -------------------------------------------------------------------------- */ - -/* -------------------------- enchanced table head -------------------------- */ -const headCells: readonly HeadCell[] = [ - { - id: 'member_id', - align: 'left', - label: 'Member ID', - isSort: true, - }, - { - id: 'name', - align: 'center', - label: 'Name', - isSort: true, - }, - { - id: 'division', - align: 'center', - label: 'Divisi', - isSort: false, - }, - { - id: 'limit', - align: 'center', - label: 'Limit', - isSort: false, - }, - { - id: 'active', - align: 'center', - label: 'Status', - isSort: true, - }, -]; - -function EnhancedTableHead({ order, orderBy, onRequestSort }: EnhancedTableProps) { - const createSortHandler = (property: string) => (event: React.MouseEvent) => { - onRequestSort(event, property); - }; - - return ( - - - {headCells.map((headCell) => ( - - {headCell.isSort ? ( - - {headCell.label} - {orderBy === headCell.id ? ( - - {order === 'desc' ? 'sorted descending' : 'sorted ascending'} - - ) : null} - - ) : ( - headCell.label - )} - - ))} - {''} - - - ); -} -/* -------------------------------------------------------------------------- */ - -export default function TableList(props: any) { - const { corporateValue } = useContext(UserCurrentCorporateContext); - - const [dataTable, setDataTable] = useState([]); - const [paginationTable, setPaginationTable] = useState({ - current_page: 0, - from: 0, - last_page: 0, - links: [], - path: '', - per_page: 0, - to: 0, - total: 0, - }); - - const [isLoading, setIsLoading] = useState(true); - const [searchParams, setSearchParams] = useSearchParams(); - const [appliedParams, setAppliedParams] = useState({}); - - const [order, setOrder] = useState('asc'); - const [orderBy, setOrderBy] = useState('name'); - const [page, setPage] = useState(0); - const [rowsPerPage, setRowsPerPage] = useState(10); - - /* ------------------------------- handle sort ------------------------------ */ - const handleRequestSort = async (event: React.MouseEvent, property: string) => { - const isAsc = orderBy === property && order === 'asc'; - setOrder(isAsc ? 'desc' : 'asc'); - setOrderBy(property); - const params = Object.fromEntries([ - ...searchParams.entries(), - ['order', isAsc ? 'desc' : 'asc'], - ['orderBy', property], - ]); - setAppliedParams(params); - }; - /* -------------------------------------------------------------------------- */ - - /* ----------------------------- division field ----------------------------- */ - const [divisionValue, setDivisionValue] = useState('all'); - const [divisionData, setDivisionData] = useState([]); - - const handleDivisionChange = (event: SelectChangeEvent) => { - setDivisionValue(event.target.value as string); - - if (event.target.value === 'all') { - searchParams.delete('division'); - const params = Object.fromEntries([...searchParams.entries()]); - setAppliedParams(params); - } else { - const params = Object.fromEntries([ - ...searchParams.entries(), - ['division', event.target.value as string], - ]); - setAppliedParams(params); - } - }; - /* -------------------------------------------------------------------------- */ - - /* ------------------------------ Search field ------------------------------ */ - const [searchText, setSearchText] = useState(''); - - const handleSearchSubmit = async (event: React.FormEvent) => { - event.preventDefault(); - setIsLoading(true); - if (searchText === '') { - searchParams.delete('search'); - const params = Object.fromEntries([...searchParams.entries()]); - setAppliedParams(params); - } else { - const params = Object.fromEntries([...searchParams.entries(), ['search', searchText]]); - setAppliedParams(params); - } - await new Promise((resolve) => setTimeout(resolve, 500)); - setIsLoading(false); - }; - /* -------------------------------------------------------------------------- */ - - /* ------------------------ button change pagination ------------------------ */ - const onPageChangeHandle = async ( - event: React.MouseEvent | null, - newPage: number - ) => { - setIsLoading(true); - const params = Object.fromEntries([...searchParams.entries(), ['page', newPage + 1]]); - setPage(newPage); - await new Promise((resolve) => setTimeout(resolve, 500)); - setAppliedParams(params); - setIsLoading(false); - }; - /* -------------------------------------------------------------------------- */ - - /* --------------------------- row page per limit --------------------------- */ - const onRowsPerPageChangeHandle = async (event: React.ChangeEvent) => { - setIsLoading(true); - searchParams.delete('page'); - const params = Object.fromEntries([ - ...searchParams.entries(), - ['per_page', parseInt(event.target.value, 10)], - ]); - setRowsPerPage(parseInt(event.target.value, 10)); - await new Promise((resolve) => setTimeout(resolve, 500)); - setAppliedParams(params); - setIsLoading(false); - }; - /* -------------------------------------------------------------------------- */ - - useEffect(() => { - (async () => { - setIsLoading(true); - - const division = await axios.get(`${corporateValue}/division`); - setDivisionData(division.data); - - const params = - Object.keys(appliedParams).length !== 0 - ? appliedParams - : Object.fromEntries([...searchParams.entries(), ['order', order], ['orderBy', orderBy]]); - - const corporateMembers = await axios.get(`${corporateValue}/members`, { - params: { ...params, claimMember: false }, - }); - - setSearchParams(params); - setDataTable(corporateMembers.data.data); - setPaginationTable(corporateMembers.data); - setRowsPerPage(corporateMembers.data.per_page); - setIsLoading(false); - })(); - }, [appliedParams, searchParams, order, orderBy, setSearchParams, corporateValue]); - - return ( - - - {/* Field 1 */} - - - - - Division - - - - -
- setSearchText(event.target.value)} - value={searchText} - fullWidth - /> - -
-
-
- {/* End Field 1 */} - {/* Field 2 */} - - - - - - {isLoading ? ( - - - Loading . . . - - - ) : dataTable.length >= 1 ? ( - dataTable.map((row: DataTableProps, index) => ( - - {row.memberId} - {row.fullName} - {row.division} - - - - - {fSplit(row.limit.current)} / {fSplit(row.limit.total)} - - - - - {row.status === 1 ? ( - - ) : ( - - )} - - {/* - - - - */} - - )) - ) : ( - - - No Data Found - - - )} - -
-
- - {/* Pagination */} - -
- {/* End Field 2 */} -
-
- ); -}