diff --git a/src/Pages/Fawateer/CreateRequest.jsx b/src/Pages/Fawateer/CreateRequest.jsx index 3bd9e39..0529ef9 100644 --- a/src/Pages/Fawateer/CreateRequest.jsx +++ b/src/Pages/Fawateer/CreateRequest.jsx @@ -1,17 +1,27 @@ import React, { useState } from "react"; import { OPACITY_ON_LOAD } from "../../Layout/animations"; -import { Box, Button, HStack, Input, InputGroup, InputRightAddon, Textarea, useDisclosure, Image, Icon, VStack, Text, useToast } from "@chakra-ui/react"; import { - FormControl, - FormLabel, - FormHelperText, + Box, + Button, + HStack, + Input, + InputGroup, + InputRightAddon, + Textarea, + useDisclosure, + Image, + Icon, + VStack, + Text, + useToast, } from "@chakra-ui/react"; +import { FormControl, FormLabel, FormHelperText } from "@chakra-ui/react"; import { DeleteIcon, Search2Icon } from "@chakra-ui/icons"; import SelectInvestorModal from "./SelectInvestorModal"; import { Controller, useForm } from "react-hook-form"; // Import useForm import { yupResolver } from "@hookform/resolvers/yup"; // Import resolver for Yup import * as Yup from "yup"; // Import Yup for validation -import { motion } from 'framer-motion'; // Import Framer Motion for animations +import { motion } from "framer-motion"; // Import Framer Motion for animations import { bytesToMB } from "../../Constants/Constants"; import { useCreateFawateerRequestMutation } from "../../Services/fawateer.maker.service"; import ToastBox from "../../Components/ToastBox"; @@ -23,60 +33,66 @@ const validationSchema = Yup.object().shape({ investorName: Yup.string().required("Investor name is required"), clientId: Yup.string().required("Client ID is required"), transaction_date: Yup.date() - .required('Date is required') - .transform((value, originalValue) => { - return originalValue === "" ? null : value; // Convert empty strings to null - }) - .typeError('Please enter a valid date').max(new Date(), "Date cannot be in the future"), + .required("Date is required") + .transform((value, originalValue) => { + return originalValue === "" ? null : value; // Convert empty strings to null + }) + .typeError("Please enter a valid date") + .max(new Date(), "Date cannot be in the future"), transaction_amount: Yup.number() - .required("Transaction amount is required") - .transform((value, originalValue) => originalValue === "" ? null : value) // Convert empty strings to null - .typeError('Transaction amount must be a number') // Custom error message if it's not a number - .positive('Transaction amount must be greater than zero'), + .required("Transaction amount is required") + .transform((value, originalValue) => (originalValue === "" ? null : value)) // Convert empty strings to null + .typeError("Transaction amount must be a number") // Custom error message if it's not a number + .positive("Transaction amount must be greater than zero"), spportFile_path: Yup.mixed().required("Support file is required"), makerComment: Yup.string(), }); const CreateRequest = () => { - const toast = useToast() - const navigate=useNavigate() + const toast = useToast(); + const navigate = useNavigate(); const { isOpen, onOpen, onClose } = useDisclosure(); const [selectedInvestor, setSelectorInvestor] = useState({}); const [filePreview, setFilePreview] = useState(null); // State for previewing the file const [fileType, setFileType] = useState(null); // State to store file type for conditional rendering - const[ isLoading, setIsLoading ] = useState(false) - const [id, setId ] = useState(null) + const [isLoading, setIsLoading] = useState(false); + const [id, setId] = useState(null); // Initialize useForm with the resolver for Yup validation - const {control, register, handleSubmit, setValue,reset, formState: { errors } } = useForm({ + const { + control, + register, + handleSubmit, + setValue, + reset, + formState: { errors }, + } = useForm({ resolver: yupResolver(validationSchema), }); - - const [ creatFawaateerRequest ] = useCreateFawateerRequestMutation() - + const [creatFawaateerRequest] = useCreateFawateerRequestMutation(); const onSubmit = async (data) => { console.log(data); - setIsLoading(true) - + setIsLoading(true); + // Convert data to FormData const formData = new FormData(); - - // Append each field from the data object to the FormData - Object.keys(data).forEach((key) => { - if (key === "spportFile_path" && data[key] instanceof FileList) { - // Append the first file from FileList (assuming single file input) - formData.append(key, data[key][0]); // Append the file - } else { - formData.append(key, data[key]); // Append other fields - } - }); - + + // Append each field from the data object to the FormData + Object.keys(data).forEach((key) => { + if (key === "spportFile_path" && data[key] instanceof FileList) { + // Append the first file from FileList (assuming single file input) + formData.append(key, data[key][0]); // Append the file + } else { + formData.append(key, data[key]); // Append other fields + } + }); + try { // Make the API call with formData const res = await creatFawaateerRequest({ data: formData, id }); - + if (res?.error) { toast({ render: () => ( @@ -84,39 +100,35 @@ const CreateRequest = () => { ), }); setIsLoading(false); - reset() - return + reset(); + return; } else if (res?.data) { toast({ - render: () => ( - - ), + render: () => , }); setIsLoading(false); - navigate('/fawateer-history') - return + navigate("/fawateer-history"); + return; } else { toast({ render: () => ( - + ), }); setIsLoading(false); - return + return; } - } catch (error) { console.error("Error:", error); toast({ render: () => ( - + ), }); setIsLoading(false); - return + return; } }; - // Handle file change and preview const handleFileChange = (e) => { @@ -137,15 +149,12 @@ const CreateRequest = () => { } }; - - - return ( { onSubmit={handleSubmit(onSubmit)} > {/* Investor Name Field */} - + Investor name - + { {...register("investorName")} _placeholder={{ fontSize: "sm" }} /> - + Search - {errors.investorName?.message} + + {errors.investorName?.message} + {/* Client ID Field */} @@ -193,7 +220,13 @@ const CreateRequest = () => { placeholder={"Client ID"} {...register("clientId")} /> - {errors.clientId?.message} + + {errors.clientId?.message} + {/* Date Field */} @@ -208,10 +241,21 @@ const CreateRequest = () => { fontSize={"sm"} rounded={"sm"} type={"date"} - max={new Date().toISOString().split("T")[0]} // Disable future dates - {...register("transaction_date")} + max={new Date().toLocaleDateString("en-CA")} // Ensures max is in local timezone + {...register("transaction_date", { + setValueAs: (value) => { + // Convert date string to local timezone Date object + return value ? new Date(value) : undefined; + }, + })} /> - {errors.transaction_date?.message} + + {errors.transaction_date?.message} + {/* Amount Field */} @@ -220,19 +264,35 @@ const CreateRequest = () => { Amount (BHD) ( - - )} - /> - + name="transaction_amount" + control={control} + render={({ field }) => ( + + )} + /> + {errors.transaction_amount?.message} - + {/* Support File Field with Preview */} - + Support file @@ -249,7 +309,13 @@ const CreateRequest = () => { {...register("spportFile_path")} // onChange={handleFileChange} /> - {errors.spportFile_path?.message} + + {errors.spportFile_path?.message} + {/* Animated Preview */} {filePreview && fileType?.type.startsWith("image/") && ( @@ -259,14 +325,55 @@ const CreateRequest = () => { transition={{ duration: 0.5 }} style={{ marginTop: "10px" }} > - - File preview - setFilePreview(null)} className="link" rounded={'md'} color={'red.700'} cursor={'pointer'} p={1.5} position={'absolute'} top={0} right={0} as={DeleteIcon} boxSize={7} /> - - File Name: {fileType?.name} - File Size: {bytesToMB(fileType?.size)} Mb - File Type: {fileType?.type} - + + File preview + setFilePreview(null)} + className="link" + rounded={"md"} + color={"red.700"} + cursor={"pointer"} + p={1.5} + position={"absolute"} + top={0} + right={0} + as={DeleteIcon} + boxSize={7} + /> + + + File Name:{" "} + + {" "} + {fileType?.name} + + + + File Size:{" "} + + {" "} + {bytesToMB(fileType?.size)} Mb + + + + File Type:{" "} + + {" "} + {fileType?.type} + + @@ -274,7 +381,7 @@ const CreateRequest = () => { {/* Description Field */} - + Description @@ -287,12 +394,18 @@ const CreateRequest = () => { placeholder={"Description"} {...register("makerComment")} /> - {errors.makerComment?.message} + + {errors.makerComment?.message} + {/* Submit Button */} - - */} - {IODetails?.isInvestedAmount ? ( - localStorage?.getItem('role') ==="Maker"&& - ) : null} + ) : null} */} diff --git a/src/Pages/IO_Management/CreateIO/IOCashDetails/IOCashDetails.jsx b/src/Pages/IO_Management/CreateIO/IOCashDetails/IOCashDetails.jsx index 4c9e6c7..3055a43 100644 --- a/src/Pages/IO_Management/CreateIO/IOCashDetails/IOCashDetails.jsx +++ b/src/Pages/IO_Management/CreateIO/IOCashDetails/IOCashDetails.jsx @@ -1,41 +1,111 @@ -import { Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react"; -import React from "react"; +import { + Box, + Button, + Tab, + TabList, + TabPanel, + TabPanels, + Tabs, + useDisclosure, + useToast, +} from "@chakra-ui/react"; +import React, { useContext, useRef } from "react"; import Approved from "./Approved"; import Pending from "./Pending"; import Rejected from "./Rejected"; +import { AddIcon } from "@chakra-ui/icons"; +import GlobalStateContext from "../../../../Contexts/GlobalStateContext"; +import AddCaseDetails from "./AddCaseDetails"; +import { useUpdateIOCaseMutation } from "../../../../Services/io.service"; +import ToastBox from "../../../../Components/ToastBox"; +import { useParams } from "react-router-dom"; const IOCashDetails = () => { + const params = useParams(); + const toast = useToast(); + const id = params?.id; + const { IODetails} = useContext(GlobalStateContext); + const { isOpen, onOpen, onClose } = useDisclosure(); + const firstField = useRef(); + + const [updateIOCase] = useUpdateIOCaseMutation(); + + const handleAdd = async () => { + + + try { + const res = await updateIOCase(id); + if (res?.data) { + // toast({ + // render: () => ( + // + // ), + // }); + // setIsLoading(false); + onOpen(); + } else if (res?.error) { + toast({ + render: () => ( + + ), + }); + setIsLoading(false); + } + } catch (error) {} + }; + return ( - - - + + + + + Approved + + + Pending + + + Rejected + + + {IODetails?.isInvestedAmount ? ( + localStorage?.getItem('role') ==="Maker" && + + ) : null} + @@ -48,6 +118,12 @@ const IOCashDetails = () => { + + ); }; diff --git a/src/Pages/IO_Management/CreateIO/IOCashDetails/Pending.jsx b/src/Pages/IO_Management/CreateIO/IOCashDetails/Pending.jsx index fd89eea..fa7e9db 100644 --- a/src/Pages/IO_Management/CreateIO/IOCashDetails/Pending.jsx +++ b/src/Pages/IO_Management/CreateIO/IOCashDetails/Pending.jsx @@ -102,9 +102,10 @@ const Pending = () => { "Transaction Type", "Amount", "Comments", - // "Update by", + "Update by", "Update On", - ...(localStorage?.getItem('role')!=="Maker" ? ["Status"] : []), + ...(localStorage?.getItem('role')!=="Maker" ? ["Actions"] : []), + ]; const extractedArray = filteredData?.map((item, index) => ({ @@ -129,7 +130,10 @@ const Pending = () => { $ - {item?.transactionAmount} + {parseFloat(item?.transactionAmount || 0).toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} ), Comments: ( @@ -146,13 +150,13 @@ const Pending = () => { display={"flex"} alignItems={"center"} > - - {item?.creator?.firstName} + /> */} + {item?.modifier?.firstName} ), "Update On": ( @@ -160,8 +164,10 @@ const Pending = () => { {formatDate(item.updatedAt)} ), - Status: ( - + Actions: ( + + {localStorage?.getItem("role") !== "Maker" ? + {index===0&& { > - + } + + : } ), })); @@ -289,7 +309,13 @@ const Pending = () => { wordBreak="normal" overflowWrap="normal" > - {"48,000.00"} + + $ + + {parseFloat(IODetails?.ioCash || 0).toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} { try { const res = await updateIOCase(id); if (res?.data) { - toast({ - render: () => ( - - ), - }); + // toast({ + // render: () => ( + // + // ), + // }); setIsLoading(false); onOpen(); } else if (res?.error) { @@ -377,7 +403,7 @@ const Pending = () => { onChange={(e) => setSearchTerm(e.target.value)} /> - + {/* {IODetails?.isInvestedAmount ? ( localStorage?.getItem('role') ==="Maker"&& ) : null} - + */} @@ -401,7 +427,7 @@ const Pending = () => { isLoading={isLoading} viewActionId={actionId} setViewActionId={setActionId} - total={} + // total={} setMouseEnteredId={setMouseEnteredId} setMouseEntered={setMouseEntered} /> diff --git a/src/Pages/IO_Management/CreateIO/IOCashDetails/Rejected.jsx b/src/Pages/IO_Management/CreateIO/IOCashDetails/Rejected.jsx index 88c7ec1..470fdc8 100644 --- a/src/Pages/IO_Management/CreateIO/IOCashDetails/Rejected.jsx +++ b/src/Pages/IO_Management/CreateIO/IOCashDetails/Rejected.jsx @@ -81,7 +81,7 @@ import AddCaseDetails from "./AddCaseDetails"; "Transaction Type", "Amount", "Comments", - // "Update by", + "Update by", "Update On", ]; @@ -117,9 +117,12 @@ import AddCaseDetails from "./AddCaseDetails"; fontWeight={"500"} > - $ - - {item?.transactionAmount} + $ + + {parseFloat(IODetails?.ioCash || 0).toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} ), "Comments": ( @@ -141,13 +144,13 @@ import AddCaseDetails from "./AddCaseDetails"; display={"flex"} alignItems={"center"} > - - {item?.creator?.firstName} + /> */} + {item?.modifier?.firstName} ), "Update On": ( @@ -264,11 +267,11 @@ import AddCaseDetails from "./AddCaseDetails"; try { const res = await updateIOCase(id) if (res?.data) { - toast({ - render: () => ( - - ), - }); + // toast({ + // render: () => ( + // + // ), + // }); setIsLoading(false); onOpen() @@ -304,7 +307,7 @@ import AddCaseDetails from "./AddCaseDetails"; onChange={(e) => setSearchTerm(e.target.value)} /> - + {/* {IODetails?.isInvestedAmount ? ( localStorage?.getItem('role') ==="Maker"&& - {IODetails?.isInvestedAmount ? ( - localStorage?.getItem('role') ==="Maker"&& - ) : null} + {/* {IODetails?.isInvestedAmount + ? localStorage?.getItem("role") === "Maker" && ( + + ) + : null} */} - - - - - - setDeleteAlert(false)} - isOpen={deleteAlert} - message={"Are you sure you want to delete sponers?"} - alertHandler={handleDelete} - isLoading={isLoading} - /> + + + + + + setDeleteAlert(false)} + isOpen={deleteAlert} + message={"Are you sure you want to delete sponers?"} + alertHandler={handleDelete} + isLoading={isLoading} + /> - - ); - }; - - export default Approved; - \ No newline at end of file + + ); +}; + +export default Approved; diff --git a/src/Pages/IO_Management/CreateIO/IONAVDetails/IONAVDetails.jsx b/src/Pages/IO_Management/CreateIO/IONAVDetails/IONAVDetails.jsx index bad63f8..03cf067 100644 --- a/src/Pages/IO_Management/CreateIO/IONAVDetails/IONAVDetails.jsx +++ b/src/Pages/IO_Management/CreateIO/IONAVDetails/IONAVDetails.jsx @@ -1,53 +1,183 @@ -import { Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react"; -import React from "react"; +// import { Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react"; +// import React from "react"; +// import Approved from "./Approved"; +// import Pending from "./Pending"; +// import Rejected from "./Rejected"; + +// const IONAVDetails = () => { +// return ( +// +// +// +// Approved +// +// +// Pending +// +// +// Rejected +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// ); +// }; + +// export default IONAVDetails; + +import { + Box, + Button, + Tab, + TabList, + TabPanel, + TabPanels, + Tabs, + useDisclosure, + useToast, +} from "@chakra-ui/react"; +import React, { useContext, useRef } from "react"; import Approved from "./Approved"; import Pending from "./Pending"; import Rejected from "./Rejected"; +import { AddIcon } from "@chakra-ui/icons"; +import GlobalStateContext from "../../../../Contexts/GlobalStateContext"; +import ToastBox from "../../../../Components/ToastBox"; +import { useParams } from "react-router-dom"; +import AddNavDetails from "./AddNavDetails"; +import { useUpdateIOCaseMutation } from "../../../../Services/io.service"; const IONAVDetails = () => { + const params = useParams(); + const toast = useToast(); + const id = params?.id; + const { IODetails } = useContext(GlobalStateContext); + const { isOpen, onOpen, onClose } = useDisclosure(); + const firstField = useRef(); + + const [updateIOCase] = useUpdateIOCaseMutation(); + + const handleAdd = async () => { + try { + const res = await updateIOCase(id); + if (res?.data) { + // toast({ + // render: () => ( + // + // ), + // }); + // setIsLoading(false); + onOpen(); + } else if (res?.error) { + toast({ + render: () => ( + + ), + }); + setIsLoading(false); + } + } catch (error) {} + }; + return ( - - - + + - Approved - - - Pending - - - Rejected - - - - - - - - - - - - - - + + + Approved + + + Pending + + + Rejected + + + {IODetails?.isInvestedAmount + ? localStorage?.getItem("role") === "Maker" && ( + + ) + : null} + + + + + + + + + + + + + + + ); }; diff --git a/src/Pages/IO_Management/CreateIO/IONAVDetails/Pending.jsx b/src/Pages/IO_Management/CreateIO/IONAVDetails/Pending.jsx index c4bfe4d..928532a 100644 --- a/src/Pages/IO_Management/CreateIO/IONAVDetails/Pending.jsx +++ b/src/Pages/IO_Management/CreateIO/IONAVDetails/Pending.jsx @@ -15,7 +15,7 @@ import { OPACITY_ON_LOAD } from "../../../../Layout/animations"; import NormalTable from "../../../../Components/DataTable/NormalTable"; import GlobalStateContext from "../../../../Contexts/GlobalStateContext"; import CustomAlertDialog from "../../../../Components/CustomAlertDialog"; -import { AddIcon, CheckIcon, CloseIcon } from "@chakra-ui/icons"; +import { AddIcon, CheckIcon, CloseIcon, ViewIcon } from "@chakra-ui/icons"; import { useParams } from "react-router-dom"; import { useUpdateIOCaseMutation } from "../../../../Services/io.service"; import ToastBox from "../../../../Components/ToastBox"; @@ -53,7 +53,6 @@ const Pending = () => { onClose: onRejectClose, } = useDisclosure(); - useEffect(() => { // Simulate loading const timer = setTimeout(() => { @@ -90,8 +89,8 @@ const Pending = () => { "Last Nav Update", "Investment Closed", "Comments", - // "Updated By", - ...(localStorage?.getItem('role')!=="Maker" ? ["Status"] : []), + "Updated By", + ...(localStorage?.getItem("role") !== "Maker" ? ["Status"] : []), ]; const extractedArray = filteredData?.map((item, index) => ({ @@ -111,7 +110,10 @@ const Pending = () => { $ - {item?.transactionAmount} + {parseFloat(item?.transactionAmount || 0).toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} ), "Last Nav Update": ( @@ -150,17 +152,19 @@ const Pending = () => { display={"flex"} alignItems={"center"} > - - {item?.creator?.firstName} + /> */} + {item?.modifier?.firstName} ), Status: ( - + + + { + + ), })); @@ -236,11 +242,11 @@ const Pending = () => { try { const res = await updateIOCase(id); if (res?.data) { - toast({ - render: () => ( - - ), - }); + // toast({ + // render: () => ( + // + // ), + // }); setIsLoading(false); onOpen(); } else if (res?.error) { @@ -273,18 +279,20 @@ const Pending = () => { value={searchTerm} onChange={(e) => setSearchTerm(e.target.value)} /> - {IODetails?.isInvestedAmount ? ( - localStorage?.getItem('role') ==="Maker"&& - ) : null} + {/* {IODetails?.isInvestedAmount + ? localStorage?.getItem("role") === "Maker" && ( + + ) + : null} */} diff --git a/src/Pages/IO_Management/CreateIO/IONAVDetails/Rejected.jsx b/src/Pages/IO_Management/CreateIO/IONAVDetails/Rejected.jsx index 351e5dc..2603e3f 100644 --- a/src/Pages/IO_Management/CreateIO/IONAVDetails/Rejected.jsx +++ b/src/Pages/IO_Management/CreateIO/IONAVDetails/Rejected.jsx @@ -1,134 +1,124 @@ import { - Avatar, - Badge, - Box, - Button, - HStack, - Input, - Table, - Tag, - Tbody, - Text, - Th, - Tooltip, - Tr, - useDisclosure, - useToast, - } from "@chakra-ui/react"; - import React, { useContext, useEffect, useRef, useState } from "react"; - import { AddIcon, DeleteIcon, EditIcon, ViewIcon } from "@chakra-ui/icons"; - import { LuFileSpreadsheet } from "react-icons/lu"; - import { OPACITY_ON_LOAD } from "../../../../Layout/animations"; - import NormalTable from "../../../../Components/DataTable/NormalTable"; - import GlobalStateContext from "../../../../Contexts/GlobalStateContext"; - import CustomAlertDialog from "../../../../Components/CustomAlertDialog"; - import ToastBox from "../../../../Components/ToastBox"; - import AddCashDetails from "../AddCashDetails"; - import { debounce } from "../../../Admin/Contact"; + Avatar, + Badge, + Box, + Button, + HStack, + Input, + Table, + Tag, + Tbody, + Text, + Th, + Tooltip, + Tr, + useDisclosure, + useToast, +} from "@chakra-ui/react"; +import React, { useContext, useEffect, useRef, useState } from "react"; +import { AddIcon, DeleteIcon, EditIcon, ViewIcon } from "@chakra-ui/icons"; +import { LuFileSpreadsheet } from "react-icons/lu"; +import { OPACITY_ON_LOAD } from "../../../../Layout/animations"; +import NormalTable from "../../../../Components/DataTable/NormalTable"; +import GlobalStateContext from "../../../../Contexts/GlobalStateContext"; +import CustomAlertDialog from "../../../../Components/CustomAlertDialog"; +import ToastBox from "../../../../Components/ToastBox"; +import AddCashDetails from "../AddCashDetails"; +import { debounce } from "../../../Admin/Contact"; import { useUpdateIOCaseMutation } from "../../../../Services/io.service"; import { useParams } from "react-router-dom"; import AddNavDetails from "./AddNavDetails"; - - const formatDate = (date) => new Date(date).toLocaleDateString(); - - const Rejected = () => { - const params = useParams() - const toast = useToast(); - const id = params?.id - const firstField = useRef(); - const { isOpen, onOpen, onClose } = useDisclosure(); - const { IODetails, iONAVDetail, setIONAVDetail } = - useContext(GlobalStateContext); - const [searchTerm, setSearchTerm] = useState(""); - const [isLoading, setIsLoading] = useState(true); - const [deleteAlert, setDeleteAlert] = useState(false); - const [actionId, setActionId] = useState(false); - const [mouseEntered, setMouseEntered] = useState(false); - const [mouseEnteredId, setMouseEnteredId] = useState(""); - const [updateIOCase] = useUpdateIOCaseMutation() - - useEffect(() => { - // Simulate loading - const timer = setTimeout(() => { - setIsLoading(false); - }, 1500); - - // Cleanup the timer on component unmount - return () => clearTimeout(timer); - }, []); - - const formatDate = (date) => { - return new Date(date).toLocaleDateString("en-GB", { - day: "2-digit", - month: "2-digit", - year: "numeric", - }); - }; - - - // Table filter - const filteredData = IODetails?.ioNAVStatusHistory?.Reject?.filter((item) => { - // Filter by name (case insensitive) - const name = item.transactionAmount; - const searchLower = searchTerm.toLowerCase(); - const nameMatches = name.toLowerCase().includes(searchLower); - return nameMatches; + +const formatDate = (date) => new Date(date).toLocaleDateString(); + +const Rejected = () => { + const params = useParams(); + const toast = useToast(); + const id = params?.id; + const firstField = useRef(); + const { isOpen, onOpen, onClose } = useDisclosure(); + const { IODetails, iONAVDetail, setIONAVDetail } = + useContext(GlobalStateContext); + const [searchTerm, setSearchTerm] = useState(""); + const [isLoading, setIsLoading] = useState(true); + const [deleteAlert, setDeleteAlert] = useState(false); + const [actionId, setActionId] = useState(false); + const [mouseEntered, setMouseEntered] = useState(false); + const [mouseEnteredId, setMouseEnteredId] = useState(""); + const [updateIOCase] = useUpdateIOCaseMutation(); + + useEffect(() => { + // Simulate loading + const timer = setTimeout(() => { + setIsLoading(false); + }, 1500); + + // Cleanup the timer on component unmount + return () => clearTimeout(timer); + }, []); + + const formatDate = (date) => { + return new Date(date).toLocaleDateString("en-GB", { + day: "2-digit", + month: "2-digit", + year: "numeric", }); - - const tableHeadRow = [ - "Sr No.", - "Valuation date", - "NAV", - "Last Nav Update", - "Investment Closed", - "Comments", - // "Updated By", - ]; - - const extractedArray = filteredData?.map((item, index) => ({ - id: item?.id, - "Sr No.": ( - - {index + 1}. - - ), - "Valuation date": ( - - {formatDate(item?.transactionDate)} - - ), - "NAV": ( - - - $ - - {item?.transactionAmount} - - ), - "Last Nav Update": ( - - {item.previousNAVvalue && `${item.previousNAVvalue}`} - - ), - "Investment Closed": ( + }; + + // Table filter + const filteredData = IODetails?.ioNAVStatusHistory?.Reject?.filter((item) => { + // Filter by name (case insensitive) + const name = item.transactionAmount; + const searchLower = searchTerm.toLowerCase(); + const nameMatches = name.toLowerCase().includes(searchLower); + return nameMatches; + }); + + const tableHeadRow = [ + "Sr No.", + "Valuation date", + "NAV", + "Last Nav Update", + "Investment Closed", + "Comments", + "Updated By", + ]; + + const extractedArray = filteredData?.map((item, index) => ({ + id: item?.id, + "Sr No.": ( + + {index + 1}. + + ), + "Valuation date": ( + + {formatDate(item?.transactionDate)} + + ), + NAV: ( + + + $ + + {parseFloat(item?.transactionAmount || 0).toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} + + ), + "Last Nav Update": ( + + {item.previousNAVvalue && `${item.previousNAVvalue}`} + + ), + "Investment Closed": ( ), - "Comments": ( - - {item?.comments ? item?.comments : "---" } - - ), - "Updated By": ( - + {item?.comments ? item?.comments : "---"} + + ), + "Updated By": ( + - + {/* - {item?.creator?.firstName} - - ), - })); - - const handleDelete = () => { - const updatedSponsors = sponser.filter( - (sponsor) => sponsor.id !== actionId - ); - - setTimeout(() => { - setCaseDetails(updatedSponsors); - setDeleteAlert(false); + /> */} + {item?.modifier?.firstName} + + ), + })); + + const handleDelete = () => { + const updatedSponsors = sponser.filter( + (sponsor) => sponsor.id !== actionId + ); + + setTimeout(() => { + setCaseDetails(updatedSponsors); + setDeleteAlert(false); + setIsLoading(false); + }, 100); + setIsLoading(true); + }; + + const handleAdd = async () => { + try { + const res = await updateIOCase(id); + if (res?.data) { + // toast({ + // render: () => ( + // + // ), + // }); + setIsLoading(false); + onOpen(); + } else if (res?.error) { + toast({ + render: () => ( + + ), + }); setIsLoading(false); - }, 100); - setIsLoading(true); - }; - - const handleAdd = async () =>{ - try { - const res = await updateIOCase(id) - if (res?.data) { - toast({ - render: () => ( - - ), - }); - setIsLoading(false); - onOpen() - - } else if (res?.error) { - toast({ - render: () => ( - - ), - }); - setIsLoading(false); - } - } catch (error) { - } - } + } catch (error) {} + }; - return ( - - - - setSearchTerm(e.target.value)} - /> + return ( + + + + setSearchTerm(e.target.value)} + /> -{IODetails?.isInvestedAmount ? ( - localStorage?.getItem('role') ==="Maker"&& - ) : null} - - - - - - setDeleteAlert(false)} - isOpen={deleteAlert} - message={"Are you sure you want to delete sponers?"} - alertHandler={handleDelete} - isLoading={isLoading} - /> + {/* {IODetails?.isInvestedAmount + ? localStorage?.getItem("role") === "Maker" && ( + + ) + : null} */} + + + + + + setDeleteAlert(false)} + isOpen={deleteAlert} + message={"Are you sure you want to delete sponers?"} + alertHandler={handleDelete} + isLoading={isLoading} + /> + + ); +}; - - ); - }; - - export default Rejected; - \ No newline at end of file +export default Rejected; diff --git a/src/Pages/IO_Management/CreateIO/IONAVDetails/RequestApproveModal.jsx b/src/Pages/IO_Management/CreateIO/IONAVDetails/RequestApproveModal.jsx index 861d3ed..edad9d3 100644 --- a/src/Pages/IO_Management/CreateIO/IONAVDetails/RequestApproveModal.jsx +++ b/src/Pages/IO_Management/CreateIO/IONAVDetails/RequestApproveModal.jsx @@ -140,7 +140,7 @@ const RequestApproveModal = ({ isOpen, onClose, firstField ,id}) => { )} - Maximum length should be 200 characters. You have entered + Maximum length should be 200 characters. You have entered {watch("checkerComment")?.length || 0} characters. diff --git a/src/Pages/IO_Management/CreateIO/IOTransaction/ApproveDistrubationModal.jsx b/src/Pages/IO_Management/CreateIO/IOTransaction/ApproveDistrubationModal.jsx new file mode 100644 index 0000000..639d4b7 --- /dev/null +++ b/src/Pages/IO_Management/CreateIO/IOTransaction/ApproveDistrubationModal.jsx @@ -0,0 +1,179 @@ +import { + Box, + Button, + FormControl, + FormHelperText, + 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 ToastBox from "../../../../Components/ToastBox"; + import { useApproveDistributedMutation } from "../../../../Services/io.service"; + + export const conformModalSchema = yup.object().shape({ + // checkerComment: yup.string().required("Comment is required") + // .max(50, "Investment name cannot be more than 50 characters"), + checkerComment: yup + .string() + .required("Comment is required") + .max(200, "Approve Comment cannot be more than 200 characters"), + }); + + const ApproveDistrubationModal = ({ isOpen, onClose, firstField ,id, onBigModalClose}) => { + const [isBtnLoading , setIsBtnLoading] = useState(false) + + const toast = useToast() + + + + const { + register, + reset, + watch, + handleSubmit, + formState: { errors }, + } = useForm({ + resolver: yupResolver(conformModalSchema), + }); + + const [ approveDistributed ] = useApproveDistributedMutation() + + + const onSubmit = async(data) => { + setIsBtnLoading(true) + try { + const res = await approveDistributed({data,id}) + if (res?.error) { + toast({ + render: () => ( + + ), + }); + setIsBtnLoading(false) + }else if(res?.data){ + toast({ + render: () => ( + + ), + }); + onClose() + onBigModalClose() + setIsBtnLoading(false) + }else{ + toast({ + render: () => ( + + ), + }); + setIsBtnLoading(false) + } + } 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() + } + + return ( + + + + Approve Comment + + {isLoading ? ( + + ) : ( + + + + Comment +