update
This commit is contained in:
@@ -13,14 +13,17 @@ import Checkbox from '@mui/material/Checkbox';
|
||||
import MuiDialog from '../../components/MuiDialog';
|
||||
import { FormProvider, RHFTextField } from '../../components/hook-form';
|
||||
// React
|
||||
import { ReactElement, useEffect, useState } from 'react';
|
||||
import { useContext, ReactElement, useEffect, useState } from 'react';
|
||||
import { fCurrency } from '../../utils/formatNumber';
|
||||
import { UserCurrentCorporateContext } from '../../contexts/UserCurrentCorporate';
|
||||
|
||||
// yup
|
||||
import * as Yup from 'yup';
|
||||
// form
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import axios from '../../utils/axios';
|
||||
import { enqueueSnackbar } from 'notistack';
|
||||
|
||||
/* ---------------------------------- types --------------------------------- */
|
||||
type MuiDialogProps = {
|
||||
@@ -76,6 +79,8 @@ export default function DialogTopUpLimit({
|
||||
const [isDisabledInput, setIsDisabledInput] = useState(false);
|
||||
const [isDisabledButton, setIsDisabledButton] = useState(true);
|
||||
const [isCheckboxChecked, setIsCheckboxChecked] = useState(false);
|
||||
const [ message, setMessage ] = useState ('');
|
||||
const { corporateValue } = useContext(UserCurrentCorporateContext);
|
||||
|
||||
const TopUpSchema = Yup.object().shape({
|
||||
topup: Yup.number().max(
|
||||
@@ -112,15 +117,32 @@ export default function DialogTopUpLimit({
|
||||
}, [openDialog, reset]);
|
||||
|
||||
const onSubmit = async (data: FormValuesProps) => {
|
||||
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
setIsDisabledInput(false);
|
||||
setIsDisabledButton(true);
|
||||
setIsCheckboxChecked(false);
|
||||
|
||||
// await axios.post('');
|
||||
|
||||
reset();
|
||||
try {
|
||||
// Send the HTTP POST request to the backend
|
||||
await axios.post(corporateValue + '/topup', {
|
||||
topup: data.topup,
|
||||
});
|
||||
|
||||
// Show a success notification
|
||||
enqueueSnackbar('The request has been sent', { variant: 'success' });
|
||||
setOpenDialog(false);
|
||||
|
||||
reset();
|
||||
} catch (error) {
|
||||
// Show an error notification
|
||||
enqueueSnackbar('An error occurred', { variant: 'error' });
|
||||
setOpenDialog(false);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
const onCheckHandler = (value: string) => {
|
||||
@@ -128,7 +150,7 @@ export default function DialogTopUpLimit({
|
||||
value === '0' || value === '' ? setIsDisabledButton(true) : setIsDisabledButton(false);
|
||||
setIsCheckboxChecked(!isCheckboxChecked);
|
||||
// @ts-ignore
|
||||
setValue('topup', data.maxTopUp);
|
||||
setValue('topup', data.maxTopUp.toString());
|
||||
};
|
||||
|
||||
const onTopupHandler = (value: string) => {
|
||||
|
||||
Reference in New Issue
Block a user