Files
tanami-admin-panel/src/Pages/IO_Management/CreateIO/IONAVDetailsOld.jsx

299 lines
8.6 KiB
React
Raw Normal View History

2024-08-28 19:35:39 +05:30
import React, { useContext, useEffect, useRef, useState } from "react";
import GlobalStateContext from "../../../Contexts/GlobalStateContext";
import {
Box,
HStack,
Input,
Text,
Table,
Tbody,
Th,
Tr,
Avatar,
useDisclosure,
Button,
Badge,
} from "@chakra-ui/react";
import { OPACITY_ON_LOAD } from "../../../Layout/animations";
import Pagination from "../../../Components/Pagination";
import NormalTable from "../../../Components/DataTable/NormalTable";
import CustomAlertDialog from "../../../Components/CustomAlertDialog";
import { formatDatee } from "../../../Components/FormField";
import { AddIcon } from "@chakra-ui/icons";
import AddIONav from "./AddIONav";
import { formatDate } from "../../Master/Sponser/Sponsers";
2024-08-30 12:07:10 +05:30
import { LuFileSpreadsheet } from "react-icons/lu";
2024-10-18 13:19:23 +05:30
import { exportToExcel, exportToExcelNew } from "../../../Constants/Constants";
2024-07-05 15:28:02 +05:30
const IONAVDetails = () => {
2024-08-12 15:35:39 +05:30
const { navDetails, setNavDetails, IODetails } =
2024-07-10 12:02:35 +05:30
useContext(GlobalStateContext);
2024-08-28 19:35:39 +05:30
const firstField = useRef();
const { isOpen, onOpen, onClose } = useDisclosure();
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("");
2024-07-10 12:02:35 +05:30
2024-08-28 19:35:39 +05:30
console.log(IODetails?.ioNAVHistory);
2024-08-12 15:35:39 +05:30
2024-07-10 12:02:35 +05:30
useEffect(() => {
// Simulate loading
const timer = setTimeout(() => {
setIsLoading(false);
}, 1500);
// Cleanup the timer on component unmount
return () => clearTimeout(timer);
}, []);
2024-08-28 19:35:39 +05:30
// Table setup
const tableHeadRow = [
// "Sr.No",
"Valuation Date",
"NAV",
"Last NAV update",
"Investment Closed",
"Comments",
"Update by ",
// "Update On",
];
// Table filter
const filteredData = IODetails?.ioNAVHistory
?.filter((item) => {
const name = item.transactionType;
const searchLower = searchTerm.toLowerCase();
const nameMatches = name.toLowerCase().includes(searchLower);
return nameMatches;
2024-09-02 17:43:54 +05:30
})
2024-09-03 13:10:31 +05:30
.reverse()
// .sort((b, a) => new Date(a.transactionDate) - new Date(b.transactionDate));
2024-08-28 19:35:39 +05:30
const extractedArray = filteredData?.map((item, index) => ({
2024-07-10 12:02:35 +05:30
id: item?.id,
2024-08-28 19:35:39 +05:30
"Sr.No": index + 1,
2024-08-12 15:35:39 +05:30
"Valuation Date": (
<Text
justifyContent={"center"}
as={"span"}
color={"teal.900"}
fontWeight={"500"}
className="d-flex align-items-center web-text-small"
>
{/* {/ {formatDatee(item.transactionDate)} /} */}
2024-08-26 16:05:03 +05:30
{formatDate(item?.transactionDate)}
2024-08-12 15:35:39 +05:30
</Text>
),
2024-08-28 19:35:39 +05:30
NAV: (
2024-07-10 12:02:35 +05:30
<Text
2024-08-30 16:50:05 +05:30
justifyContent={"center"}
2024-07-10 12:02:35 +05:30
as={"span"}
color={"teal.900"}
fontWeight={"500"}
2024-08-30 16:50:05 +05:30
className="d-flex align-items-center web-text-small"
2024-07-10 12:02:35 +05:30
>
{/* {/ {`${item.transactionAmount}`} /} */}
<Badge ms={1} colorScheme="green" me={1}>$</Badge>
{`${parseFloat(item.transactionAmount || 0).toLocaleString()}`}
2024-07-10 12:02:35 +05:30
</Text>
),
2024-08-12 15:35:39 +05:30
"Last NAV update": (
2024-07-10 12:02:35 +05:30
<Text
2024-08-12 15:35:39 +05:30
justifyContent={"center"}
2024-07-10 12:02:35 +05:30
as={"span"}
color={"teal.900"}
fontWeight={"500"}
className="d-flex align-items-center web-text-small"
>
2024-08-13 19:58:31 +05:30
{item.previousNAVvalue && `${item.previousNAVvalue}`}
2024-08-12 15:35:39 +05:30
</Text>
),
"Investment Closed": (
<Text
justifyContent={"center"}
as={"span"}
color={"teal.900"}
fontWeight={"500"}
className="d-flex align-items-center web-text-small"
>
2024-08-28 19:35:39 +05:30
{item.initialNAVvalue && `${item.initialNAVvalue}`}
2024-07-10 12:02:35 +05:30
</Text>
),
2024-08-28 19:35:39 +05:30
Comments: (
2024-11-07 19:32:55 +05:30
// <Text
// justifyContent={"center"}
// as={"span"}
// color={"teal.900"}
// fontWeight={"500"}
// className="d-flex align-items-center web-text-small"
// >
// {item.comments}
// </Text>
2024-07-10 12:02:35 +05:30
<Text
as={"span"}
color={"teal.900"}
fontWeight={"500"}
2024-11-07 19:32:55 +05:30
maxWidth="200px" // Adjust width as needed
display="block" // Ensure block display for proper truncation
overflow="hidden"
isTruncated
textOverflow="ellipsis"
2024-07-10 12:02:35 +05:30
>
{item.comments}
</Text>
),
"Update by ": (
<Text
2024-08-28 19:35:39 +05:30
justifyContent={"center"}
2024-07-10 12:02:35 +05:30
as={"span"}
color={"teal.900"}
fontWeight={"500"}
2024-08-12 15:35:39 +05:30
gap={2}
2024-07-10 12:02:35 +05:30
className="d-flex align-items-center web-text-small"
>
2024-10-15 13:11:05 +05:30
<Avatar
size="sm"
name={item.creator?.firstName}
src={item.creator?.profilePhoto}
/>
{item.creator?.firstName}
2024-07-10 12:02:35 +05:30
</Text>
),
"Update On": (
<Text
2024-10-15 13:11:05 +05:30
justifyContent={"center"}
2024-07-10 12:02:35 +05:30
as={"span"}
color={"teal.900"}
fontWeight={"500"}
className="d-flex align-items-center web-text-small"
>
2024-10-18 13:19:23 +05:30
{formatDate(item.updatedAt)}
2024-07-10 12:02:35 +05:30
</Text>
),
2024-08-12 15:35:39 +05:30
}));
2024-07-10 12:02:35 +05:30
2024-08-30 12:07:10 +05:30
const customHeaders = [
{ label: "ID", key: "id" },
{ label: "Valuation Date", key: "transactionDate" },
{ label: "NAV", key: "transactionAmount" },
{ label: "Last NAV update", key: "previousNAVvalue" },
2024-08-30 12:07:10 +05:30
{ label: "Investment Closed", key: "initialNAVvalue" },
{ label: "Comments", key: "comments" },
2024-08-30 12:07:10 +05:30
2024-08-30 16:09:07 +05:30
// { label: "Update by", key: "creator" },
{ label: "Transaction Type", key: "transactionType" },
2024-08-30 16:09:07 +05:30
// { label: "Comments", key: "comments" },
2024-08-30 12:07:10 +05:30
// Add more headers as needed
];
console.log(IODetails?.ioNAVHistory);
2024-10-18 13:19:23 +05:30
const ioNavExport = IODetails?.ioNAVHistory?.map((item, index) => ({
"ID": item?.id, // Keep as integer if it's already a number
"Valuation Date": formatDate(item?.transactionDate), // Assuming this is a date, no conversion needed
"NAV": parseFloat(item?.transactionAmount) || 0, // Convert to float
"Last NAV update": parseFloat(item?.previousNAVvalue) || 0, // Convert to float
"Investment Closed": parseFloat(item?.initialNAVvalue) || 0, // Convert to float
"Comments": item?.comments, // Keep as string
"Transaction Type": item?.transactionType, // Keep as string
"Update by ": item?.creator?.firstName, // Keep as string
// "Update On": formatDate(item?.updatedAt) // Assuming this is a date, no conversion needed
}));
2024-08-30 12:07:10 +05:30
2024-07-10 12:02:35 +05:30
const handleDelete = () => {
2024-08-28 19:35:39 +05:30
const updatedNav = navDetails.filter((sponsor) => sponsor.id !== actionId);
2024-07-10 12:02:35 +05:30
setTimeout(() => {
setNavDetails(updatedNav);
setDeleteAlert(false);
setIsLoading(false);
}, 100);
setIsLoading(true);
};
const handleExport = () => {};
2024-08-28 19:35:39 +05:30
return (
<Box {...OPACITY_ON_LOAD} pb={0}>
<Box bg="white.500">
<HStack
display={"flex"}
justifyContent={"space-between"}
pb={3}
spacing="24px"
>
<Input
type="search"
width={300}
placeholder="Search..."
size="sm"
rounded="sm"
focusBorderColor="green.500"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
2024-08-30 12:07:10 +05:30
<HStack display={"flex"} alignItems={"center"}>
2024-08-28 19:35:39 +05:30
<Button
onClick={() =>
2024-10-18 13:19:23 +05:30
exportToExcelNew(ioNavExport, "Io Nav details")
}
leftIcon={<LuFileSpreadsheet />}
2024-08-28 19:35:39 +05:30
colorScheme="forestGreen"
size={"sm"}
variant={"outline"}
2024-08-28 19:35:39 +05:30
rounded={"sm"}
fontSize={"xs"}
2024-10-18 15:08:38 +05:30
isDisabled={ioNavExport?.length === 0}
2024-08-28 19:35:39 +05:30
>
Export xls
2024-08-28 19:35:39 +05:30
</Button>
{IODetails?.isInvestedAmount ? (
<Button
onClick={onOpen}
leftIcon={<AddIcon />}
colorScheme="forestGreen"
size={"sm"}
rounded={"sm"}
fontSize={"xs"}
>
Add IO Nav
</Button>
) : null}
</HStack>
2024-08-28 19:35:39 +05:30
</HStack>
</Box>
<NormalTable
centered={true}
emptyMessage={`We don't have any Sponers`}
tableHeadRow={tableHeadRow}
data={extractedArray}
isLoading={isLoading}
viewActionId={actionId}
setViewActionId={setActionId}
caption={"Tanami v1.0"}
setMouseEnteredId={setMouseEnteredId}
setMouseEntered={setMouseEntered}
/>
<CustomAlertDialog
onClose={() => setDeleteAlert(false)}
isOpen={deleteAlert}
message={"Are you sure you want to delete sponers?"}
alertHandler={handleDelete}
isLoading={isLoading}
/>
<AddIONav isOpen={isOpen} onClose={onClose} firstField={firstField} />
2024-07-10 12:02:35 +05:30
</Box>
2024-08-28 19:35:39 +05:30
);
};
2024-07-10 12:02:35 +05:30
2024-08-28 19:35:39 +05:30
export default IONAVDetails;