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, CheckIcon, CloseIcon, 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 AddPending from "./AddPending"; import { useParams } from "react-router-dom"; import { useUpdateIOCaseMutation } from "../../../../Services/io.service"; const formatDate = (date) => new Date(date).toLocaleDateString(); const Pending = () => { const toast = useToast(); const params = useParams() const id = params?.id const firstField = useRef(); const { isOpen, onOpen, onClose } = useDisclosure(); const { IODetails, approved, setApproved } = 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?.ioCashStatusHistory?.Pending?.filter((item) => { // Filter by name (case insensitive) const name = item.transactionDate; const searchLower = searchTerm.toLowerCase(); const nameMatches = name.toLowerCase().includes(searchLower); return nameMatches; }); const tableHeadRow = [ "Sr No.", "Transaction date", "Amount", "Comments", "Update by", "Update On", "Status", ]; const extractedArray = filteredData?.map((item, index) => ({ id: item?.id, "Sr No.": ( {index + 1}. ), "Transaction date": ( {formatDate(item?.transactionDate)} ), Amount: ( $ {item?.transactionAmount} ), Comments: ( {item?.comments} ), "Update by": ( {item?.creator?.firstName} ), "Update On": ( {formatDate(item.updatedAt)} ), Status: ( ), })); const handleDelete = () => { const updatedSponsors = sponser.filter( (sponsor) => sponsor.id !== actionId ); setTimeout(() => { setCaseDetails(updatedSponsors); setDeleteAlert(false); setIsLoading(false); }, 100); setIsLoading(true); }; const Total = () => { return (
Balance in IO Cash {" "} {} {"48,000.00"} {" "}
); }; 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 ( setSearchTerm(e.target.value)} /> } setMouseEnteredId={setMouseEnteredId} setMouseEntered={setMouseEntered} /> setDeleteAlert(false)} isOpen={deleteAlert} message={"Are you sure you want to delete sponers?"} alertHandler={handleDelete} isLoading={isLoading} /> ); }; export default Pending;