Files
tanami-admin-panel/src/Pages/IO_Management/ViewIO/ViewIOTable.jsx

319 lines
8.2 KiB
React
Raw Normal View History

2024-07-05 11:55:52 +05:30
import {
Avatar,
Badge,
Box,
Button,
HStack,
Input,
Menu,
MenuButton,
MenuItem,
MenuList,
Portal,
Select,
Switch,
Tag,
Text,
Tooltip,
useToast,
} from "@chakra-ui/react";
import React, { useContext, useEffect, useState } from "react";
2024-07-05 20:02:10 +05:30
import { OPACITY_ON_LOAD } from "../../../Layout/animations";
import DataTable from "../../../Components/DataTable/DataTable";
2024-07-05 11:55:52 +05:30
import { HiDotsVertical } from "react-icons/hi";
import { Link, Link as RouterLink, useNavigate } from "react-router-dom";
import {
AddIcon,
CheckIcon,
CloseIcon,
DeleteIcon,
EditIcon,
EmailIcon,
ViewIcon,
} from "@chakra-ui/icons";
2024-07-05 20:02:10 +05:30
import Pagination from "../../../Components/Pagination";
import GlobalStateContext from "../../../Contexts/GlobalStateContext";
import CustomAlertDialog from "../../../Components/CustomAlertDialog";
import ToastBox from "../../../Components/ToastBox";
2024-07-05 11:55:52 +05:30
// import { debounce } from "./AddIOCharges";
const formatDate = (date) => new Date(date).toLocaleDateString(); // Simple date formatter
const ViewIOTable = () => {
const navigate = useNavigate();
const toast = useToast();
2024-07-09 14:49:05 +05:30
const { IODetails, setIODetails, slideFromRight } = useContext(GlobalStateContext);
2024-07-05 11:55:52 +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-07-05 20:02:10 +05:30
2024-07-05 11:55:52 +05:30
useEffect(() => {
// Simulate loading
const timer = setTimeout(() => {
setIsLoading(false);
}, 1500);
// Cleanup the timer on component unmount
return () => clearTimeout(timer);
}, []);
// ====================================================[Table Setup]================================================================
const tableHeadRow = [
"Sr.no",
"Deal ID",
2024-07-09 14:49:05 +05:30
"Sponser Name",
"Investment Type",
2024-07-05 11:55:52 +05:30
"IO status",
"Action",
];
// const handleUpdateStatus = debounce((id) => {
// setInvestmentType((prevInvestmentType) =>
// prevInvestmentType.map((investmentType) =>
// investmentType.id === id
// ? { ...investmentType, status: !investmentType.status }
// : investmentType
// )
// );
// toast({
// render: () => <ToastBox message={"Status changed succesfully.!"} />,
// });
// }, 300);
// ====================================================[Table Filter]================================================================
2024-07-09 14:49:05 +05:30
const filteredData = IODetails.filter((item) => {
2024-07-05 11:55:52 +05:30
// Filter by name (case insensitive)
2024-07-09 14:49:05 +05:30
const name = item.ioName;
2024-07-05 11:55:52 +05:30
const searchLower = searchTerm.toLowerCase();
const nameMatches = name.toLowerCase().includes(searchLower);
// Filter by status
// const status = item.status;
// const statusLower = status ? "active" : "inactive";
// const statusMatches =
// statusFilter === "all" ||
// (statusFilter === "active" && status === true) ||
// (statusFilter === "inactive" && status === false);
return nameMatches;
});
const extractedArray = filteredData?.map((item, index) => ({
"Sr.no": (
<Text
justifyContent={slideFromRight ? "right" : "left"}
as={"span"}
color={"teal.900"}
fontWeight={"500"}
className="d-flex align-items-center web-text-small"
>
{index + 1}
</Text>
),
"Deal ID": (
<Text
justifyContent={slideFromRight ? "right" : "left"}
as={"span"}
color={"teal.900"}
fontWeight={"500"}
className="d-flex align-items-center web-text-small"
>
2024-07-09 14:49:05 +05:30
{item.id}
2024-07-05 11:55:52 +05:30
</Text>
),
2024-07-09 14:49:05 +05:30
"Sponser Name": (
2024-07-05 11:55:52 +05:30
<Box w={"auto"} isTruncated={true}>
<Text as={"span"} color={"teal.900"} fontWeight={"500"}>
2024-07-09 14:49:05 +05:30
{item.sponserName}
2024-07-05 11:55:52 +05:30
</Text>
</Box>
),
2024-07-09 14:49:05 +05:30
"Investment Type": (
2024-07-05 11:55:52 +05:30
<Box w={"auto"} isTruncated={true}>
<Text as={"span"} color={"teal.900"} fontWeight={"500"}>
2024-07-09 14:49:05 +05:30
{item.typeName}
2024-07-05 11:55:52 +05:30
</Text>
</Box>
),
"IO status": (
<Box w={"auto"} isTruncated={true}>
<Badge
color={
2024-07-09 14:49:05 +05:30
item.ioStatus === "open"
2024-07-05 11:55:52 +05:30
? "#00B69B"
2024-07-09 14:49:05 +05:30
: item.ioStatus === "pending"
2024-07-05 11:55:52 +05:30
? "#6226EF"
: "#EF3826"
}
colorScheme={
2024-07-09 14:49:05 +05:30
item.ioStatus === "open"
2024-07-05 11:55:52 +05:30
? "green"
2024-07-09 14:49:05 +05:30
: item.ioStatus === "pending"
2024-07-05 11:55:52 +05:30
? "purple"
: "red"
}
>
2024-07-09 14:49:05 +05:30
{item.ioStatus}
2024-07-05 11:55:52 +05:30
</Badge>
</Box>
),
Action: (
<Box display={"flex"} justifyContent={"space-evenly"}>
<Tooltip
rounded={"sm"}
fontSize={"xs"}
label="View"
bg="#fff"
color={"green.500"}
placement="top"
>
<Button
_hover={{ color: "green.500" }}
// transition={"0.5s all"}
onClick={() => {
navigate(`/view-io/${item.id}`);
}}
color="green.300"
rounded={"sm"}
size={"xs"}
>
<ViewIcon />
</Button>
</Tooltip>
2024-07-09 14:49:05 +05:30
<Tooltip
rounded={"sm"}
fontSize={"xs"}
label="View"
bg="#fff"
color={"green.500"}
placement="top"
>
<Button
_hover={{ color: "green.500" }}
// transition={"0.5s all"}
onClick={() => {
navigate(`/create-io/${item.id}`);
}}
color="green.300"
rounded={"sm"}
size={"xs"}
>
<EditIcon />
</Button>
</Tooltip>
2024-07-05 11:55:52 +05:30
<Tooltip
rounded={"sm"}
fontSize={"xs"}
label="Delete"
bg="#fff"
color={"red.500"}
placement="top"
>
<Button
onClick={() => {
setActionId(item?.id);
setDeleteAlert(true);
}}
_hover={{ color: "red.500" }}
// transition={"0.5s all"}
color="red.300"
rounded={"sm"}
size={"xs"}
>
<DeleteIcon />
</Button>
</Tooltip>
</Box>
),
}));
const handleDelete = () => {
2024-07-09 14:49:05 +05:30
const upDatedIO = IODetails.filter((viewIO) => viewIO.id !== actionId);
2024-07-05 11:55:52 +05:30
setTimeout(() => {
2024-07-09 14:49:05 +05:30
setIODetails(upDatedIO);
2024-07-05 11:55:52 +05:30
setDeleteAlert(false);
setIsLoading(false);
}, 100);
setIsLoading(true);
};
return (
<Box {...OPACITY_ON_LOAD} overflowY={"scroll"} height={"100vh"} pb={38}>
<Box bg="white.500">
<HStack
display={"flex"}
justifyContent={"space-between"}
ps={1}
pe={1}
pb={4}
pt={4}
spacing="24px"
>
<Input
type="search"
width={300}
placeholder="Search..."
size="sm"
rounded="sm"
focusBorderColor="green.500"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
<HStack display={"flex"} alignItems={"center"}>
<Pagination totalItems={10} />
2024-07-09 14:49:05 +05:30
<Link to={"/create-io"}>
2024-07-05 11:55:52 +05:30
<Button
2024-07-09 14:49:05 +05:30
ps={4}
pe={4}
2024-07-05 11:55:52 +05:30
leftIcon={<AddIcon />}
colorScheme={"green"}
rounded={"sm"}
size={"sm"}
2024-07-09 14:49:05 +05:30
fontSize={'sm'}
2024-07-05 11:55:52 +05:30
>
2024-07-09 14:49:05 +05:30
Create IO
2024-07-05 11:55:52 +05:30
</Button>
2024-07-09 14:49:05 +05:30
</Link>
2024-07-05 11:55:52 +05:30
</HStack>
</HStack>
</Box>
<DataTable
emptyMessage={`We don't have any Sponers `}
tableHeadRow={tableHeadRow}
data={extractedArray}
isLoading={isLoading}
viewActionId={actionId}
setViewActionId={setActionId}
// totalPages={10}
setMouseEnteredId={setMouseEnteredId}
setMouseEntered={setMouseEntered}
/>
<CustomAlertDialog
onClose={() => setDeleteAlert(false)}
isOpen={deleteAlert}
message={"Are you sure you want to delete sponers?"}
alertHandler={handleDelete}
isLoading={isLoading}
/>
</Box>
);
};
export default ViewIOTable;