2024-07-22 14:50:31 +05:30
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Button,
|
|
|
|
|
HStack,
|
|
|
|
|
Input,
|
|
|
|
|
Text,
|
|
|
|
|
Tooltip,
|
|
|
|
|
useDisclosure,
|
|
|
|
|
Image,
|
|
|
|
|
useToast,
|
|
|
|
|
} 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";
|
2024-07-22 14:50:31 +05:30
|
|
|
import {
|
|
|
|
|
AddIcon,
|
|
|
|
|
DeleteIcon,
|
|
|
|
|
DownloadIcon,
|
|
|
|
|
EditIcon,
|
|
|
|
|
ViewIcon,
|
|
|
|
|
} from "@chakra-ui/icons";
|
2024-07-08 12:23:26 +05:30
|
|
|
import KeyMeritsAdd from "../KeyMeritsAdd";
|
2024-07-22 14:50:31 +05:30
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
|
import { useDeleteKeyMeritsMutation, useGetKeyMeritsQuery } from "../../../Services/io.service";
|
|
|
|
|
import FullscreenLoaders from "../../../Components/Loaders/FullscreenLoaders";
|
|
|
|
|
import ToastBox from "../../../Components/ToastBox";
|
|
|
|
|
import KeyMeritsEdit from "../KeyMeritsEdit";
|
|
|
|
|
import SetDisplayOrder from "./SetDisplayOrder";
|
2024-07-05 15:28:02 +05:30
|
|
|
|
2024-07-22 14:50:31 +05:30
|
|
|
const KeyMerits = ({ enableNextTab, index }) => {
|
|
|
|
|
const toast = useToast()
|
|
|
|
|
const params = useParams();
|
|
|
|
|
|
|
|
|
|
// =====================[ variables ]
|
|
|
|
|
const id = params?.id;
|
|
|
|
|
const { data, isLoading, error } = useGetKeyMeritsQuery(id);
|
|
|
|
|
|
|
|
|
|
console.log(data?.data);
|
|
|
|
|
|
|
|
|
|
const { keyMerits, setKeyMerits, slideFromRight } =
|
|
|
|
|
useContext(GlobalStateContext);
|
|
|
|
|
const firstField = useRef();
|
|
|
|
|
const [searchTerm, setSearchTerm] = useState("");
|
|
|
|
|
const [deleteAlert, setDeleteAlert] = useState(false);
|
|
|
|
|
const [actionId, setActionId] = useState(false);
|
|
|
|
|
const [mouseEntered, setMouseEntered] = useState(false);
|
|
|
|
|
const [isBtnLoading, setIsBtnLoading] = useState(false);
|
|
|
|
|
const [mouseEnteredId, setMouseEnteredId] = useState("");
|
|
|
|
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
|
|
|
|
const { isOpen: isEditOpen, onOpen: onEditOpen, onClose: onEditCloseOpen } = useDisclosure();
|
|
|
|
|
const [ deleteKeyMerits ] = useDeleteKeyMeritsMutation()
|
|
|
|
|
|
|
|
|
|
const tableHeadRow = ["Sr.no", "Title", "Sub title", "Icon", "Action"];
|
2024-07-05 20:04:32 +05:30
|
|
|
|
|
|
|
|
const handleUpdateStatus = debounce((id) => {
|
|
|
|
|
setKeyMerits((prevKeyMerits) =>
|
|
|
|
|
prevKeyMerits.map((keyMerits) =>
|
2024-07-22 14:50:31 +05:30
|
|
|
keyMerits.id === id
|
|
|
|
|
? { ...keyMerits, status: !keyMerits.status }
|
|
|
|
|
: keyMerits
|
2024-07-05 20:04:32 +05:30
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
toast({
|
|
|
|
|
render: () => <ToastBox message={"Status changed succesfully.!"} />,
|
|
|
|
|
});
|
|
|
|
|
}, 300);
|
|
|
|
|
|
2024-07-22 14:50:31 +05:30
|
|
|
const filteredData = data?.data?.filter((item) => {
|
2024-07-05 20:04:32 +05:30
|
|
|
// Filter by name (case insensitive)
|
2024-07-22 14:50:31 +05:30
|
|
|
const name = item.meritsHeader;
|
2024-07-05 20:04:32 +05:30
|
|
|
const searchLower = searchTerm.toLowerCase();
|
|
|
|
|
const nameMatches = name.toLowerCase().includes(searchLower);
|
|
|
|
|
|
|
|
|
|
return nameMatches;
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-22 14:50:31 +05:30
|
|
|
const handleDelete = async () => {
|
|
|
|
|
setIsBtnLoading(true)
|
|
|
|
|
try {
|
|
|
|
|
const res = await deleteKeyMerits(actionId)
|
|
|
|
|
if(res?.data?.statusCode === 200){
|
|
|
|
|
toast({
|
|
|
|
|
render: () => <ToastBox message={res?.data?.message} />,
|
|
|
|
|
});
|
|
|
|
|
setIsBtnLoading(false)
|
|
|
|
|
setDeleteAlert(false)
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
|
|
}
|
2024-07-05 20:04:32 +05:30
|
|
|
};
|
|
|
|
|
|
2024-07-22 14:50:31 +05:30
|
|
|
const extractedArray = filteredData?.map((item, index) => ({
|
2024-07-08 12:22:27 +05:30
|
|
|
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>
|
|
|
|
|
),
|
2024-07-22 14:50:31 +05:30
|
|
|
Title: (
|
2024-07-05 20:04:32 +05:30
|
|
|
<Text
|
|
|
|
|
justifyContent={slideFromRight ? "right" : "left"}
|
|
|
|
|
as={"span"}
|
|
|
|
|
color={"teal.900"}
|
|
|
|
|
fontWeight={"500"}
|
|
|
|
|
className="d-flex align-items-center web-text-small"
|
|
|
|
|
>
|
2024-07-22 14:50:31 +05:30
|
|
|
{item.meritsHeader}
|
2024-07-05 20:04:32 +05:30
|
|
|
</Text>
|
|
|
|
|
),
|
|
|
|
|
"Sub title": (
|
|
|
|
|
<Box w={"300px"} isTruncated={true}>
|
|
|
|
|
<Text as={"span"} color={"teal.900"} fontWeight={"500"}>
|
2024-07-22 14:50:31 +05:30
|
|
|
{item.meritsDescription}
|
2024-07-05 20:04:32 +05:30
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
),
|
2024-07-22 14:50:31 +05:30
|
|
|
Icon: (
|
2024-07-23 16:31:21 +05:30
|
|
|
item.iconFilePath && <Image
|
|
|
|
|
rounded={'md'}
|
|
|
|
|
bg={"#003B14"}
|
|
|
|
|
display={'flex'}
|
|
|
|
|
p={1}
|
|
|
|
|
justifyContent={'center'}
|
|
|
|
|
alignItems={'center'}
|
|
|
|
|
src={" https://admin.tanami.betadelivery.com/"+item.iconFilePath}
|
2024-07-22 14:50:31 +05:30
|
|
|
w={8}
|
|
|
|
|
h={8}
|
|
|
|
|
/>
|
2024-07-23 16:31:21 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-07-22 14:50:31 +05:30
|
|
|
// https://admin.tanami.betadelivery.com/public/icons/linkedin.png
|
2024-07-05 20:04:32 +05:30
|
|
|
),
|
|
|
|
|
Action: (
|
2024-07-22 14:50:31 +05:30
|
|
|
<Box display={"flex"} justifyContent={"center"} gap={2}>
|
|
|
|
|
{/* <Tooltip
|
2024-07-05 20:04:32 +05:30
|
|
|
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-22 14:50:31 +05:30
|
|
|
<ViewIcon />
|
2024-07-05 20:04:32 +05:30
|
|
|
</Button>
|
2024-07-22 14:50:31 +05:30
|
|
|
</Tooltip> */}
|
2024-07-05 20:04:32 +05:30
|
|
|
<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"}
|
2024-07-22 14:50:31 +05:30
|
|
|
onClick={() => {
|
|
|
|
|
setActionId(item?.id);
|
|
|
|
|
onEditOpen();
|
|
|
|
|
}}
|
2024-07-05 20:04:32 +05:30
|
|
|
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-22 14:50:31 +05:30
|
|
|
}));
|
2024-07-05 20:04:32 +05:30
|
|
|
|
2024-07-22 14:50:31 +05:30
|
|
|
return isLoading ? (
|
|
|
|
|
<FullscreenLoaders />
|
|
|
|
|
) : (
|
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)}
|
|
|
|
|
/>
|
2024-07-22 14:50:31 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
<Box display={'flex'} gap={2} as="span">
|
|
|
|
|
<SetDisplayOrder data={filteredData} />
|
2024-07-05 20:04:32 +05:30
|
|
|
<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-22 14:50:31 +05:30
|
|
|
colorScheme="forestGreen"
|
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-22 14:50:31 +05:30
|
|
|
</Box>
|
2024-07-08 12:23:26 +05:30
|
|
|
<KeyMeritsAdd
|
2024-07-22 14:50:31 +05:30
|
|
|
id={id}
|
2024-07-05 20:04:32 +05:30
|
|
|
isOpen={isOpen}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
firstField={firstField}
|
|
|
|
|
/>
|
2024-07-22 14:50:31 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<KeyMeritsEdit
|
|
|
|
|
id={id}
|
|
|
|
|
actionId={actionId}
|
|
|
|
|
isOpen={isEditOpen}
|
|
|
|
|
onClose={onEditCloseOpen}
|
|
|
|
|
firstField={firstField}
|
|
|
|
|
data={data?.data}
|
|
|
|
|
/>
|
2024-07-05 20:04:32 +05:30
|
|
|
</Box>
|
|
|
|
|
<DataTable
|
|
|
|
|
emptyMessage={`We don't have any Sponers `}
|
|
|
|
|
tableHeadRow={tableHeadRow}
|
|
|
|
|
data={extractedArray}
|
2024-07-22 14:50:31 +05:30
|
|
|
// setData={setExtractedArray}
|
|
|
|
|
isLoading={false}
|
2024-07-05 20:04:32 +05:30
|
|
|
viewActionId={actionId}
|
|
|
|
|
setViewActionId={setActionId}
|
|
|
|
|
// totalPages={10}
|
|
|
|
|
|
|
|
|
|
setMouseEnteredId={setMouseEnteredId}
|
|
|
|
|
setMouseEntered={setMouseEntered}
|
|
|
|
|
/>
|
2024-07-22 14:50:31 +05:30
|
|
|
|
|
|
|
|
<HStack justifyContent={"flex-end"}>
|
|
|
|
|
<Button
|
|
|
|
|
ps={8}
|
|
|
|
|
pe={8}
|
|
|
|
|
colorScheme="forestGreen"
|
|
|
|
|
size={"sm"}
|
|
|
|
|
rounded={"sm"}
|
|
|
|
|
onClick={() => enableNextTab(index)}
|
|
|
|
|
>
|
|
|
|
|
Next
|
|
|
|
|
</Button>
|
2024-07-08 12:22:27 +05:30
|
|
|
</HStack>
|
2024-07-05 20:04:32 +05:30
|
|
|
<CustomAlertDialog
|
|
|
|
|
onClose={() => setDeleteAlert(false)}
|
|
|
|
|
isOpen={deleteAlert}
|
2024-07-22 14:50:31 +05:30
|
|
|
message={"Are you sure you want to delete key merit?"}
|
2024-07-05 20:04:32 +05:30
|
|
|
alertHandler={handleDelete}
|
2024-07-22 14:50:31 +05:30
|
|
|
isLoading={isBtnLoading}
|
2024-07-05 20:04:32 +05:30
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
2024-07-05 15:28:02 +05:30
|
|
|
|
2024-07-05 20:04:32 +05:30
|
|
|
export default KeyMerits;
|