From 94001459904498ce645769305fe2302e330c2076 Mon Sep 17 00:00:00 2001 From: pajri Date: Sat, 24 Dec 2022 15:10:13 +0700 Subject: [PATCH] form exclusion specialities done --- .../Api/CorporateServiceController.php | 16 + .../CorporateServiceConfigResource.php | 18 +- .../src/pages/Corporates/Services/Create.tsx | 587 ++++++++++-------- 3 files changed, 373 insertions(+), 248 deletions(-) diff --git a/Modules/Internal/Http/Controllers/Api/CorporateServiceController.php b/Modules/Internal/Http/Controllers/Api/CorporateServiceController.php index 9d4fe2b3..93472ef1 100755 --- a/Modules/Internal/Http/Controllers/Api/CorporateServiceController.php +++ b/Modules/Internal/Http/Controllers/Api/CorporateServiceController.php @@ -359,6 +359,22 @@ class CorporateServiceController extends Controller ]); } + if ($request->type == "plan") { + $value = $request->value; + foreach ($value as $key => $val) { + $item[] = $val['value']; + } + + $plan = implode(",", $item); + + $exclusion_rule = $exclusion->rules()->updateOrCreate([ + 'exclusion_id' => $exclusion->id, + 'name' => 'plan', + ], [ + 'name' => 'plan', + 'values' => $plan, + ]); + } $selected_specialities = CorporateServiceSpeciality::query() diff --git a/Modules/Internal/Transformers/CorporateServiceConfigResource.php b/Modules/Internal/Transformers/CorporateServiceConfigResource.php index 3c94db55..bbfc2100 100755 --- a/Modules/Internal/Transformers/CorporateServiceConfigResource.php +++ b/Modules/Internal/Transformers/CorporateServiceConfigResource.php @@ -65,10 +65,26 @@ class CorporateServiceConfigResource extends JsonResource return $speciality->exclusions->first()->rules->where('name', 'min_age')->first()->values ?? ''; }); - $data['exclusions'] = $data['exclusions']->map(function ($item, $key) use ($list_msc, $list_gender, $min_age) { + $max_age = $this->specialities->map(function ($speciality) { + return $speciality->exclusions->first()->rules->where('name', 'max_age')->first()->values ?? ''; + }); + + $plan = $this->specialities->map(function ($speciality) { + return $speciality->exclusions->first()->rules->where('name', 'plan')->first()->values ?? null; + }); + + $data['exclusions'] = $data['exclusions']->map(function ($item, $key) use ( + $list_msc, + $list_gender, + $min_age, + $max_age, + $plan, + ) { $item['msc'] = $list_msc[$key]; $item['gender'] = $list_gender[$key]; $item['min_age'] = $min_age[$key]; + $item['max_age'] = $max_age[$key]; + $item['plan'] = $plan[$key]; return $item; }); diff --git a/frontend/dashboard/src/pages/Corporates/Services/Create.tsx b/frontend/dashboard/src/pages/Corporates/Services/Create.tsx index e99dba6a..468a6d32 100755 --- a/frontend/dashboard/src/pages/Corporates/Services/Create.tsx +++ b/frontend/dashboard/src/pages/Corporates/Services/Create.tsx @@ -3,15 +3,21 @@ import { yupResolver } from '@hookform/resolvers/yup'; import { Autocomplete, Box, + Button, Card, Checkbox, Collapse, + Dialog, + DialogContent, + DialogTitle, Divider, FormControlLabel, FormGroup, Grid, + IconButton, Modal, Paper, + Popper, Stack, Table, TableBody, @@ -22,10 +28,24 @@ import { TextField, Typography, } from '@mui/material'; + +// components +import { + FormProvider, + RHFTextField, + RHFRadioGroup, + RHFUploadAvatar, + RHFSwitch, + RHFSelect, + RHFEditor, + RHFDatepicker, + RHFMultiCheckbox, + RHFCheckbox, + RHFCustomMultiCheckbox, +} from '../../../components/hook-form'; import { useForm } from 'react-hook-form'; import { useParams } from 'react-router-dom'; import HeaderBreadcrumbs from '../../../components/HeaderBreadcrumbs'; -import { FormProvider, RHFCheckbox, RHFSelect, RHFTextField } from '../../../components/hook-form'; import Page from '../../../components/Page'; import useSettings from '../../../hooks/useSettings'; import CorporateTabNavigations from '../CorporateTabNavigations'; @@ -34,6 +54,10 @@ import { ChangeEvent, useEffect, useMemo, useState } from 'react'; import axios from '../../../utils/axios'; import { CorporateService } from '../../../@types/corporates'; import { InfoIcon } from '../../../theme/overrides/CustomIcons'; +import { includes, set } from 'lodash'; +import { array } from 'yup/lib/locale'; +import CancelIcon from '@mui/icons-material/Cancel'; +import { enqueueSnackbar, useSnackbar } from 'notistack'; export default function Divisions() { const { themeStretch } = useSettings(); @@ -86,22 +110,8 @@ export default function Divisions() { }); }; - // const [configExclusions, setConfigExclusions] = useState([]); - - // console.log('Config Exclusions', configExclusions); - - // const handleConfigExclusion = (event: ChangeEvent, speciality: any) => { - - // setConfigExclusions({ - // ...configExclusions, - // [event.target.name]: event.target.checked, - // }); - // }; - const [exclusion, setExclusion] = useState([]); - console.log('Exclusions', exclusion); - const handleConfigExclusion = ( event: ChangeEvent, service: any, @@ -110,23 +120,33 @@ export default function Divisions() { type: string ) => { console.log(event.target.checked, service, speciality, value, type); - - axios - .post(`/corporates/${corporate_id}/services/${service_code}/specialities/exclusion`, { - // service_code: service.service_code, - speciality_id: speciality.id, - checked: event.target.checked ? '1' : '0', - value: value, - type: type, - }) - .then((res) => { - console.log('update', res.data); - setService({ - ...service, - selected_specialities: res.data?.selected_specialities, - exclusions: res.data?.service?.exclusions, + try { + axios + .post(`/corporates/${corporate_id}/services/${service_code}/specialities/exclusion`, { + // service_code: service.service_code, + speciality_id: speciality.id, + checked: event.target.checked ? '1' : '0', + value: value, + type: type, + }) + .then((res) => { + console.log('update', res.data); + setService({ + ...service, + selected_specialities: res.data?.selected_specialities, + exclusions: res.data?.service?.exclusions, + }); }); + + enqueueSnackbar('Exclusion Updated', { + variant: 'success', }); + } catch (error) { + console.log(error); + enqueueSnackbar('Exclusion Update Failed', { + variant: 'error', + }); + } }; const handleToggleSpeciality = ( @@ -135,25 +155,35 @@ export default function Divisions() { speciality: any ) => { console.log('Changing Service ', service, 'and', speciality); - axios - .post(`/corporates/${corporate_id}/services/${service_code}/specialities`, { - // service_code: service.service_code, - speciality_id: speciality.id, - active: event.target.checked ? '1' : '0', - }) - .then((res) => { - setService({ - ...service, - selected_specialities: res.data, - }); - // let newConfigurations = service.configurations - // newConfigurations[res.data.name] = res.data.value == true + try { + axios + .post(`/corporates/${corporate_id}/services/${service_code}/specialities`, { + // service_code: service.service_code, + speciality_id: speciality.id, + active: event.target.checked ? '1' : '0', + }) + .then((res) => { + setService({ + ...service, + selected_specialities: res.data, + }); + // let newConfigurations = service.configurations + // newConfigurations[res.data.name] = res.data.value == true - // setService({ - // ...service, - // configurations: { ...newConfigurations } - // }) + // setService({ + // ...service, + // configurations: { ...newConfigurations } + // }) + enqueueSnackbar('Speciality Updated', { + variant: 'success', + }); + }); + } catch (error) { + console.log(error); + enqueueSnackbar('Speciality Update Failed', { + variant: 'error', }); + } }; const specialityModalStyle = { @@ -161,8 +191,8 @@ export default function Divisions() { top: '50%', left: '50%', transform: 'translate(-50%, -50%)', - width: '80%', - maxHeight: '80%', + width: '90%', + maxHeight: '90%', overflowY: 'scroll', bgcolor: 'background.paper', border: '2px solid gray', @@ -194,6 +224,9 @@ export default function Divisions() { const [minAge, setMinAge] = useState(''); const [maxAge, setMaxAge] = useState(''); + const [valuePlan, setValuePlan] = useState([]); + + console.log('plan', valuePlan); const handleMinAge = (event: ChangeEvent) => { setMinAge(event.target.value); @@ -203,23 +236,27 @@ export default function Divisions() { setMaxAge(event.target.value); }; - const getMinAge = (service: any, speciality: any) => { - let minAge = ''; - if (service.exclusions) { - service.exclusions.map((exclusion: any) => { - if (exclusion.speciality_id == speciality.id) { - minAge = exclusion.min_age; - } - }); - } - - return minAge; + const handlePlanChange = (event: ChangeEvent, value: any) => { + setValuePlan(value); }; - console.log('minAge', minAge); - console.log('maxAge', maxAge); + // const [currentValuePlan, setCurrentValuePlan] = useState([]); + + const converToArray = (value: any) => { + console.log('value', value); + if (value == null) { + return null; + } + const array = value.split(',') ?? []; + const currentValuePlan = array.map((item: any) => ({ + value: item, + label: item, + })); + console.log('currentValuePlan', currentValuePlan); + + return currentValuePlan; + }; - console.log('Service _exclusions', service.exclusions); return ( - {/* */} + {/* */} @@ -423,213 +460,269 @@ export default function Divisions() { - { setSpecialityModal(false); }} + sx={{ + '& .MuiDialog-paper': { + width: '100%', + maxWidth: 1500, + maxHeight: 750, + bgcolor: 'background.paper', + boxShadow: 24, + }, + }} aria-labelledby="modal-modal-title" aria-describedby="modal-modal-description" > - - - Specialities - - - - - - Covered - - Nama Spesialisasi - MSC - Gender - Min Age - Max Age - Plan - - - - {specialities.map((row) => ( - - - { - handleToggleSpeciality(event, service, row); - }} - name="vitamins" - /> + + + + Specialities + + + + + + + +
+ + + Covered + Nama Spesialisasi + MSC + Gender + + Min Age - - {row.name} + + Max Age - - - {/* {listMsc.map((list) => ( + Plan + + + + {specialities.map((row) => ( + + + { + handleToggleSpeciality(event, service, row); + }} + /> + + + {row.name} + + + item.speciality_id == 2) - .includes(row.id)} + checked={service.exclusions.find( + (item) => + item.speciality_id == row.id && item.msc?.m == '1' + )} onChange={(event) => { - handleConfigExclusion(event, service, row, 'msc'); + handleConfigExclusion(event, service, row, 'm', 'msc'); }} /> } - label={list.name} + label="Member" /> - ))} */} + + item.speciality_id == row.id && item.msc?.s == '1' + )} + onChange={(event) => { + handleConfigExclusion(event, service, row, 's', 'msc'); + }} + /> + } + label="Spouse" + /> + + item.speciality_id == row.id && item.msc?.c == '1' + )} + onChange={(event) => { + handleConfigExclusion(event, service, row, 'c', 'msc'); + }} + /> + } + label="Child" + /> + + + + + + item.speciality_id == row.id && + item.gender?.male == '1' + )} + onChange={(event) => { + handleConfigExclusion( + event, + service, + row, + 'male', + 'gender' + ); + }} + /> + } + label="Male" + /> + + item.speciality_id == row.id && + item.gender?.female == '1' + )} + onChange={(event) => { + handleConfigExclusion( + event, + service, + row, + 'female', + 'gender' + ); + }} + /> + } + label="Female" + /> + + - - item.speciality_id == row.id && item.msc?.m == '1' - )} - onChange={(event) => { - handleConfigExclusion(event, service, row, 'm', 'msc'); - }} - /> + + item.speciality_id == row.id + )?.min_age } - label="Member" + onChange={(event) => { + handleMinAge(event); + }} + onKeyDown={(event) => { + if (event.key === 'Enter') { + handleConfigExclusion( + event, + service, + row, + minAge, + 'min_age' + ); + } + }} /> - - item.speciality_id == row.id && item.msc?.s == '1' - )} - onChange={(event) => { - handleConfigExclusion(event, service, row, 's', 'msc'); - }} - /> + + + item.speciality_id == row.id + )?.max_age } - label="Spouse" + onChange={(event) => { + handleMaxAge(event); + }} + onKeyDown={(event) => { + if (event.key === 'Enter') { + handleConfigExclusion( + event, + service, + row, + maxAge, + 'max_age' + ); + } + }} /> - - item.speciality_id == row.id && item.msc?.c == '1' - )} - onChange={(event) => { - handleConfigExclusion(event, service, row, 'c', 'msc'); - }} - /> + + + option.label} + defaultValue={ + converToArray( + service.exclusions.find( + (item) => item.speciality_id == row.id + )?.plan + ) || [] } - label="Child" + isOptionEqualToValue={(option, value) => + option.value === value.value + } + onChange={(event, value) => { + handlePlanChange(event, value); + }} + onKeyDown={(event) => { + if (event.key === 'Enter') { + handleConfigExclusion( + event, + service, + row, + valuePlan, + 'plan' + ); + } + }} + renderInput={(params) => ( + + )} /> - - - - - - item.speciality_id == row.id && item.gender?.male == '1' - )} - onChange={(event) => { - handleConfigExclusion( - event, - service, - row, - 'male', - 'gender' - ); - }} - /> - } - label="Male" - /> - - item.speciality_id == row.id && - item.gender?.female == '1' - )} - onChange={(event) => { - handleConfigExclusion( - event, - service, - row, - 'female', - 'gender' - ); - }} - /> - } - label="Female" - /> - - - - - item.speciality_id == row.id) - // ?.min_age - // } - - onChange={(event) => { - handleMinAge(event); - }} - onKeyDown={(event) => { - if (event.key === 'Enter') { - handleConfigExclusion(event, service, row, minAge, 'min_age'); - } - }} - /> - - - { - handleMaxAge(event); - }} - onKeyDown={(event) => { - if (event.key === 'Enter') { - handleConfigExclusion(event, service, row, maxAge, 'max_age'); - } - }} - /> - - - option.label} - style={{ width: 200 }} - renderInput={(params) => ( - - )} - /> - - - ))} - -
-
-
-
+ + + ))} + + + +
+ +