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