Files
tanami-admin-panel/src/Pages/FawateerChecker/ApproveRequest/RequestRejectModal.jsx

190 lines
4.8 KiB
React
Raw Normal View History

2024-10-10 15:47:15 +05:30
import {
Box,
Button,
FormControl,
2025-01-20 16:56:31 +05:30
FormHelperText,
2024-10-10 15:47:15 +05:30
FormLabel,
Input,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Text,
Textarea,
useDisclosure,
useToast,
} from "@chakra-ui/react";
import React, { useEffect, useState } from "react";
import * as yup from "yup";
import { yupResolver } from "@hookform/resolvers/yup";
import { useForm } from "react-hook-form";
import { useDepositRejectMutation } from "../../../Services/deposit.request.service";
import ToastBox from "../../../Components/ToastBox";
2024-10-11 13:33:27 +05:30
import { useRejectCommentMutation } from "../../../Services/fawateer.request.service";
2024-10-10 15:47:15 +05:30
2025-01-20 16:56:31 +05:30
// export const conformModalSchema = yup.object().shape({
// comments: yup.string().required("Comment is required")
// .max(200, "Approve Comment cannot be more than 200 characters"),
// });
2024-10-10 15:47:15 +05:30
export const conformModalSchema = yup.object().shape({
2025-01-20 16:56:31 +05:30
// checkerComment: yup.string().required("Comment is required")
// .max(50, "Investment name cannot be more than 50 characters"),
comments: yup
.string()
.required("Comment is required")
.max(200, "Approve Comment cannot be more than 200 characters"),
2024-10-10 15:47:15 +05:30
});
2024-10-10 16:16:28 +05:30
const RequestRejectModal = ({ isOpen, onClose, firstField ,id}) => {
2024-10-10 15:47:15 +05:30
const [isBtnLoading , setIsBtnLoading] = useState(false)
const toast = useToast()
const {
register,
reset,
2025-01-20 16:56:31 +05:30
watch,
2024-10-10 15:47:15 +05:30
handleSubmit,
formState: { errors },
} = useForm({
resolver: yupResolver(conformModalSchema),
});
2025-01-20 15:05:39 +05:30
useEffect(() => {
if (!isOpen) {
reset(); // Clear the form state
}
}, [isOpen, reset]);
2024-10-11 13:33:27 +05:30
const [ rejectFawateer ] = useRejectCommentMutation()
2024-10-10 15:47:15 +05:30
const onSubmit = async(data) => {
2024-10-11 13:33:27 +05:30
console.log(data, "tewxttttt");
2024-10-10 15:47:15 +05:30
setIsBtnLoading(true)
try {
2024-10-11 13:33:27 +05:30
const res = await rejectFawateer({data,id})
2024-10-10 15:47:15 +05:30
if (res?.error) {
toast({
render: () => (
2024-10-11 13:33:27 +05:30
<ToastBox status={"error"} message={res?.error?.data?.message} />
2024-10-10 15:47:15 +05:30
),
});
setIsBtnLoading(false)
2024-10-11 13:33:27 +05:30
}else if(res?.data){
2024-10-10 15:47:15 +05:30
toast({
render: () => (
<ToastBox message={res?.data?.message} />
),
});
2024-10-11 13:33:27 +05:30
onClose()
2024-10-10 15:47:15 +05:30
setIsBtnLoading(false)
2024-10-11 13:33:27 +05:30
}else{
toast({
render: () => (
<ToastBox status={'error'} message={"Something went wrong"} />
),
});
setIsBtnLoading(false)
}
2024-10-10 15:47:15 +05:30
} catch (error) {
}
};
const handleFileChange = (event) => {
const selectedFile = event.target.files[0];
setFile(selectedFile);
};
const { data, isLoading } =
(id, {
skip: !id,
});
useEffect(() => {
if (data) {
reset({
investorAmount: data?.data?.investorAmount,
});
}
}, [data, reset]);
const heandleOnClose = () =>{
reset()
onClose()
}
2025-01-20 16:56:31 +05:30
2024-10-10 15:47:15 +05:30
return (
<Modal isCentered isOpen={isOpen} onClose={heandleOnClose} initialFocusRef={firstField}>
<ModalOverlay />
<ModalContent pb={4}>
2024-10-11 13:33:27 +05:30
<ModalHeader fontSize={"md"}>Reject Comment</ModalHeader>
2024-10-10 15:47:15 +05:30
<ModalCloseButton />
{isLoading ? (
<FullscreenLoaders height={"50vh"} />
) : (
<Box as="form" onSubmit={handleSubmit(onSubmit)}>
<ModalBody>
<FormControl mb={4} isRequired>
<FormLabel fontSize="sm">Comment</FormLabel>
<Textarea
rows={6}
focusBorderColor="green.400"
name="comments"
{...register("comments")}
fontSize="sm"
type="textarea"
size="md"
placeholder={"Enter your comments...."}
rounded={"md"}
resize={"none"}
2025-01-20 16:56:31 +05:30
maxLength={200}
2024-10-10 15:47:15 +05:30
/>
{errors.comments && (
<Text fontSize="xs" color="red">
{errors.comments.message}
</Text>
)}
2025-01-20 16:56:31 +05:30
<FormHelperText fontSize="xs" color="gray.500">
Maximum length should be 200 characters. You have entered
<Text as={'span'} ml={2}>{watch("comments")?.length || 0} </Text>characters.
</FormHelperText>
2024-10-10 15:47:15 +05:30
</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"}
isLoading={isBtnLoading}
type="submit"
>
Send
</Button>
</ModalFooter>
</Box>
)}
</ModalContent>
</Modal>
);
};
2024-10-10 16:16:28 +05:30
export default RequestRejectModal;