import { Box, Button, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, DrawerHeader, DrawerOverlay, FormControl, FormErrorMessage, FormHelperText, FormLabel, Input, Select, Stack, Textarea, useToast, } from "@chakra-ui/react"; import * as yup from "yup"; import React, { useState, useEffect, useContext } from "react"; import { useForm, Controller } from "react-hook-form"; import { yupResolver } from "@hookform/resolvers/yup"; import { v4 as uuidv4 } from "uuid"; import { useParams } from "react-router-dom"; import CustomAlertDialog from "../../../../Components/CustomAlertDialog"; import { useCreateIoCashMutation, useCreateVideoArtifactsMutation, useUpdateVideoArtifactsMutation } from "../../../../Services/io.service"; import ToastBox from "../../../../Components/ToastBox"; import GlobalStateContext from "../../../../Contexts/GlobalStateContext"; import CurrencyInput from "../../../../Components/CurrencyInput"; const cashDetails = yup.object().shape({ transactionDate: yup.string().required("Date is required"), ioTransType_xid: yup.number().required("Cash transaction is required"), transactionAmount: yup.number().required("Transaction Amount is required"), comments: yup.string().notRequired() .max(200, "Approve Comment cannot be more than 200 characters"), }); const AddCaseDetails = ({ isOpen, onClose, firstField, actionId, setActionId, data, setActiveTab }) => { const params = useParams() const id = params?.id const [file, setFile] = useState(""); const [fileName, setFileName] = useState(""); const [isLoading, setIsLoading] = useState(false) const [alert, setAlert] = useState(false); const toast = useToast(); console.log(isOpen); // ======================[ Cotext Api ] const { IODetails } = useContext(GlobalStateContext); const found = data?.find((item) => item?.id === actionId); const [createArtifactsVideo] = useCreateVideoArtifactsMutation() const [updateVideoArtifacts] = useUpdateVideoArtifactsMutation() // const { // data // } = useGetArtifactsQuery(id) const { control, handleSubmit, watch, reset, formState: { errors }, } = useForm({ resolver: yupResolver(cashDetails), }); const [createIoCash] = useCreateIoCashMutation() const onSubmit = async (data) => { setIsLoading(true) try { const res = await createIoCash({ data, id }) if (res?.data) { setIsLoading(false); toast({ render: () => , }); handleClose() setActiveTab(1) }else if(res?.error){ setIsLoading(false); toast({ render: () => , }); } } catch (error) { console.log(error); setIsLoading(false); } }; const handleConfirm = () => { handleSubmit(onSubmit)(); }; const handleSave = () => { handleSubmit(onSubmit)(); }; const handleClose = () => { setAlert(false) onClose() reset({ transactionAmount:"" }) } return ( <> IO Cash Details Date Selection ( )} /> {errors.transactionDate?.message} Cash transaction ( )} /> {errors.ioTransType_xid?.message} Transaction Amount ( )} /> {errors.transactionAmount?.message} Comment (