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

225 lines
5.9 KiB
React
Raw Normal View History

2024-08-12 15:35:39 +05:30
import React, { useContext, useEffect, useRef, useState } from 'react'
2024-07-10 12:02:35 +05:30
import GlobalStateContext from '../../../Contexts/GlobalStateContext';
2024-08-12 15:35:39 +05:30
import { Box, HStack, Input,Text, Table, Tbody, Th, Tr, Avatar, useDisclosure,Button } from '@chakra-ui/react';
2024-07-10 12:02:35 +05:30
import { OPACITY_ON_LOAD } from '../../../Layout/animations';
import Pagination from '../../../Components/Pagination';
2024-08-12 15:35:39 +05:30
import NormalTable from '../../../Components/DataTable/NormalTable';
2024-07-10 12:02:35 +05:30
import CustomAlertDialog from '../../../Components/CustomAlertDialog';
2024-08-12 15:35:39 +05:30
import { formatDatee } from '../../../Components/FormField';
import { AddIcon } from '@chakra-ui/icons';
import AddIONav from './AddIONav';
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-12 15:35:39 +05:30
const firstField = useRef();
const { isOpen, onOpen, onClose } = useDisclosure();
2024-07-10 12:02:35 +05:30
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-08-12 15:35:39 +05:30
console.log(IODetails?.ioNAVHistory);
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);
}, []);
// Table setup
const tableHeadRow = [
2024-08-12 15:35:39 +05:30
// "Sr.No",
"Valuation Date",
"NAV",
"Last NAV update",
"Investment Closed",
2024-07-10 12:02:35 +05:30
"Comments",
"Update by ",
2024-08-12 15:35:39 +05:30
// "Update On",
2024-07-10 12:02:35 +05:30
];
// Table filter
2024-08-12 15:35:39 +05:30
const filteredData = IODetails?.ioNAVHistory?.filter((item) => {
const name = item.transactionType;
2024-07-10 12:02:35 +05:30
const searchLower = searchTerm.toLowerCase();
const nameMatches = name.toLowerCase().includes(searchLower);
return nameMatches;
2024-08-16 20:44:13 +05:30
}).sort((b, a) => new Date(a.transactionDate) - new Date(b.transactionDate));
2024-07-10 12:02:35 +05:30
2024-08-12 15:35:39 +05:30
const extractedArray=filteredData?.map((item, index) => ({
2024-07-10 12:02:35 +05:30
id: item?.id,
"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)}
</Text>
),
"NAV": (
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-16 18:29:33 +05:30
{/* {`${item.transactionAmount}`} */}
{`$${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-13 19:58:31 +05:30
{item.initialNAVvalue&& `${item.initialNAVvalue}`}
2024-07-10 12:02:35 +05:30
</Text>
),
"Comments": (
<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"
>
{item.comments}
</Text>
),
"Update by ": (
<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"}
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-08-12 15:35:39 +05:30
<Avatar size='sm' name={"faisal"} src={null} />Faisal
2024-07-10 12:02:35 +05:30
</Text>
),
"Update On": (
<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"
>
{item.updateOn}
</Text>
),
2024-08-12 15:35:39 +05:30
}));
2024-07-10 12:02:35 +05:30
const handleDelete = () => {
const updatedNav = navDetails.filter(
(sponsor) => sponsor.id !== actionId
);
setTimeout(() => {
setNavDetails(updatedNav);
setDeleteAlert(false);
setIsLoading(false);
}, 100);
setIsLoading(true);
};
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-08 19:38:17 +05:30
{/* <HStack display={"flex"} alignItems={"center"}>
2024-07-10 12:02:35 +05:30
<Pagination totalItems={10} />
2024-08-08 19:38:17 +05:30
</HStack> */}
2024-08-12 15:35:39 +05:30
2024-08-22 14:43:57 +05:30
{IODetails?.isInvestedAmount ? <Button onClick={onOpen} leftIcon={<AddIcon/>} colorScheme="forestGreen" size={'sm'} rounded={'sm'} fontSize={'xs'} >Add IO Cash</Button>:null}
2024-08-12 15:35:39 +05:30
2024-07-10 12:02:35 +05:30
</HStack>
</Box>
2024-08-12 15:35:39 +05:30
<NormalTable
2024-07-10 12:02:35 +05:30
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}
/>
2024-08-12 15:35:39 +05:30
<AddIONav
isOpen={isOpen}
onClose={onClose}
firstField={firstField} />
2024-07-10 12:02:35 +05:30
</Box>
2024-07-05 15:28:02 +05:30
)
}
export default IONAVDetails