// @mui import { styled } from '@mui/material/styles'; import { Typography, LinearProgress, linearProgressClasses, Stack, FormControlLabel, } from '@mui/material'; import { LoadingButton } from '@mui/lab'; import Checkbox from '@mui/material/Checkbox'; // components import MuiDialog from '../../components/MuiDialog'; import { FormProvider, RHFTextField } from '../../components/hook-form'; // React import { ReactElement, useEffect, useState } from 'react'; import { fCurrency } from '../../utils/formatNumber'; // yup import * as Yup from 'yup'; // form import { useForm } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers/yup'; // ---------------------------------------------------------------------- type DataContent = { info: string; date: string; time: string; }; type MuiDialogProps = { title?: { name?: string; icon?: string; }; openDialog: boolean; setOpenDialog: Function; content?: ReactElement; data?: DataContent[]; }; type FormValuesProps = { topup: string; }; // ---------------------------------------------------------------------- const testData = { companyName: 'PT. Aman Mineral', policyNumber: 12345678, totalMembers: 50, totalCases: 100, totalPersen: 75, myLimit: 375000000, totalLimit: 500000000, }; const BorderLinearProgress = styled(LinearProgress)(({ theme }) => ({ height: 10, borderRadius: 6, [`&.${linearProgressClasses.colorPrimary}`]: { backgroundColor: theme.palette.grey[theme.palette.mode === 'light' ? 300 : 800], }, [`& .${linearProgressClasses.bar}`]: { borderRadius: 6, background: 'linear-gradient(270deg, #19BBBB 38.42%, #FF9565 76.21%, #FE7253 104.02%)', }, })); // ---------------------------------------------------------------------- const DialogTopUpLimit = ({ title, openDialog, setOpenDialog, data }: MuiDialogProps) => { const [isDisabledCheckbox, setIsDisabledCheckbox] = useState(false); const [isDisabledButton, setIsDisabledButton] = useState(true); const TopUpSchema = Yup.object().shape({ topup: Yup.number(), // /* // // @ts-ignore */ // .test('limit', 'Maximum Top Up Rp. 5.000.000', (val) => (val > 5000000 ? false : true)), }); const defaultValues = { topup: 0, }; const methods = useForm({ resolver: yupResolver(TopUpSchema), defaultValues, }); const { setValue, reset, handleSubmit, formState: { isSubmitting }, } = methods; useEffect(() => { if (openDialog === false) { reset(); } }, [openDialog, reset]); const onSubmit = async (data: FormValuesProps) => { reset(); }; const onCheckHandler = (data: FormValuesProps) => { setIsDisabledCheckbox(!isDisabledCheckbox); setIsDisabledButton(false); setValue('topup', testData.totalLimit - testData.myLimit); }; const onTopupHandler = (value: string) => { value === '0' || value === '' ? setIsDisabledButton(true) : setIsDisabledButton(false); setValue('topup', value); }; const getContent = () => ( Company Name {testData.companyName} Policy Number {testData.policyNumber} Total Member {testData.totalMembers} Person Total Cases {testData.totalCases} Cases Company Pooled Fund {fCurrency(testData.myLimit)} / {testData.totalLimit} {testData.totalPersen}% Top Up Limit onTopupHandler(e.target.value)} /> } label={'Max ' + fCurrency(testData.totalLimit - testData.myLimit)} onChange={handleSubmit(onCheckHandler)} /> Ajukan Permintaan ); return ( ); }; export default DialogTopUpLimit;