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 * as XLSX from "xlsx"; 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 AddApproved from "./AddCaseDetails"; import { useUpdateIOCaseMutation } from "../../../../Services/io.service"; import { useParams } from "react-router-dom"; import AddCaseDetails from "./AddCaseDetails"; const formatDate = (date) => new Date(date).toLocaleDateString(); const Approved = () => { const firstField = useRef(); const params = useParams(); const toast = useToast(); const id = params?.id; 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(""); 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", }); }; console.log("==============", IODetails?.ioCashStatusHistory?.Approved); // Table filter const filteredData = IODetails?.ioCashStatusHistory?.Approved?.filter( (item) => { // Filter by name (case insensitive) const name = item.transactionDate; const searchLower = searchTerm.toLowerCase(); const nameMatches = name.toLowerCase().includes(searchLower); return nameMatches; } ); const [updateIOCase] = useUpdateIOCaseMutation(); const tableHeadRow = [ "Sr No.", "Transaction Date", "Transaction Type", "Amount", "Comments", "Update By", "Update On", ]; const extractedArray = filteredData?.map((item, index) => ({ id: item?.id, "Sr No.": ( {index + 1}. ), "Transaction Date": ( {formatDate(item?.transactionDate)} ), "Transaction Type": ( {item?.transactionType} ), Amount: ( $ {parseFloat(item?.transactionAmount || 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} ), Comments: ( {item?.comments ? item?.comments : "---"} ), "Update By": ( {/* */} {item?.modifier?.firstName} ), "Update On": ( {formatDate(item.updatedAt)} ), })); const handleDelete = () => { const updatedSponsors = sponser.filter( (sponsor) => sponsor.id !== actionId ); setTimeout(() => { setCaseDetails(updatedSponsors); setDeleteAlert(false); setIsLoading(false); }, 100); setIsLoading(true); }; const ioCashExporteDetails = IODetails?.ioCashStatusHistory?.Approved?.map( (item, index) => ({ "Transaction date": item?.transactionDate, "Transaction type": item?.transactionType, Amount: parseFloat(item?.transactionAmount) || 0, Comments: item?.comments, }) ); const exportToExcelNew = (data, fileName) => { const worksheet = XLSX.utils.json_to_sheet(data); const workbook = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1"); // Export file XLSX.writeFile(workbook, `${fileName}.xlsx`); }; const Total = () => { return (
Balance in IO Cash {" "} {" "} $ {/* {IODetails?.ioCash} */} {parseFloat(IODetails?.ioCash || 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2, })} {} {" "}
); }; 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)} /> {/* */} {/* {IODetails?.isInvestedAmount ? ( localStorage?.getItem('role') ==="Maker" && ) : null} */} } setMouseEnteredId={setMouseEnteredId} setMouseEntered={setMouseEntered} /> {/* setDeleteAlert(false)} isOpen={deleteAlert} message={"Are you sure you want to delete sponers?"} alertHandler={handleDelete} isLoading={isLoading} /> */} ); }; export default Approved;