Dummy Members

This commit is contained in:
2022-05-26 16:43:59 +07:00
parent e8bb61be2f
commit 40d680287e
4 changed files with 190 additions and 27 deletions

View File

@@ -14,7 +14,25 @@ class MemberController extends Controller
*/ */
public function index() public function index()
{ {
// $members = [];
$faker = \Faker\Factory::create();
for ($i = 0; $i < 10; $i++) {
$members[] = [
'id' => (10-$i),
'code' => 'UT0000'.sprintf("%02d", 10-$i),
'nik' => 'UNTR0000'.sprintf("%02d", $i),
'name' => $faker->name,
'plan_code' => collect(['PLAN001', 'PLAN002', 'PLAN003', 'PLAN004', 'PLAN005'])->random(),
'number_of_families' => random_int(2,4),
'number_of_claim' => random_int(0,2),
'active' => true,
'history' => []
];
}
return $members;
} }
/** /**

View File

@@ -13,7 +13,7 @@ export default function NavbarDocs() {
> >
<DocIllustration sx={{ width: 1 }} /> <DocIllustration sx={{ width: 1 }} />
<div> {/* <div>
<Typography gutterBottom variant="subtitle1"> <Typography gutterBottom variant="subtitle1">
Hi, Rayan Moran Hi, Rayan Moran
</Typography> </Typography>
@@ -23,7 +23,7 @@ export default function NavbarDocs() {
</Typography> </Typography>
</div> </div>
<Button variant="contained">Documentation</Button> <Button variant="contained">Documentation</Button> */}
</Stack> </Stack>
); );
} }

View File

@@ -1,7 +1,8 @@
// @mui // @mui
import { Box, Button, Card, Collapse, Container, IconButton, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography } from '@mui/material'; import { Box, Button, Card, Collapse, Container, FormControl, Grid, IconButton, InputLabel, MenuItem, OutlinedInput, Paper, Select, SelectChangeEvent, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField, Typography, Badge } from '@mui/material';
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight'; import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
import PublishIcon from '@mui/icons-material/Publish';
// hooks // hooks
import useSettings from '../../hooks/useSettings'; import useSettings from '../../hooks/useSettings';
// components // components
@@ -9,7 +10,8 @@ import Page from '../../components/Page';
import axios from '../../utils/axios'; import axios from '../../utils/axios';
import useAuth from '../../hooks/useAuth'; import useAuth from '../../hooks/useAuth';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import React from 'react'; import React, { useEffect, useRef } from 'react';
import { Theme, useTheme } from '@mui/material/styles';
export default function Members() { export default function Members() {
const { themeStretch } = useSettings(); const { themeStretch } = useSettings();
@@ -29,7 +31,7 @@ export default function Members() {
number_of_families: number; number_of_families: number;
number_of_claim: number; number_of_claim: number;
active: boolean; active: boolean;
history?: []; history: any[];
} }
function createData( member: Member ): Member { function createData( member: Member ): Member {
@@ -72,6 +74,7 @@ export default function Members() {
<TableCell align="right">{row.plan_code}</TableCell> <TableCell align="right">{row.plan_code}</TableCell>
<TableCell align="right">{row.number_of_claim}</TableCell> <TableCell align="right">{row.number_of_claim}</TableCell>
<TableCell align="right">{row.number_of_families}</TableCell> <TableCell align="right">{row.number_of_families}</TableCell>
<TableCell align="right"><Button variant="outlined" color="success" size="small">Active</Button></TableCell>
</TableRow> </TableRow>
<TableRow> <TableRow>
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}> <TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6}>
@@ -98,7 +101,7 @@ export default function Members() {
<TableCell>{historyRow?.customerId}</TableCell> <TableCell>{historyRow?.customerId}</TableCell>
<TableCell align="right">{historyRow?.amount}</TableCell> <TableCell align="right">{historyRow?.amount}</TableCell>
<TableCell align="right"> <TableCell align="right">
{Math.round(historyRow?.amount * row.price * 100) / 100} {Math.round(historyRow?.amount * 1000 * 100) / 100}
</TableCell> </TableCell>
</TableRow> </TableRow>
)) ))
@@ -119,23 +122,86 @@ export default function Members() {
} }
// Dummy Default Data // Dummy Default Data
const rows = [ const [memberLoading, setMemberLoading] = React.useState(true);
createData({ const [members, setMembers] = React.useState<Member[]>([]);
id: 1,
code: 'MEMBERCODE', const loadMembers = async () => {
nik: 'SM12310003', setMemberLoading(true)
name: 'Dede Pardede', const response = await axios.get('/members');
plan_code: 'PLAN001', setMemberLoading(false)
number_of_families: 4, setMembers(response.data.map(createData));
number_of_claim: 0, }
active: true,
}) useEffect(() => {
]; loadMembers();
}, [])
const headStyle = { const headStyle = {
fontWeight: 'bold', fontWeight: 'bold',
}; };
// FILTER SELECT
const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
PaperProps: {
style: {
maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
width: 250,
},
},
};
const names = [
'PLAN001',
'PLAN002',
'PLAN003',
'PLAN004',
'PLAN005',
];
function getStyles(name: string, personName: string[], theme: Theme) {
return {
fontWeight:
personName.indexOf(name) === -1
? theme.typography.fontWeightRegular
: theme.typography.fontWeightMedium,
};
}
const theme = useTheme();
const [planIdFilter, setPlanIdFilter] = React.useState<string[]>([]);
const handleChangePlanID = (event: SelectChangeEvent<typeof planIdFilter>) => {
const {
target: { value },
} = event;
setPlanIdFilter(
// On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value,
);
};
const [statusFilter, setStatusFilter] = React.useState<string[]>([]);
const handleChangeStatus = (event: SelectChangeEvent<typeof statusFilter>) => {
const {
target: { value },
} = event;
setStatusFilter(
// On autofill we get a stringified value.
typeof value === 'string' ? value.split(',') : value,
);
};
// END FILTER SELECT
// IMPORT
const importMember = React.useRef(null);
const handleImportButton = (event: any) => {
if (importMember?.current)
importMember.current.click()
else
alert('No file selected')
}
return ( return (
<Page title="Member List"> <Page title="Member List">
<Container maxWidth={themeStretch ? false : 'xl'}> <Container maxWidth={themeStretch ? false : 'xl'}>
@@ -143,10 +209,68 @@ export default function Members() {
Member List Member List
</Typography> </Typography>
<Grid container spacing={2} sx={{ mb: 2 }} justifyContent="flex-end">
<Grid item>
<TextField id="outlined-basic" label="Search" variant="outlined" sx={{ width: 400 }}/>
</Grid>
<Typography variant="body1" component="p" paragraph> <Grid item>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat, delectus? Suscipit placeat tempora mollitia optio, assumenda maiores architecto officia itaque molestias cum id eligendi necessitatibus! A velit eos ratione ullam. <FormControl sx={{ width: 200 }}>
</Typography> <InputLabel id="plan-id-label">PlanID</InputLabel>
<Select
labelId="plan-id-label"
id="plan-id"
multiple
value={planIdFilter}
onChange={handleChangePlanID}
input={<OutlinedInput label="PlanID" />}
MenuProps={MenuProps}
>
{names.map((name) => (
<MenuItem
key={name}
value={name}
style={getStyles(name, planIdFilter, theme)}
>
{name}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
<Grid item>
<FormControl sx={{ width: 200 }}>
<InputLabel id="status-filter-label">Status</InputLabel>
<Select
labelId="status-filter-label"
id="status-filter"
multiple
value={statusFilter}
onChange={handleChangeStatus}
input={<OutlinedInput label="Status" />}
MenuProps={MenuProps}
>
{['Active', 'Suspended'].map((name) => (
<MenuItem
key={name}
value={name}
style={getStyles(name, statusFilter, theme)}
>
{name}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
<Grid item>
<input id="importMember" ref={importMember} style={{ display: 'none' }} type="file" accept='.csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, text/plain' />
<Button variant="outlined" startIcon={<PublishIcon />} sx={{ p: 1.8 }} onClick={handleImportButton}>
Import
</Button>
</Grid>
</Grid>
<Card> <Card>
<TableContainer component={Paper}> <TableContainer component={Paper}>
@@ -163,11 +287,29 @@ export default function Members() {
<TableCell style={headStyle} align="right">Status</TableCell> <TableCell style={headStyle} align="right">Status</TableCell>
</TableRow> </TableRow>
</TableBody> </TableBody>
<TableBody> {memberLoading ?
{rows.map((row, index) => ( (
<Row key={index} row={row} /> <TableBody>
))} <TableRow>
</TableBody> <TableCell colSpan={8} align="center">Loading</TableCell>
</TableRow>
</TableBody>
) : (
members.length == 0 ?
(
<TableBody>
<TableRow>
<TableCell colSpan={8} align="center">No Data</TableCell>
</TableRow>
</TableBody>
) : (
<TableBody>
{members.map(row => (
<Row key={row.code} row={row} />
))}
</TableBody>
)
)}
</Table> </Table>
</TableContainer> </TableContainer>
</Card> </Card>

View File

@@ -1,6 +1,7 @@
<?php <?php
use App\Http\Controllers\Api\AuthController; use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\MemberController;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
@@ -24,4 +25,6 @@ Route::middleware('auth:sanctum')->group(function() {
Route::get('/user', function (Request $request) { Route::get('/user', function (Request $request) {
return $request->user(); return $request->user();
}); });
Route::get('members', [MemberController::class, 'index'])->name('members.index');
}); });