Add InitiateReversalPopup component and integrate into DepositHistory
This commit is contained in:
118
src/Components/Popups/InitiateReversalPopups.jsx
Normal file
118
src/Components/Popups/InitiateReversalPopups.jsx
Normal file
@@ -0,0 +1,118 @@
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
FormControl,
|
||||
FormLabel,
|
||||
Modal,
|
||||
ModalBody,
|
||||
ModalCloseButton,
|
||||
ModalContent,
|
||||
ModalFooter,
|
||||
ModalHeader,
|
||||
ModalOverlay,
|
||||
Text,
|
||||
Textarea,
|
||||
} from "@chakra-ui/react";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import * as yup from "yup";
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
export const conformModalSchema = yup.object().shape({
|
||||
comments: yup
|
||||
.string()
|
||||
.min(2, "Minimum length should be 150 characters.")
|
||||
.max(150, "Maximum length should be 150 characters.")
|
||||
.matches(/^[^\d]+$/, "Sponsor Name cannot contain numbers")
|
||||
.required("Comment is required"),
|
||||
});
|
||||
|
||||
const InitiateReversalPopup = ({ isOpen, onClose, handelApproved }) => {
|
||||
const {
|
||||
watch,
|
||||
register,
|
||||
reset,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
resolver: yupResolver(conformModalSchema),
|
||||
mode: "all",
|
||||
});
|
||||
|
||||
return (
|
||||
<Modal isOpen={isOpen} onClose={onClose}>
|
||||
<ModalOverlay />
|
||||
<ModalContent pb={4}>
|
||||
<ModalHeader fontSize={"md"}>Reversal Reason</ModalHeader>
|
||||
<ModalCloseButton />
|
||||
<Box
|
||||
as="form"
|
||||
onSubmit={handleSubmit((data) => {
|
||||
handelApproved(data);
|
||||
reset();
|
||||
})}
|
||||
>
|
||||
<ModalBody>
|
||||
<FormControl mb={4} isRequired>
|
||||
<FormLabel fontSize="sm">Comment</FormLabel>
|
||||
<Textarea
|
||||
rows={6}
|
||||
focusBorderColor="green.400"
|
||||
name="fileName"
|
||||
{...register("comments")}
|
||||
fontSize="sm"
|
||||
type="textarea"
|
||||
size="md"
|
||||
placeholder={"Enter your comments...."}
|
||||
rounded={"md"}
|
||||
resize={"none"}
|
||||
mb={2}
|
||||
/>
|
||||
|
||||
{errors.comments ? (
|
||||
<Text fontSize="xs" color="red">
|
||||
{errors.comments.message}
|
||||
</Text>
|
||||
) : (
|
||||
<Text fontSize="xs" color="gray.500">
|
||||
Maximum length should be 150 characters. You have entered{" "}
|
||||
{watch()?.comments?.length || 0} characters.
|
||||
</Text>
|
||||
)}
|
||||
</FormControl>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button
|
||||
colorScheme="gray"
|
||||
mr={3}
|
||||
onClick={onClose}
|
||||
size={"sm"}
|
||||
rounded={"sm"}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
colorScheme="forestGreen"
|
||||
variant="solid"
|
||||
size={"sm"}
|
||||
rounded={"sm"}
|
||||
type={"submit"}
|
||||
>
|
||||
Send
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</Box>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
InitiateReversalPopup.propTypes = {
|
||||
isOpen: PropTypes.bool.isRequired,
|
||||
onClose: PropTypes.func.isRequired,
|
||||
handelApproved: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default InitiateReversalPopup;
|
||||
Reference in New Issue
Block a user