2024-07-08 12:22:27 +05:30
|
|
|
import { Box, Button, HStack, Input, Text, Tooltip, useDisclosure } from "@chakra-ui/react";
|
2024-07-05 20:04:32 +05:30
|
|
|
import React, { useContext, useEffect, useRef, useState } from "react";
|
|
|
|
|
import InvestmentDocuments from "../InvestmentDocuments";
|
|
|
|
|
import DataTable from "../../../Components/DataTable/DataTable";
|
|
|
|
|
import CustomAlertDialog from "../../../Components/CustomAlertDialog";
|
|
|
|
|
import GlobalStateContext from "../../../Contexts/GlobalStateContext";
|
|
|
|
|
import { debounce } from "../../Master/Sponser/AddSponser";
|
|
|
|
|
import { formatDate } from "../../../Components/Functions/UTCConvertor";
|
|
|
|
|
import { AddIcon, DeleteIcon, DownloadIcon, EditIcon, ViewIcon } from "@chakra-ui/icons";
|
2024-07-08 12:23:26 +05:30
|
|
|
import KeyMeritsAdd from "../KeyMeritsAdd";
|
2024-07-05 15:28:02 +05:30
|
|
|
|
2024-07-08 12:22:27 +05:30
|
|
|
const KeyMerits = ({enableNextTab, index}) => {
|
2024-07-05 20:04:32 +05:30
|
|
|
const { keyMerits, setKeyMerits,slideFromRight} =
|
|
|
|
|
useContext(GlobalStateContext);
|
|
|
|
|
const firstField = useRef();
|
|
|
|
|
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("");
|
|
|
|
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
2024-07-08 20:39:43 +05:30
|
|
|
|
2024-07-05 20:04:32 +05:30
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// Simulate loading
|
|
|
|
|
const timer = setTimeout(() => {
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
}, 1500);
|
|
|
|
|
|
|
|
|
|
// Cleanup the timer on component unmount
|
|
|
|
|
return () => clearTimeout(timer);
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tableHeadRow = [
|
|
|
|
|
"Sr.no",
|
|
|
|
|
"Title",
|
|
|
|
|
"Sub title",
|
|
|
|
|
"Icon",
|
|
|
|
|
"Action",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const handleUpdateStatus = debounce((id) => {
|
|
|
|
|
setKeyMerits((prevKeyMerits) =>
|
|
|
|
|
prevKeyMerits.map((keyMerits) =>
|
|
|
|
|
keyMerits.id === id ? { ...keyMerits, status: !keyMerits.status } : keyMerits
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
toast({
|
|
|
|
|
render: () => <ToastBox message={"Status changed succesfully.!"} />,
|
|
|
|
|
});
|
|
|
|
|
}, 300);
|
|
|
|
|
|
|
|
|
|
const filteredData = keyMerits?.filter((item) => {
|
|
|
|
|
// Filter by name (case insensitive)
|
|
|
|
|
const name = item.title;
|
|
|
|
|
const searchLower = searchTerm.toLowerCase();
|
|
|
|
|
const nameMatches = name.toLowerCase().includes(searchLower);
|
|
|
|
|
|
|
|
|
|
return nameMatches;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const handleDelete = () => {
|
|
|
|
|
const updatedKeyMerits = keyMerits.filter((keyMerits) => keyMerits.id !== actionId);
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
setSponser(updatedKeyMerits);
|
|
|
|
|
setDeleteAlert(false);
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
}, 100);
|
|
|
|
|
setIsLoading(true);
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-08 12:22:27 +05:30
|
|
|
const [ extractedArray, setExtractedArray ] = useState(filteredData?.map((item, index) => ({
|
|
|
|
|
id: item.id,
|
2024-07-05 20:04:32 +05:30
|
|
|
"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>
|
|
|
|
|
),
|
|
|
|
|
"Title": (
|
|
|
|
|
<Text
|
|
|
|
|
justifyContent={slideFromRight ? "right" : "left"}
|
|
|
|
|
as={"span"}
|
|
|
|
|
color={"teal.900"}
|
|
|
|
|
fontWeight={"500"}
|
|
|
|
|
className="d-flex align-items-center web-text-small"
|
|
|
|
|
>
|
|
|
|
|
{item.title}
|
|
|
|
|
</Text>
|
|
|
|
|
),
|
|
|
|
|
"Sub title": (
|
|
|
|
|
<Box w={"300px"} isTruncated={true}>
|
|
|
|
|
<Text as={"span"} color={"teal.900"} fontWeight={"500"}>
|
|
|
|
|
{item.subTitle}
|
|
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
),
|
|
|
|
|
"Icon": (
|
|
|
|
|
<Text
|
|
|
|
|
color={'green.500'}
|
|
|
|
|
justifyContent={slideFromRight ? "right" : "left"}
|
|
|
|
|
as={"span"}
|
|
|
|
|
fontWeight={"500"}
|
|
|
|
|
className="d-flex align-items-center web-text-small"
|
|
|
|
|
>
|
|
|
|
|
{item.icon}
|
|
|
|
|
</Text>
|
|
|
|
|
),
|
|
|
|
|
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-investment/${item.id}`);
|
|
|
|
|
}}
|
|
|
|
|
color="green.300"
|
|
|
|
|
rounded={"sm"}
|
|
|
|
|
size={"xs"}
|
|
|
|
|
>
|
2024-07-08 12:23:26 +05:30
|
|
|
<ViewIcon />
|
2024-07-05 20:04:32 +05:30
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
<Tooltip
|
|
|
|
|
rounded={"sm"}
|
|
|
|
|
fontSize={"xs"}
|
|
|
|
|
label="Edit"
|
|
|
|
|
bg="#fff"
|
|
|
|
|
color={"blue.500"}
|
|
|
|
|
placement="top"
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
_hover={{ color: "blue.500" }}
|
|
|
|
|
// transition={"0.5s all"}
|
|
|
|
|
color="blue.400"
|
|
|
|
|
rounded={"sm"}
|
|
|
|
|
size={"xs"}
|
|
|
|
|
>
|
|
|
|
|
<EditIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
<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>
|
|
|
|
|
),
|
2024-07-08 12:22:27 +05:30
|
|
|
})));
|
2024-07-05 20:04:32 +05:30
|
|
|
|
|
|
|
|
|
2024-07-05 15:28:02 +05:30
|
|
|
return (
|
2024-07-05 20:04:32 +05:30
|
|
|
<Box>
|
|
|
|
|
<Box display={"flex"} justifyContent={"space-between"} mb={4}>
|
|
|
|
|
<Input
|
|
|
|
|
type="search"
|
|
|
|
|
width={300}
|
|
|
|
|
placeholder="Search..."
|
|
|
|
|
size="sm"
|
|
|
|
|
rounded="sm"
|
|
|
|
|
focusBorderColor="green.500"
|
|
|
|
|
value={searchTerm}
|
|
|
|
|
onChange={(e) => setSearchTerm(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
leftIcon={<AddIcon />}
|
|
|
|
|
onClick={onOpen}
|
2024-07-08 12:22:27 +05:30
|
|
|
size={"sm"}
|
2024-07-05 20:04:32 +05:30
|
|
|
// width={"44.5%"}
|
|
|
|
|
fontSize={"xs"}
|
|
|
|
|
rounded={"sm"}
|
|
|
|
|
|
2024-07-09 14:49:05 +05:30
|
|
|
// colorScheme="green"
|
|
|
|
|
color={'green'}
|
2024-07-05 20:04:32 +05:30
|
|
|
>
|
2024-07-09 14:49:05 +05:30
|
|
|
Add key merits
|
2024-07-05 20:04:32 +05:30
|
|
|
</Button>
|
2024-07-08 12:23:26 +05:30
|
|
|
<KeyMeritsAdd
|
2024-07-05 20:04:32 +05:30
|
|
|
isOpen={isOpen}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
firstField={firstField}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
<DataTable
|
|
|
|
|
emptyMessage={`We don't have any Sponers `}
|
|
|
|
|
tableHeadRow={tableHeadRow}
|
|
|
|
|
data={extractedArray}
|
2024-07-08 12:22:27 +05:30
|
|
|
setData={setExtractedArray}
|
2024-07-05 20:04:32 +05:30
|
|
|
isLoading={isLoading}
|
|
|
|
|
viewActionId={actionId}
|
|
|
|
|
setViewActionId={setActionId}
|
|
|
|
|
// totalPages={10}
|
|
|
|
|
|
|
|
|
|
setMouseEnteredId={setMouseEnteredId}
|
|
|
|
|
setMouseEntered={setMouseEntered}
|
|
|
|
|
/>
|
2024-07-08 12:22:27 +05:30
|
|
|
|
|
|
|
|
<HStack justifyContent={'flex-end'}>
|
|
|
|
|
<Button ps={8} pe={8} colorScheme="green" size={'sm'} rounded={'sm'} onClick={()=> enableNextTab(index)}>Next</Button>
|
|
|
|
|
</HStack>
|
2024-07-05 20:04:32 +05:30
|
|
|
<CustomAlertDialog
|
|
|
|
|
onClose={() => setDeleteAlert(false)}
|
|
|
|
|
isOpen={deleteAlert}
|
|
|
|
|
message={"Are you sure you want to delete sponers?"}
|
|
|
|
|
alertHandler={handleDelete}
|
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
2024-07-05 15:28:02 +05:30
|
|
|
|
2024-07-05 20:04:32 +05:30
|
|
|
export default KeyMerits;
|