fix dashboard table
This commit is contained in:
@@ -17,7 +17,7 @@ class DashboardController extends Controller
|
|||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
$data = DashboardResources::make($user->managedCorporates()->where('active', 1)->with('currentPolicy', 'employees')->first());
|
$data = DashboardResources::make($user->managedCorporates()->where('active', 1)->with('currentPolicy')->first());
|
||||||
|
|
||||||
return response()->json($data);
|
return response()->json($data);
|
||||||
}
|
}
|
||||||
|
|||||||
120
Modules/Client/Http/Controllers/Api/DivisionController.php
Executable file
120
Modules/Client/Http/Controllers/Api/DivisionController.php
Executable file
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Client\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Models\CorporateDivision;
|
||||||
|
use Illuminate\Contracts\Support\Renderable;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Controller;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class DivisionController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
* @return Renderable
|
||||||
|
*/
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
|
||||||
|
$corporate = $user->managedCorporates()->where('active', 1)->first();
|
||||||
|
|
||||||
|
$benefits = CorporateDivision::query()
|
||||||
|
->where('corporate_id', $corporate->id)
|
||||||
|
->get(['id', 'name']);
|
||||||
|
|
||||||
|
return $benefits;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for creating a new resource.
|
||||||
|
* @return Renderable
|
||||||
|
*/
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
return view('internal::create');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
* @param Request $request
|
||||||
|
* @return Renderable
|
||||||
|
*/
|
||||||
|
public function store(Request $request, $corporate_id)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'code' => [
|
||||||
|
'required',
|
||||||
|
],
|
||||||
|
'name' => 'required'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$newCorporatePlan = CorporateDivision::create([
|
||||||
|
'corporate_id' => $corporate_id,
|
||||||
|
'code' => $request->code,
|
||||||
|
'name' => $request->name,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $newCorporatePlan;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the specified resource.
|
||||||
|
* @param int $id
|
||||||
|
* @return Renderable
|
||||||
|
*/
|
||||||
|
public function show($id)
|
||||||
|
{
|
||||||
|
return view('internal::show');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for editing the specified resource.
|
||||||
|
* @param int $id
|
||||||
|
* @return Renderable
|
||||||
|
*/
|
||||||
|
public function edit($corporate_id, $id)
|
||||||
|
{
|
||||||
|
$corporatePlan = CorporateDivision::findOrFail($id);
|
||||||
|
|
||||||
|
return $corporatePlan;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
* @param Request $request
|
||||||
|
* @param int $id
|
||||||
|
* @return Renderable
|
||||||
|
*/
|
||||||
|
public function update(Request $request, $corporate_id, $id)
|
||||||
|
{
|
||||||
|
$corporatePlan = CorporateDivision::findOrFail($id);
|
||||||
|
$request->validate([
|
||||||
|
'code' => [
|
||||||
|
'required',
|
||||||
|
Rule::unique('corporate_plans')->where('corporate_id', $corporate_id)->ignore($corporatePlan->id)
|
||||||
|
],
|
||||||
|
'name' => 'required'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$corporatePlan->fill([
|
||||||
|
'code' => $request->code,
|
||||||
|
'name' => $request->name,
|
||||||
|
'active' => $request->active,
|
||||||
|
])->save();
|
||||||
|
|
||||||
|
return $corporatePlan;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
* @param int $id
|
||||||
|
* @return Renderable
|
||||||
|
*/
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
use Modules\Client\Http\Controllers\Api\AuthController;
|
use Modules\Client\Http\Controllers\Api\AuthController;
|
||||||
use Modules\Client\Http\Controllers\Api\CorporateController;
|
use Modules\Client\Http\Controllers\Api\CorporateController;
|
||||||
use Modules\Client\Http\Controllers\Api\DashboardController;
|
use Modules\Client\Http\Controllers\Api\DashboardController;
|
||||||
|
use Modules\Client\Http\Controllers\Api\DivisionController;
|
||||||
use Modules\Client\Http\Controllers\Api\MemberController;
|
use Modules\Client\Http\Controllers\Api\MemberController;
|
||||||
use Modules\Client\Http\Controllers\Api\UserController;
|
use Modules\Client\Http\Controllers\Api\UserController;
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ Route::prefix('client')->group(function () {
|
|||||||
Route::get('dashboard', [DashboardController::class, 'index']);
|
Route::get('dashboard', [DashboardController::class, 'index']);
|
||||||
Route::get('corporate', [CorporateController::class, 'index']);
|
Route::get('corporate', [CorporateController::class, 'index']);
|
||||||
Route::get('corporate/{corporate_id}', [CorporateController::class, 'show']);
|
Route::get('corporate/{corporate_id}', [CorporateController::class, 'show']);
|
||||||
|
Route::get('division', [DivisionController::class, 'index']);
|
||||||
Route::get('members', [MemberController::class, 'index']);
|
Route::get('members', [MemberController::class, 'index']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Modules\Client\Transformers;
|
namespace Modules\Client\Transformers;
|
||||||
|
|
||||||
|
use App\Helpers\Helper;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
class DashboardResources extends JsonResource
|
class DashboardResources extends JsonResource
|
||||||
|
|||||||
25
Modules/Client/Transformers/MemberResources.php
Normal file
25
Modules/Client/Transformers/MemberResources.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Client\Transformers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class MemberResources extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'memberId' => $this->member_id,
|
||||||
|
'full_name' => $this->full_name,
|
||||||
|
'division' => $this->division->name,
|
||||||
|
'employeeLimit' => '',
|
||||||
|
'status' => $this->active
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,10 +44,10 @@ class Corporate extends Model
|
|||||||
public function currentPolicy()
|
public function currentPolicy()
|
||||||
{
|
{
|
||||||
return $this->hasOne(CorporatePolicy::class)
|
return $this->hasOne(CorporatePolicy::class)
|
||||||
// ->where('start', '<=', now())
|
// ->where('start', '<=', now())
|
||||||
// ->where('end', '>=', now())
|
// ->where('end', '>=', now())
|
||||||
->where('active', true)
|
->where('active', true)
|
||||||
->latestOfMany();
|
->latestOfMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function corporatePlans()
|
public function corporatePlans()
|
||||||
|
|||||||
@@ -19,4 +19,9 @@ class CorporateEmployee extends Model
|
|||||||
'nik',
|
'nik',
|
||||||
'status'
|
'status'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function division()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(CorporateDivision::class, 'division_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,4 +182,14 @@ class Member extends Model
|
|||||||
// });
|
// });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public function corporateEmployee()
|
||||||
|
// {
|
||||||
|
// return $this->hasOne(CorporateEmployee::class, 'member_id');
|
||||||
|
// }
|
||||||
|
|
||||||
|
public function division()
|
||||||
|
{
|
||||||
|
return $this->hasOneThrough(CorporateDivision::class, CorporateEmployee::class, 'member_id', 'id', 'id', 'division_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,8 +59,9 @@ export default function Dashboard() {
|
|||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const [corporateValue, setCorporateValue] = useState(`1`);
|
const [corporateValue, setCorporateValue] = useState(`${user.corporate.id}`);
|
||||||
const [corporateData, setCorporateData] = useState([]);
|
const [corporateData, setCorporateData] = useState([]);
|
||||||
|
const [tableData, setTableData] = useState([]);
|
||||||
const [policyData, setPolicyData] = useState<CardBalanceProps>({
|
const [policyData, setPolicyData] = useState<CardBalanceProps>({
|
||||||
myLimit: {
|
myLimit: {
|
||||||
balance: 0,
|
balance: 0,
|
||||||
@@ -82,6 +83,8 @@ export default function Dashboard() {
|
|||||||
const corporates = await axios.get('corporate');
|
const corporates = await axios.get('corporate');
|
||||||
const dashboard = await axios.get('dashboard');
|
const dashboard = await axios.get('dashboard');
|
||||||
|
|
||||||
|
console.log(dashboard);
|
||||||
|
|
||||||
setCorporateData(corporates.data);
|
setCorporateData(corporates.data);
|
||||||
setPolicyData(dashboard.data.policy);
|
setPolicyData(dashboard.data.policy);
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ export default function CardBalance(props: CardBalanceProps) {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography sx={{ typography: 'caption', color: '#637381' }}>
|
<Typography sx={{ typography: 'caption', color: '#637381' }}>
|
||||||
{lockLimit ? lockLimit.balance : 0}
|
{lockLimit ? lockLimit.balance : 0} / {myLimit ? myLimit.total : 0}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,16 @@ import {
|
|||||||
IconButton,
|
IconButton,
|
||||||
Card,
|
Card,
|
||||||
Grid,
|
Grid,
|
||||||
Autocomplete,
|
FormControl,
|
||||||
|
InputLabel,
|
||||||
|
Select,
|
||||||
|
MenuItem,
|
||||||
|
SelectChangeEvent,
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { visuallyHidden } from '@mui/utils';
|
import { visuallyHidden } from '@mui/utils';
|
||||||
import { Add as AddIcon } from '@mui/icons-material';
|
import { Add as AddIcon } from '@mui/icons-material';
|
||||||
/* ---------------------------------- axios --------------------------------- */
|
/* ---------------------------------- axios --------------------------------- */
|
||||||
import axios from 'axios';
|
import axios from '../../utils/axios';
|
||||||
/* ---------------------------------- react --------------------------------- */
|
/* ---------------------------------- react --------------------------------- */
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
/* -------------------------------- component ------------------------------- */
|
/* -------------------------------- component ------------------------------- */
|
||||||
@@ -63,6 +67,11 @@ interface EnhancedTableProps {
|
|||||||
order: Order;
|
order: Order;
|
||||||
orderBy: string;
|
orderBy: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DivisionDataProps = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* -------------------------- enchanced table head -------------------------- */
|
/* -------------------------- enchanced table head -------------------------- */
|
||||||
@@ -140,13 +149,12 @@ function EnhancedTableHead({ order, orderBy, onRequestSort }: EnhancedTableProps
|
|||||||
}
|
}
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
export default function TableList() {
|
export default function TableList(props: any) {
|
||||||
const [order, setOrder] = useState<Order>('asc');
|
const [order, setOrder] = useState<Order>('asc');
|
||||||
const [orderBy, setOrderBy] = useState('name');
|
const [orderBy, setOrderBy] = useState('name');
|
||||||
const [customSearchParams, setCustomSearchParams] = useSearchParams();
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [dataTable, setDataTable] = useState([]);
|
const [dataTable, setDataTable] = useState([]);
|
||||||
const [dataDivision, setDataDivision] = useState([]);
|
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
const [rowsPerPage, setRowsPerPage] = useState(10);
|
const [rowsPerPage, setRowsPerPage] = useState(10);
|
||||||
const [appliedParams, setAppliedParams] = useState({});
|
const [appliedParams, setAppliedParams] = useState({});
|
||||||
@@ -167,7 +175,7 @@ export default function TableList() {
|
|||||||
setOrder(isAsc ? 'desc' : 'asc');
|
setOrder(isAsc ? 'desc' : 'asc');
|
||||||
setOrderBy(property);
|
setOrderBy(property);
|
||||||
const params = Object.fromEntries([
|
const params = Object.fromEntries([
|
||||||
...customSearchParams.entries(),
|
...searchParams.entries(),
|
||||||
['order', isAsc ? 'desc' : 'asc'],
|
['order', isAsc ? 'desc' : 'asc'],
|
||||||
['orderBy', property],
|
['orderBy', property],
|
||||||
]);
|
]);
|
||||||
@@ -177,9 +185,24 @@ export default function TableList() {
|
|||||||
|
|
||||||
/* ----------------------------- Field Container ---------------------------- */
|
/* ----------------------------- Field Container ---------------------------- */
|
||||||
/* ----------------------------- division field ----------------------------- */
|
/* ----------------------------- division field ----------------------------- */
|
||||||
const optionDivisions = ['All'];
|
const [divisionValue, setDivisionValue] = useState('all');
|
||||||
|
const [divisionData, setDivisionData] = useState([]);
|
||||||
|
|
||||||
const [value, setValue] = useState<string | null>(optionDivisions[0]);
|
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 ------------------------------ */
|
/* ------------------------------ Search field ------------------------------ */
|
||||||
@@ -188,7 +211,7 @@ export default function TableList() {
|
|||||||
const handleSearchSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
const handleSearchSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const params = Object.fromEntries([...customSearchParams.entries(), ['search', searchText]]);
|
const params = Object.fromEntries([...searchParams.entries(), ['search', searchText]]);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
setAppliedParams(params);
|
setAppliedParams(params);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
@@ -223,12 +246,12 @@ export default function TableList() {
|
|||||||
newPage: number
|
newPage: number
|
||||||
) => {
|
) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const params = Object.fromEntries([...customSearchParams.entries(), ['page', newPage + 1]]);
|
const params = Object.fromEntries([...searchParams.entries(), ['page', newPage + 1]]);
|
||||||
setPage(newPage);
|
setPage(newPage);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||||
setAppliedParams(params);
|
setAppliedParams(params);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
// setCustomSearchParams.set('page', newPage + 1);
|
// setSearchParams.set('page', newPage + 1);
|
||||||
};
|
};
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
@@ -237,7 +260,7 @@ export default function TableList() {
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setPage(0);
|
setPage(0);
|
||||||
const params = Object.fromEntries([
|
const params = Object.fromEntries([
|
||||||
...customSearchParams.entries(),
|
...searchParams.entries(),
|
||||||
['per_page', parseInt(event.target.value, 10)],
|
['per_page', parseInt(event.target.value, 10)],
|
||||||
]);
|
]);
|
||||||
setRowsPerPage(parseInt(event.target.value, 10));
|
setRowsPerPage(parseInt(event.target.value, 10));
|
||||||
@@ -252,29 +275,27 @@ export default function TableList() {
|
|||||||
(async () => {
|
(async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
|
const division = await axios.get('/division');
|
||||||
|
setDivisionData(division.data);
|
||||||
|
|
||||||
const params =
|
const params =
|
||||||
Object.keys(appliedParams).length !== 0
|
Object.keys(appliedParams).length !== 0
|
||||||
? appliedParams
|
? appliedParams
|
||||||
: Object.fromEntries([
|
: Object.fromEntries([...searchParams.entries(), ['order', order], ['orderBy', orderBy]]);
|
||||||
...customSearchParams.entries(),
|
|
||||||
['order', order],
|
|
||||||
['orderBy', orderBy],
|
|
||||||
]);
|
|
||||||
|
|
||||||
const response = await axios.get('http://localhost:8001/api/dashboard', {
|
const response = await axios.get('/dashboard', {
|
||||||
params: params,
|
params: params,
|
||||||
});
|
});
|
||||||
|
|
||||||
const division = await axios.get('http://localhost:8001/api/division');
|
console.log(response);
|
||||||
setDataDivision(division.data);
|
|
||||||
|
|
||||||
setCustomSearchParams(params);
|
setSearchParams(params);
|
||||||
setDataTable(response.data.data);
|
// setDataTable(response.data.data);
|
||||||
setPaginationTable(response.data.meta);
|
// setPaginationTable(response.data.meta);
|
||||||
setRowsPerPage(response.data.meta.per_page);
|
// setRowsPerPage(response.data.meta.per_page);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
})();
|
})();
|
||||||
}, [appliedParams, customSearchParams, order, orderBy, setCustomSearchParams]);
|
}, [appliedParams, searchParams, order, orderBy, setSearchParams]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
@@ -283,15 +304,23 @@ export default function TableList() {
|
|||||||
<Grid item xs={12} paddingX="24px" paddingY="20px">
|
<Grid item xs={12} paddingX="24px" paddingY="20px">
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<Grid item xs={12} lg={3} xl={2}>
|
<Grid item xs={12} lg={3} xl={2}>
|
||||||
<Autocomplete
|
<FormControl fullWidth>
|
||||||
disablePortal
|
<InputLabel id="simple-division-select-lable">Division</InputLabel>
|
||||||
options={optionDivisions}
|
<Select
|
||||||
value={value}
|
labelId="simple-division-select-lable"
|
||||||
onChange={(event: any, newValue: string | null) => {
|
id="division-select-lable"
|
||||||
setValue(newValue);
|
value={divisionValue}
|
||||||
}}
|
label="Division"
|
||||||
renderInput={(params) => <TextField {...params} label="Division" />}
|
onChange={handleDivisionChange}
|
||||||
/>
|
>
|
||||||
|
<MenuItem value="all">All</MenuItem>
|
||||||
|
{divisionData.map((row: DivisionDataProps, index) => (
|
||||||
|
<MenuItem key={index} value={row.id}>
|
||||||
|
{row.name}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12} lg={5} xl={6}>
|
<Grid item xs={12} lg={5} xl={6}>
|
||||||
<form onSubmit={handleSearchSubmit}>
|
<form onSubmit={handleSearchSubmit}>
|
||||||
|
|||||||
Reference in New Issue
Block a user