Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | import * as React from "react";
import { palette } from "@palette";
// form
import * as Yup from "yup";
import { yupResolver } from "@hookform/resolvers/yup";
import { VALIDATION_MESSAGES } from "@validation/messages";
import { useForm, FormProvider, SubmitHandler } from "react-hook-form";
// @mui
import Grid from "@mui/material/Grid";
import { useTheme } from "@mui/material/styles";
import useMediaQuery from "@mui/material/useMediaQuery";
// components
import { Text } from "@common/Text";
import { Modal } from "@common/Modal";
import { Button } from "@common/Button";
import { RHFInput } from "@common/Input";
import { RHFSelect } from "@common/Select";
import { showMessage } from "@common/Toast/ShowToast";
// assets
import { RefreshIcon } from "@assets/icons";
import NiceModal, { muiDialogV5, useModal } from "@ebay/nice-modal-react";
type IFormInputs = {
recurrence: string;
maxNumber: string;
};
const ProcessingMakeRecuring = NiceModal.create(() => {
const modal = useModal();
const theme = useTheme();
const isDesktop = useMediaQuery(theme.breakpoints.up("sm"));
const handleClose = () => {
modal.hide();
};
const schema = Yup.object({
recurrence: Yup.string().required(VALIDATION_MESSAGES.REQUIRED),
});
const defaultValues = {
maxNumber: "",
recurrence: "",
};
const methods = useForm<IFormInputs>({
resolver: yupResolver(schema),
defaultValues,
});
const { setValue, watch } = methods;
const onSubmit: SubmitHandler<IFormInputs> = (data) => {
if (isDesktop) {
showMessage("Success", "", true, "Payment updated");
} else {
showMessage(
"Success",
<span style={{ fontSize: 16, fontWeight: "600" }}>
Payment updated
</span>,
false,
);
}
handleClose();
};
const normalizeNumberOfPayments = (value: string) => {
if (!value) return value;
const currentValue = value.replace(/[^\d]/g, "");
return currentValue;
};
React.useEffect(() => {
setValue("maxNumber", normalizeNumberOfPayments(watch("maxNumber")));
}, [watch("maxNumber")]);
return (
<Modal
{...muiDialogV5(modal)}
title="Make Recurring"
onClose={handleClose}
titleIcon={<RefreshIcon />}
closeAfterTransition={true}
actions={
<>
<Button variant="text" onClick={handleClose}>
Cancel
</Button>
<Button
type="submit"
variant="primary"
form="make-recurring"
sx={{ color: palette.info.main }}
>
Confirm
</Button>
</>
}
>
<Text variant="h5" fontWeight="semibold" color={palette.neutral[800]}>
Antonio Silvestre, antonio@gmail.com, VISA 1111
</Text>
<Text fontSize={16} color={palette.neutral[600]} mt={1}>
Choose recurrence and number of payments
</Text>
<FormProvider {...methods}>
<Grid
mt={2}
mb={1}
container
spacing={2}
component="form"
id="make-recurring"
onSubmit={methods.handleSubmit(onSubmit)}
>
<Grid item xs={12} sm={6}>
<RHFSelect
name="recurrence"
placeholder="Select an option"
label="Recurrence"
options={[
{
value: "Weekly",
label: "Weekly",
},
{
value: "Monthly",
label: "Monthly",
},
{
value: "Quarterly",
label: "Quarterly",
},
{
value: "Yearly",
label: "Yearly",
},
]}
/>
</Grid>
<Grid item xs={12} sm={6}>
<RHFInput
name="maxNumber"
fullWidth
placeholder="Leave blank for unlimited payments"
label="Number of Payments"
/>
</Grid>
</Grid>
</FormProvider>
</Modal>
);
});
export default ProcessingMakeRecuring;
|