update
This commit is contained in:
@@ -20,10 +20,12 @@ class CorporateBenefitController extends Controller
|
||||
$benefits = CorporateBenefit::query()
|
||||
->filter($request->all())
|
||||
->where('corporate_id', $corporate_id)
|
||||
->paginate(0)
|
||||
->with('benefit', 'plan')
|
||||
->paginate(10)
|
||||
->appends($request->all());
|
||||
return $benefits;
|
||||
}
|
||||
|
||||
public function activation(Request $request, $benefit_id)
|
||||
{
|
||||
$request->validate([
|
||||
@@ -31,9 +33,8 @@ class CorporateBenefitController extends Controller
|
||||
]);
|
||||
|
||||
// abort(404);
|
||||
|
||||
$benefit = CorporateBenefit::findOrFail($benefit_id);
|
||||
$benefit->active = $request->active == '1';
|
||||
$benefit = CorporateBenefit::find($benefit_id);
|
||||
$benefit->active = $request->active == 1 ? 0 : 1;
|
||||
$benefit->reason = $request->reason;
|
||||
|
||||
if ($benefit->save()) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// @mui
|
||||
import * as Yup from 'yup';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -38,6 +39,8 @@ import HistoryIcon from '@mui/icons-material/History';
|
||||
import CachedOutlinedIcon from '@mui/icons-material/CachedOutlined';
|
||||
import FindInPageOutlinedIcon from '@mui/icons-material/FindInPageOutlined';
|
||||
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
// hooks
|
||||
import React, { ChangeEvent, Component, useEffect, useRef, useState } from 'react';
|
||||
@@ -72,6 +75,7 @@ import TableMoreMenu from '@/components/table/TableMoreMenu';
|
||||
import { Edit } from '@mui/icons-material';
|
||||
import { fData, fNumber } from '@/utils/formatNumber';
|
||||
import DialogUpdateStatus from '@/components/DialogUpdateStatus';
|
||||
import { ro } from 'date-fns/locale';
|
||||
|
||||
export default function PlanList() {
|
||||
const { themeStretch } = useSettings();
|
||||
@@ -313,12 +317,18 @@ export default function PlanList() {
|
||||
}
|
||||
|
||||
type DataContent = {
|
||||
code: string;
|
||||
name: string;
|
||||
service: string;
|
||||
id: number;
|
||||
status: string|number;
|
||||
status: number;
|
||||
plan: string,
|
||||
benefit_code: string,
|
||||
customer_benefit_code: string,
|
||||
};
|
||||
|
||||
type FormValuesProps = {
|
||||
value: string;
|
||||
active: boolean;
|
||||
};
|
||||
|
||||
// Generate the every row of the table
|
||||
const [isDialogOpen, setDialogOpen] = useState(false)
|
||||
@@ -335,6 +345,14 @@ export default function PlanList() {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [openEdit, setOpenEdit] = React.useState(false);
|
||||
|
||||
const handleActivate = (isOpen: boolean, dataValue: DataContent) => {
|
||||
console.log(dataValue)
|
||||
setDialogOpen(isOpen)
|
||||
setDataValue(dataValue)
|
||||
setDescriptionValue('Are you sure to inactive this service ?')
|
||||
setUrl(url)
|
||||
};
|
||||
|
||||
// const handleActivate = (model: any, status: string) => {
|
||||
// axios
|
||||
// .put(`/benefits/${row.id}/activation`, {
|
||||
@@ -362,14 +380,6 @@ export default function PlanList() {
|
||||
// });
|
||||
// };
|
||||
|
||||
|
||||
const handleActivate = (isOpen: boolean, dataValue: DataContent) => {
|
||||
setDialogOpen(isOpen)
|
||||
setDataValue(dataValue)
|
||||
setDescriptionValue('Are you sure to inactive this service ?')
|
||||
setUrl(url)
|
||||
};
|
||||
|
||||
let frequency_period_name: string
|
||||
switch (row.max_frequency_period) {
|
||||
case '1' :
|
||||
@@ -476,7 +486,18 @@ export default function PlanList() {
|
||||
<HistoryIcon />
|
||||
History
|
||||
</MenuItem>
|
||||
<MenuItem onClick={() => handleActivate(true, {code: row.code, name: row.service_code, id:row.id, status: row.active}) }>
|
||||
<MenuItem
|
||||
onClick={() =>
|
||||
handleActivate(true, {
|
||||
service: row.benefit?.service_code,
|
||||
plan: row.plan?.code,
|
||||
benefit_code: row.benefit?.code,
|
||||
customer_benefit_code: row.corporate_benefit_code,
|
||||
id:row.id,
|
||||
status: row.active
|
||||
})
|
||||
}
|
||||
>
|
||||
<CachedOutlinedIcon />
|
||||
Update Status
|
||||
</MenuItem>
|
||||
@@ -866,7 +887,7 @@ export default function PlanList() {
|
||||
const loadDataTableData = async (appliedFilter = null) => {
|
||||
setDataTableLoading(true);
|
||||
const filter = appliedFilter ? appliedFilter : Object.fromEntries([...searchParams.entries()]);
|
||||
const response = await axios.get('/corporates/' + corporate_id + '/benefits', {
|
||||
const response = await axios.get('/corporates/' + corporate_id + '/corporate-benefits', {
|
||||
params: filter,
|
||||
});
|
||||
// console.log(response.data);
|
||||
@@ -879,6 +900,19 @@ export default function PlanList() {
|
||||
fontWeight: 'bold',
|
||||
};
|
||||
|
||||
const onSubmit = async (row : any) => {
|
||||
try {
|
||||
handleUpdate(dataValue.status, dataValue.id, row.reason)
|
||||
} catch (error: any) {
|
||||
console.log('data gagal');
|
||||
}
|
||||
|
||||
const ascent = document?.querySelector('ascent');
|
||||
if (ascent != null) {
|
||||
ascent.innerHTML = '';
|
||||
}
|
||||
};
|
||||
|
||||
const applyFilter = async (searchFilter: string) => {
|
||||
await loadDataTableData({ search: searchFilter });
|
||||
setSearchParams({ search: searchFilter });
|
||||
@@ -894,25 +928,64 @@ export default function PlanList() {
|
||||
loadDataTableData();
|
||||
}, []);
|
||||
|
||||
const NewCorporateSchema = Yup.object().shape({
|
||||
reason: Yup.string().required('Reason Edit is required'),
|
||||
});
|
||||
|
||||
const methods = useForm<FormValuesProps>({
|
||||
resolver: yupResolver(NewCorporateSchema),
|
||||
});
|
||||
|
||||
|
||||
const {
|
||||
reset,
|
||||
handleSubmit,
|
||||
formState: { isSubmitting },
|
||||
} = methods;
|
||||
|
||||
const handleUpdate = (active: number, id: number, reason:string) => {
|
||||
console.log(active)
|
||||
axios
|
||||
.put(`/benefits/${id}/activation`, {
|
||||
active: active,
|
||||
reason: reason
|
||||
})
|
||||
.then((res) => {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const getContent = () => (
|
||||
<>
|
||||
<Stack paddingX={2} paddingY={2}>
|
||||
<Typography variant='subtitle1'>Are you sure to {dataValue?.status == 1 ? 'inactive' : 'active'} this service ?</Typography>
|
||||
<Typography variant='subtitle1'>Are you sure to {dataValue?.status == 1 ? 'inactive' : 'active'} this benefit ?</Typography>
|
||||
</Stack>
|
||||
<Card>
|
||||
<Grid container paddingX={2} paddingY={2}>
|
||||
<Grid item xs={4} md={4}>
|
||||
<Grid item xs={5} md={5}>
|
||||
<Typography variant='inherit'>Service</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={7}>
|
||||
<Typography variant='subtitle1'>{dataValue?.service}</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={5} md={5} marginTop={2}>
|
||||
<Typography variant='inherit'>Plan</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={7} marginTop={2}>
|
||||
<Typography variant='subtitle1'>{dataValue?.plan}</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={5} md={5} marginTop={2}>
|
||||
<Typography variant='inherit'>Code</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={8}>
|
||||
<Typography variant='subtitle1'>{dataValue?.code}</Typography>
|
||||
<Grid item xs={7} marginTop={2}>
|
||||
<Typography variant='subtitle1'>{dataValue?.benefit_code}</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={4} md={4} marginTop={2}>
|
||||
<Typography variant='inherit'>Service Name</Typography>
|
||||
<Grid item xs={5} md={5} marginTop={2}>
|
||||
<Typography variant='inherit'>Customer Benefit Code</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={8} marginTop={2}>
|
||||
<Typography variant='subtitle1'>{dataValue?.name}</Typography>
|
||||
<Grid item xs={7} marginTop={2}>
|
||||
<Typography variant='subtitle1'>{dataValue?.customer_benefit_code}</Typography>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Card>
|
||||
@@ -1058,7 +1131,7 @@ export default function PlanList() {
|
||||
title={{ name: 'Reason For Update' }}
|
||||
/>
|
||||
)}
|
||||
{/* <DialogUpdateStatus
|
||||
<DialogUpdateStatus
|
||||
openDialog={isDialogOpen}
|
||||
setOpenDialog={setDialogOpen}
|
||||
title={titles}
|
||||
@@ -1066,7 +1139,7 @@ export default function PlanList() {
|
||||
description={dataDescription}
|
||||
content={getContent()}
|
||||
// maxWidth='50px'
|
||||
/> */}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -155,6 +155,7 @@ export default function CustomizedAccordions() {
|
||||
if (key !== 'reason') {
|
||||
return null; // Melewati iterasi saat key adalah 'deleted_by'
|
||||
}
|
||||
|
||||
renderedValue = item.new_values[key];
|
||||
|
||||
const field = key.charAt(0).toUpperCase() + key.slice(1);
|
||||
|
||||
@@ -514,7 +514,7 @@ export default function List(props: any) {
|
||||
<TableCell align="left" onClick={() => {if(open==true) setOpen(!open)}}>
|
||||
{row.active == 1 && (
|
||||
<Label
|
||||
variant="outlined"
|
||||
variant="ghost"
|
||||
color="success"
|
||||
size="small"
|
||||
>
|
||||
@@ -523,7 +523,7 @@ export default function List(props: any) {
|
||||
)}
|
||||
{row.active != 1 && (
|
||||
<Label
|
||||
variant="outlined"
|
||||
variant="ghost"
|
||||
color="error"
|
||||
size="small"
|
||||
>
|
||||
|
||||
@@ -854,7 +854,7 @@ export default function CorporatePlanList() {
|
||||
.then((res) => {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const getContent = () => (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user