add switch corporate & fix table & fix policy
This commit is contained in:
@@ -1,13 +1,5 @@
|
||||
// @mui
|
||||
import {
|
||||
Typography,
|
||||
Container,
|
||||
Grid,
|
||||
FormControl,
|
||||
InputLabel,
|
||||
MenuItem,
|
||||
Select,
|
||||
} from '@mui/material';
|
||||
import { Typography, Container, Grid } from '@mui/material';
|
||||
// hooks
|
||||
import useSettings from '../../hooks/useSettings';
|
||||
// components
|
||||
@@ -16,11 +8,10 @@ import Page from '../../components/Page';
|
||||
import CardNotification from '../../sections/dashboard/CardNotification';
|
||||
import CardBalance from '../../sections/dashboard/CardBalance';
|
||||
import TableList from '../../sections/dashboard/TableList';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useContext, useEffect, useState } from 'react';
|
||||
import axios from '../../utils/axios';
|
||||
import { Stack } from '@mui/system';
|
||||
import { SelectChangeEvent } from '@mui/material/Select';
|
||||
import useAuth from '../../hooks/useAuth';
|
||||
import { UserCurrentCorporateContext } from '../../contexts/UserCurrentCorporate';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@@ -35,12 +26,7 @@ const itemList = [
|
||||
|
||||
/* ---------------------------------- types --------------------------------- */
|
||||
|
||||
type CorporateDataProps = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
type CardBalanceProps = {
|
||||
type PolicyProps = {
|
||||
myLimit: {
|
||||
balance: number;
|
||||
total: number;
|
||||
@@ -54,42 +40,35 @@ type CardBalanceProps = {
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/* ------------------------------ default data ------------------------------ */
|
||||
const defaultPolicyData = {
|
||||
myLimit: {
|
||||
balance: 0,
|
||||
total: 0,
|
||||
percentage: 0,
|
||||
},
|
||||
lockLimit: {
|
||||
balance: 0,
|
||||
percentage: 0,
|
||||
},
|
||||
};
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
export default function Dashboard() {
|
||||
const { themeStretch } = useSettings();
|
||||
const { user } = useAuth();
|
||||
const [currentCorporate, setCurrentCorporate] = useState({id: 1});
|
||||
const { corporateValue } = useContext(UserCurrentCorporateContext);
|
||||
|
||||
// @ts-ignore
|
||||
const [corporateValue, setCorporateValue] = useState(`${user.corporate.id}`);
|
||||
const [corporateData, setCorporateData] = useState([]);
|
||||
const [tableData, setTableData] = useState([]);
|
||||
const [policyData, setPolicyData] = useState<CardBalanceProps>({
|
||||
myLimit: {
|
||||
balance: 0,
|
||||
total: 0,
|
||||
percentage: 0,
|
||||
},
|
||||
lockLimit: {
|
||||
balance: 0,
|
||||
percentage: 0,
|
||||
},
|
||||
});
|
||||
|
||||
const handleCorporateChange = (event: SelectChangeEvent) => {
|
||||
setCorporateValue(event.target.value as string);
|
||||
};
|
||||
// const [tableData, setTableData] = useState([]);
|
||||
const [policyData, setPolicyData] = useState<PolicyProps>(defaultPolicyData);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const corporates = await axios.get(`${currentCorporate.id}/dashboard`);
|
||||
const dashboard = await axios.get(`${currentCorporate.id}/dashboard`);
|
||||
|
||||
console.log(dashboard);
|
||||
|
||||
setCorporateData(corporates.data);
|
||||
setPolicyData(defaultPolicyData);
|
||||
await new Promise((resolve) => setTimeout(resolve, 250));
|
||||
const dashboard = await axios.get(`${corporateValue}/policy`);
|
||||
setPolicyData(dashboard.data.policy);
|
||||
})();
|
||||
}, [user, corporateValue]);
|
||||
}, [corporateValue]);
|
||||
|
||||
return (
|
||||
<Page title="Dashboard">
|
||||
@@ -98,24 +77,6 @@ export default function Dashboard() {
|
||||
<Typography variant="h3" component="h1" paragraph>
|
||||
Dashboard
|
||||
</Typography>
|
||||
|
||||
<FormControl>
|
||||
<InputLabel id="simple-corporate-select-lable">Corporate</InputLabel>
|
||||
<Select
|
||||
labelId="simple-corporate-select-lable"
|
||||
id="corporate-select-lable"
|
||||
value={corporateValue}
|
||||
label="Corporate"
|
||||
defaultValue={corporateValue}
|
||||
onChange={handleCorporateChange}
|
||||
>
|
||||
{corporateData.map((row: CorporateDataProps, index) => (
|
||||
<MenuItem key={index} value={row.id}>
|
||||
{row.name}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
</Stack>
|
||||
|
||||
<Grid container spacing={2}>
|
||||
|
||||
@@ -83,11 +83,7 @@ export default function Login() {
|
||||
</Box>
|
||||
</Stack>
|
||||
|
||||
<VerifyCodeForm
|
||||
setEmailOrPhoneForm={setEmailOrPhoneForm}
|
||||
setLoginOrVerifyCode={setLoginOrVerifyCode}
|
||||
emailOrPhone={emailOrPhone}
|
||||
/>
|
||||
<VerifyCodeForm emailOrPhone={emailOrPhone} />
|
||||
|
||||
<Stack sx={{ marginTop: 5 }} spacing={1} alignItems="center">
|
||||
<Typography>Tidak mendapatkan kode?</Typography>
|
||||
|
||||
Reference in New Issue
Block a user