import { Avatar, Box, Button, HStack, Input, Table, Tag, Tbody, Text, Th, Tr, useDisclosure, useToast, } from "@chakra-ui/react"; import React, { useContext, useEffect, useRef, useState } from "react"; import { OPACITY_ON_LOAD } from "../../../Layout/animations"; import NormalTable from "../../../Components/DataTable/NormalTable"; import Pagination from "../../../Components/Pagination"; import GlobalStateContext from "../../../Contexts/GlobalStateContext"; import CustomAlertDialog from "../../../Components/CustomAlertDialog"; import ToastBox from "../../../Components/ToastBox"; import { debounce } from "../../Master/Sponser/AddSponser"; import { AddIcon } from "@chakra-ui/icons"; import AddCashDetails from "./AddCashDetails"; const formatDate = (date) => new Date(date).toLocaleDateString(); // Simple date formatter const IOCashDetails = () => { const toast = useToast(); const firstField = useRef(); const { isOpen, onOpen, onClose } = useDisclosure(); const { caseDetails, setCaseDetails, IODetails } = 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(""); useEffect(() => { // Simulate loading const timer = setTimeout(() => { setIsLoading(false); }, 1500); // Cleanup the timer on component unmount return () => clearTimeout(timer); }, []); // Calculate totals const totalAmount = caseDetails.reduce( (acc, caseDetail) => acc + caseDetail.amount, 0 ); // Table setup const tableHeadRow = [ "Date", "Transaction type", "Amount", "Comments", "Update by ", "Update On", ]; const handleUpdateStatus = debounce((id) => { setCaseDetails((prevSponser) => prevSponser.map((sponsor) => sponsor.id === id ? { ...sponsor, status: !sponsor.status } : sponsor ) ); toast({ render: () => , }); }, 300); // Table filter const filteredData = IODetails?.ioCashHistory?.filter((item) => { const name = item.transactionType; const searchLower = searchTerm.toLowerCase(); const nameMatches = name.toLowerCase().includes(searchLower); return nameMatches; }).sort((b, a) => new Date(a.createdAt) - new Date(b.createdAt)); const extractedArray = filteredData?.map((item, index) => ({ id: item?.id, "Date": ( {item?.transactionDate} ), "Transaction type": ( {item?.transactionType} ), "Amount": ( {`$${parseFloat(item.transactionAmount||0).toLocaleString()}`} ), "Comments": ( {item.comments} ), "Update by ": ( {item.creator?.firstName} ), "Update On": ( {item.updateOn} ), })); const handleDelete = () => { const updatedSponsors = sponser.filter( (sponsor) => sponsor.id !== actionId ); setTimeout(() => { setCaseDetails(updatedSponsors); setDeleteAlert(false); setIsLoading(false); }, 100); setIsLoading(true); }; const Total = () => { return (
Total {" "} {/* {totalAmount} */} {"5000"} {" "} {" "} {" "}
); }; return ( setSearchTerm(e.target.value)} /> {IODetails?.isInvestedAmount ? :null} } setMouseEnteredId={setMouseEnteredId} setMouseEntered={setMouseEntered} /> setDeleteAlert(false)} isOpen={deleteAlert} message={"Are you sure you want to delete sponers?"} alertHandler={handleDelete} isLoading={isLoading} /> ); }; export default IOCashDetails;