diff --git a/src/Pages/FawateerChecker/ApproveHistory/ApproveHistory.jsx b/src/Pages/FawateerChecker/ApproveHistory/ApproveHistory.jsx deleted file mode 100644 index 4c7042c..0000000 --- a/src/Pages/FawateerChecker/ApproveHistory/ApproveHistory.jsx +++ /dev/null @@ -1,289 +0,0 @@ -import { - Avatar, - Badge, - Box, - Button, - HStack, - Input, - Text, - Tooltip, - useDisclosure, - useToast, - } from "@chakra-ui/react"; - import React, { useContext, useEffect, useState } from "react"; - import { CheckIcon, CloseIcon } from "@chakra-ui/icons"; -import Pagination from "../../../Components/Pagination"; -import GlobalStateContext from "../../../Contexts/GlobalStateContext"; -import CustomAlertDialog from "../../../Components/CustomAlertDialog"; -import DrawalRequestReject from "../../WithDrawal/DrawalRequest/DrawalRequestReject"; -import NormalTable from "../../../Components/DataTable/NormalTable"; -import DrawalRequestApprove from "../../WithDrawal/DrawalRequest/DrawalRequestApprove"; -import { generateSerialNumber } from "../../../Constants/Constants"; -import { useGetApproveHistoryQuery, useGetFawateerRequestQuery } from "../../../Services/fawateer.request.service"; -import { TABLE_PAGINATION } from "../../../Constants/Paginations"; -import { OPACITY_ON_LOAD } from "../../../Layout/animations"; - - const ApproveHistory = () => { - const toast = useToast(); - const { slideFromRight, approveHistory, setApproveHistory } = - 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 [pageSize, setPageSize] = useState(TABLE_PAGINATION?.size); - const [currentPage, setCurrentPage] = useState(TABLE_PAGINATION?.page); - - const formatDate = (date) => { - return new Date(date).toLocaleDateString('en-GB', { - day: '2-digit', - month: '2-digit', - year: 'numeric', - }); - }; - - const { - isOpen: isConfirmOpen, - onOpen: onConfirmOpen, - onClose: onConfirmClose, - } = useDisclosure(); - const { - isOpen: isRejectOpen, - onOpen: onRejectOpen, - onClose: onRejectClose, - } = useDisclosure(); - - const { - data, - isLoading: drawalRequestLoading, - error, - refetch - } = useGetApproveHistoryQuery(); - - console.log(data); - - - - - // Use useEffect to refetch data when the component mounts - useEffect(() => { - refetch(); - }, [refetch]); - - useEffect(() => { - - // Simulate loading - const timer = setTimeout(() => { - setIsLoading(false); - }, 1500); - - // Cleanup the timer on component unmount - return () => clearTimeout(timer); - }, []); - - // ====================================================[Table Filter]================================================================ - const filteredData = approveHistory?.filter((item) => { - // Filter by name (case insensitive) - const name = item.firstName; - const searchLower = searchTerm.toLowerCase(); - const nameMatches = name.toLowerCase().includes(searchLower); - - // Filter by status - // const status = item.status; - // const statusLower = status ? "active" : "inactive"; - - // const statusMatches = - // statusFilter === "all" || - // (statusFilter === "active" && status === true) || - // (statusFilter === "inactive" && status === false); - - return nameMatches; - - - }); - - // ====================================================[Table Setup]================================================================ - const tableHeadRow = [ - "Sr.no", - "Client ID", - "First Name", - "Last Name", - "E-mail ID", - "Phone Number", - "Transaction Date", - "Transaction Amount", - "Status" - ]; - - - - const extractedArray = filteredData?.map((item, idx) => ({ - // id: item?.id, - "Sr.no": ( - - {generateSerialNumber(idx,currentPage, pageSize )} - - ), - "Client ID": ( - - {item.clientReference_id} - - ), - "First Name": ( - - - {item.firstName} - - - ), - "Last Name": ( - - - {item.lastName} - - - ), - "E-mail ID": ( - - - {item.emailAddress} - - - ), - "Phone Number": ( - - - {item.mobileNumber} - - - ), - "Transaction Date": ( - - - {item.transaction_date} - - - ), - "Transaction Amount": ( - - - {/* {item.investorAmount} */} - {parseFloat(item?.transaction_amount || 0).toLocaleString(undefined, { - minimumFractionDigits: 2, - maximumFractionDigits: 2, - })} - {/* {item?.transaction_amount} */} - - - ), - "Status": ( - - - {item.transactionStatus} - - - ), - })); - - const handleDelete = () => { - const updatedSponsors = sponser.filter( - (sponsor) => sponsor.id !== actionId - ); - - setTimeout(() => { - setSponser(updatedSponsors); - setDeleteAlert(false); - setIsLoading(false); - }, 100); - setIsLoading(true); - }; - - return ( - - - - setSearchTerm(e.target.value)} - /> - - - - - - - - setDeleteAlert(false)} - isOpen={deleteAlert} - message={"Are you sure you want to delete sponers?"} - alertHandler={handleDelete} - isLoading={isLoading} - /> - - - - ); - }; - - export default ApproveHistory; - \ No newline at end of file diff --git a/src/Pages/FawateerChecker/ApproveHistory/ApproveHistoryChecker.jsx b/src/Pages/FawateerChecker/ApproveHistory/ApproveHistoryChecker.jsx new file mode 100644 index 0000000..8aa4fb5 --- /dev/null +++ b/src/Pages/FawateerChecker/ApproveHistory/ApproveHistoryChecker.jsx @@ -0,0 +1,299 @@ +import { + Avatar, + Badge, + Box, + Button, + HStack, + Input, + Text, + Tooltip, + useDisclosure, + useToast, +} from "@chakra-ui/react"; +import React, { useContext, useEffect, useState } from "react"; +import { CheckIcon, CloseIcon } from "@chakra-ui/icons"; +import Pagination from "../../../Components/Pagination"; +import GlobalStateContext from "../../../Contexts/GlobalStateContext"; +import CustomAlertDialog from "../../../Components/CustomAlertDialog"; +import DrawalRequestReject from "../../WithDrawal/DrawalRequest/DrawalRequestReject"; +import NormalTable from "../../../Components/DataTable/NormalTable"; +import DrawalRequestApprove from "../../WithDrawal/DrawalRequest/DrawalRequestApprove"; +import { generateSerialNumber } from "../../../Constants/Constants"; +import { + useGetApproveHistoryQuery, + useGetFawateerRequestQuery, +} from "../../../Services/fawateer.request.service"; +import { TABLE_PAGINATION } from "../../../Constants/Paginations"; +import { OPACITY_ON_LOAD } from "../../../Layout/animations"; + +const ApproveHistory = () => { + const toast = useToast(); + const { slideFromRight, approveHistory, setApproveHistory } = + 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 [pageSize, setPageSize] = useState(TABLE_PAGINATION?.size); + const [currentPage, setCurrentPage] = useState(TABLE_PAGINATION?.page); + + const formatDate = (date) => { + return new Date(date).toLocaleDateString("en-GB", { + day: "2-digit", + month: "2-digit", + year: "numeric", + }); + }; + + const { + isOpen: isConfirmOpen, + onOpen: onConfirmOpen, + onClose: onConfirmClose, + } = useDisclosure(); + const { + isOpen: isRejectOpen, + onOpen: onRejectOpen, + onClose: onRejectClose, + } = useDisclosure(); + + const { + data, + isLoading: drawalRequestLoading, + error, + refetch, + } = useGetApproveHistoryQuery(); + + console.log(data?.data?.rows); + + // Use useEffect to refetch data when the component mounts + useEffect(() => { + refetch(); + }, [refetch]); + + useEffect(() => { + // Simulate loading + const timer = setTimeout(() => { + setIsLoading(false); + }, 1500); + + // Cleanup the timer on component unmount + return () => clearTimeout(timer); + }, []); + + // ====================================================[Table Filter]================================================================ + const filteredData = data?.data?.rows?.filter((item) => { + // Filter by name (case insensitive) + const name = item.firstName; + const searchLower = searchTerm.toLowerCase(); + const nameMatches = name.toLowerCase().includes(searchLower); + + // Filter by status + // const status = item.status; + // const statusLower = status ? "active" : "inactive"; + + // const statusMatches = + // statusFilter === "all" || + // (statusFilter === "active" && status === true) || + // (statusFilter === "inactive" && status === false); + + return nameMatches; + }); + + // ====================================================[Table Setup]================================================================ + const tableHeadRow = [ + "Sr.no", + "Client ID", + "First Name", + "Last Name", + "E-mail ID", + "Phone Number", + "Transaction Date", + "Transaction Amount", + "Status", + ]; + + const extractedArray = filteredData?.map((item, idx) => ({ + // id: item?.id, + "Sr.no": ( + + {generateSerialNumber(idx, currentPage, pageSize)} + + ), + "Client ID": ( + + {item.clientReference_id} + + ), + "First Name": ( + + + {item.firstName} + + + ), + "Last Name": ( + + + {item.lastName} + + + ), + "E-mail ID": ( + + + {item.emailAddress} + + + ), + "Phone Number": ( + + + {item.mobileNumber} + + + ), + "Transaction Date": ( + + + {item.transaction_date} + + + ), + "Transaction Amount": ( + + + {/* {item.investorAmount} */} + {parseFloat(item?.transaction_amount || 0).toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} + {/* {item?.transaction_amount} */} + + + ), + Status: ( + + + {item.transactionStatus} + + + ), + })); + + const handleDelete = () => { + const updatedSponsors = sponser.filter( + (sponsor) => sponsor.id !== actionId + ); + + setTimeout(() => { + setSponser(updatedSponsors); + setDeleteAlert(false); + setIsLoading(false); + }, 100); + setIsLoading(true); + }; + + return ( + + + + setSearchTerm(e.target.value)} + /> + + + + + + + + setDeleteAlert(false)} + isOpen={deleteAlert} + message={"Are you sure you want to delete sponers?"} + alertHandler={handleDelete} + isLoading={isLoading} + /> + + + + ); +}; + +export default ApproveHistory; diff --git a/src/Pages/FawateerChecker/ApproveHistory/ApproveHistoryMaker.jsx b/src/Pages/FawateerChecker/ApproveHistory/ApproveHistoryMaker.jsx new file mode 100644 index 0000000..07a25f7 --- /dev/null +++ b/src/Pages/FawateerChecker/ApproveHistory/ApproveHistoryMaker.jsx @@ -0,0 +1,320 @@ +import { + Avatar, + Badge, + Box, + Button, + HStack, + Input, + Text, + Tooltip, + useDisclosure, + useToast, + } from "@chakra-ui/react"; + import React, { useContext, useEffect, useState } from "react"; + import { CheckIcon, CloseIcon } from "@chakra-ui/icons"; + import Pagination from "../../../Components/Pagination"; + import GlobalStateContext from "../../../Contexts/GlobalStateContext"; + import CustomAlertDialog from "../../../Components/CustomAlertDialog"; + import DrawalRequestReject from "../../WithDrawal/DrawalRequest/DrawalRequestReject"; + import NormalTable from "../../../Components/DataTable/NormalTable"; + import DrawalRequestApprove from "../../WithDrawal/DrawalRequest/DrawalRequestApprove"; + import { generateSerialNumber } from "../../../Constants/Constants"; + import { + useGetApproveHistoryQuery, + useGetFawateerForMakerRequestQuery, + useGetFawateerRequestQuery, + } from "../../../Services/fawateer.request.service"; + import { TABLE_PAGINATION } from "../../../Constants/Paginations"; + import { OPACITY_ON_LOAD } from "../../../Layout/animations"; + + const ApproveHistoryMaker = () => { + const toast = useToast(); + const { slideFromRight, approveHistory, setApproveHistory } = + 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 [debouncedSearchTerm, setDebouncedSearchTerm] = useState(""); + + const [pageSize, setPageSize] = useState(TABLE_PAGINATION?.size); + const [currentPage, setCurrentPage] = useState(TABLE_PAGINATION?.page); + + const formatDate = (date) => { + return new Date(date).toLocaleDateString("en-GB", { + day: "2-digit", + month: "2-digit", + year: "numeric", + }); + }; + + const { + isOpen: isConfirmOpen, + onOpen: onConfirmOpen, + onClose: onConfirmClose, + } = useDisclosure(); + const { + isOpen: isRejectOpen, + onOpen: onRejectOpen, + onClose: onRejectClose, + } = useDisclosure(); + + const { + data, + isLoading: drawalRequestLoading, + error, + refetch + } = useGetFawateerForMakerRequestQuery( + { + page: debouncedSearchTerm ? undefined : currentPage, // Omit pagination for search + size: debouncedSearchTerm ? undefined : pageSize, // Omit pagination for search + searchTerm: debouncedSearchTerm, + }, + { + skip: debouncedSearchTerm === "" && searchTerm !== "", // Skip if search is empty and it's not the initial request + } + ); + + console.log(data); + + useEffect(() => { + const handler = setTimeout(() => { + setDebouncedSearchTerm(searchTerm); + }, 500); // Adjust delay as needed + return () => { + clearTimeout(handler); + }; + }, [searchTerm]); + + // Use useEffect to refetch data when the component mounts + useEffect(() => { + refetch(); + }, [refetch]); + + useEffect(() => { + // Simulate loading + const timer = setTimeout(() => { + setIsLoading(false); + }, 1500); + + // Cleanup the timer on component unmount + return () => clearTimeout(timer); + }, []); + + // ====================================================[Table Filter]================================================================ + const filteredData = data?.data?.rows?.filter((item) => { + // Filter by name (case insensitive) + const name = item.firstName; + const searchLower = searchTerm.toLowerCase(); + const nameMatches = name.toLowerCase().includes(searchLower); + + // Filter by status + // const status = item.status; + // const statusLower = status ? "active" : "inactive"; + + // const statusMatches = + // statusFilter === "all" || + // (statusFilter === "active" && status === true) || + // (statusFilter === "inactive" && status === false); + + return nameMatches; + }); + + // ====================================================[Table Setup]================================================================ + const tableHeadRow = [ + "Sr.no", + "Client ID", + "First Name", + "Last Name", + "E-mail ID", + "Phone Number", + "Transaction Date", + "Transaction Amount", + "Status", + ]; + + const extractedArray = filteredData?.map((item, idx) => ({ + // id: item?.id, + "Sr.no": ( + + {generateSerialNumber(idx, currentPage, pageSize)} + + ), + "Client ID": ( + + {item.clientReference_id} + + ), + "First Name": ( + + + {item.firstName} + + + ), + "Last Name": ( + + + {item.lastName} + + + ), + "E-mail ID": ( + + + {item.emailAddress} + + + ), + "Phone Number": ( + + + {item.mobileNumber} + + + ), + "Transaction Date": ( + + + {item.transaction_date} + + + ), + "Transaction Amount": ( + + + {/* {item.investorAmount} */} + {parseFloat(item?.transaction_amount || 0).toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} + {/* {item?.transaction_amount} */} + + + ), + Status: ( + + + {item.transactionStatus} + + + ), + })); + + const handleDelete = () => { + const updatedSponsors = sponser.filter( + (sponsor) => sponsor.id !== actionId + ); + + setTimeout(() => { + setSponser(updatedSponsors); + setDeleteAlert(false); + setIsLoading(false); + }, 100); + setIsLoading(true); + }; + + return ( + + + + setSearchTerm(e.target.value)} + /> + + + + + + + + setDeleteAlert(false)} + isOpen={deleteAlert} + message={"Are you sure you want to delete sponers?"} + alertHandler={handleDelete} + isLoading={isLoading} + /> + + + + ); + }; + + export default ApproveHistoryMaker; + \ No newline at end of file diff --git a/src/Pages/FawateerChecker/ApproveRequest/RequestApproveModal.jsx b/src/Pages/FawateerChecker/ApproveRequest/RequestApproveModal.jsx index b3a13f2..fab8abe 100644 --- a/src/Pages/FawateerChecker/ApproveRequest/RequestApproveModal.jsx +++ b/src/Pages/FawateerChecker/ApproveRequest/RequestApproveModal.jsx @@ -1,9 +1,7 @@ import { - Badge, Box, Button, FormControl, - FormErrorMessage, FormLabel, Input, Modal, @@ -21,218 +19,143 @@ import { import React, { useEffect, useState } from "react"; import * as yup from "yup"; import { yupResolver } from "@hookform/resolvers/yup"; -import { Controller, useForm } from "react-hook-form"; -import { - useGetDepositRequestByIdQuery, - useGetDepositRequestQuery, - useUpdateDepositRequestMutation, -} from "../../../Services/deposit.request.service"; -import FullscreenLoaders from "../../../Components/Loaders/FullscreenLoaders"; +import { useForm } from "react-hook-form"; +import { useDepositRejectMutation } from "../../../Services/deposit.request.service"; import ToastBox from "../../../Components/ToastBox"; -import CurrencyInput, { formatCurrency } from "../../../Components/CurrencyInput"; - -const FILE_TYPES = ["image/jpeg", "image/png", "image/gif"]; +import { useApproveCommentMutation } from "../../../Services/fawateer.request.service"; export const conformModalSchema = yup.object().shape({ - investorAmount: yup.string().required("Investor amount is required"), - comment: yup.string().notRequired(), - supporting_FileName: yup.mixed().required("File is required"), - // .test("fileType", "Unsupported File Format", (value) => { - // return value && FILE_TYPES.includes(value.type); - // }), + checkerComment: yup.string().required("Comment is required"), }); -const RequestApproveModal = ({ - isOpen, - onClose, - firstField, - id, - data: requestData, -}) => { - const toast = useToast(); - const [file, setFile] = useState(); - const [isBtnLoading, setIsBtnLoading] = useState(false); +const RequestApproveModal = ({ isOpen, onClose, firstField ,id}) => { + const [isBtnLoading , setIsBtnLoading] = useState(false) - const [updateDepositRequest] = useUpdateDepositRequestMutation(); - const { data, isLoading } = useGetDepositRequestByIdQuery(id, { - skip: !id, - }); + const toast = useToast() - console.log(data?.data?.investorAmount); - - const { - control, + const { register, reset, - watch, handleSubmit, formState: { errors }, } = useForm({ resolver: yupResolver(conformModalSchema), }); - useEffect(() => { - if (data) { - const investorAmount = parseFloat(data?.data?.investorAmount); - reset({ - investorAmount: investorAmount, - accountName: data?.data?.accountName, - }); - } - }, [id, data, reset]); - - const onSubmit = async (data) => { - setIsBtnLoading(true); - const formData = new FormData(); - - formData.append("investorAmount", data.investorAmount); - formData.append("comment", data.comment); - const file = data.supporting_FileName["0"]; - formData.append("supporting_FileName", file); + const [ approveFawateer ] = useApproveCommentMutation() + + const onSubmit = async(data) => { + console.log(data, "tewxttttt"); + setIsBtnLoading(true) try { - const res = await updateDepositRequest({ id, data: formData }); - + const res = await approveFawateer({data,id}) if (res?.error) { toast({ render: () => ( - + ), }); - setIsBtnLoading(false); - } else if (res?.data?.statusCode === 200) { + setIsBtnLoading(false) + }else if(res?.data){ toast({ - render: () => , + render: () => ( + + ), }); - setIsBtnLoading(false); + onClose() + setIsBtnLoading(false) + }else{ + toast({ + render: () => ( + + ), + }); + setIsBtnLoading(false) } - } catch (error) {} - - heandleOnClose(); + } catch (error) { + + } }; - const heandleOnClose = () => { - reset(); - onClose(); + 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 ( - + - - Confirm + Approve Comment {isLoading ? ( ) : ( - - - {/* - - Deposit Amount - {data?.data?.currencyCode} - - - {errors.investorAmount && ( - - {errors.investorAmount.message} - - )} - */} - - - Deposit Amount - ( - - )} - /> - {errors.investorAmount && ( - - {errors.investorAmount.message} - - )} - - - - Upload Supporting - - {errors.supporting_FileName && ( - - {errors.supporting_FileName.message} - - )} - - - Comments -