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

396 lines
10 KiB
React
Raw Normal View History

2024-07-08 20:39:43 +05:30
import {
2024-08-12 12:22:01 +05:30
Avatar,
2024-08-28 19:35:39 +05:30
Badge,
2024-07-08 20:39:43 +05:30
Box,
Button,
HStack,
Input,
Table,
Tag,
Tbody,
Text,
Th,
2024-11-14 12:08:17 +05:30
Tooltip,
2024-07-08 20:39:43 +05:30
Tr,
2024-08-07 20:18:36 +05:30
useDisclosure,
2024-07-08 20:39:43 +05:30
useToast,
} from "@chakra-ui/react";
2024-08-07 20:18:36 +05:30
import React, { useContext, useEffect, useRef, useState } from "react";
2024-11-14 12:08:17 +05:30
import {
AddIcon,
CheckIcon,
CloseIcon,
DeleteIcon,
EditIcon,
ViewIcon,
} from "@chakra-ui/icons";
2024-08-30 16:09:07 +05:30
import { LuFileSpreadsheet } from "react-icons/lu";
2024-11-14 12:08:17 +05:30
import { OPACITY_ON_LOAD } from "../../../../Layout/animations";
import NormalTable from "../../../../Components/DataTable/NormalTable";
import GlobalStateContext from "../../../../Contexts/GlobalStateContext";
import CustomAlertDialog from "../../../../Components/CustomAlertDialog";
import ToastBox from "../../../../Components/ToastBox";
import AddCashDetails from "../AddCashDetails";
import { debounce } from "../../../Admin/Contact";
import AddPending from "./AddPending";
2024-11-14 16:04:20 +05:30
import { useParams } from "react-router-dom";
import { useUpdateIOCaseMutation } from "../../../../Services/io.service";
2024-07-08 20:39:43 +05:30
2024-11-14 12:08:17 +05:30
const formatDate = (date) => new Date(date).toLocaleDateString();
2024-07-05 15:28:02 +05:30
2024-11-14 12:08:17 +05:30
const Pending = () => {
2024-07-08 20:39:43 +05:30
const toast = useToast();
2024-11-14 16:04:20 +05:30
const params = useParams()
const id = params?.id
2024-08-07 20:18:36 +05:30
const firstField = useRef();
const { isOpen, onOpen, onClose } = useDisclosure();
2024-11-14 12:08:17 +05:30
const { IODetails, approved, setApproved } =
2024-08-28 19:35:39 +05:30
useContext(GlobalStateContext);
2024-07-08 20:39:43 +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-11-14 16:04:20 +05:30
const [updateIOCase] = useUpdateIOCaseMutation()
2024-07-08 20:39:43 +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
const formatDate = (date) => {
return new Date(date).toLocaleDateString("en-GB", {
day: "2-digit",
month: "2-digit",
year: "numeric",
});
};
2024-11-14 12:08:17 +05:30
// Table filter
const filteredData = IODetails?.ioCashStatusHistory?.Pending?.filter((item) => {
// Filter by name (case insensitive)
const name = item.transactionDate;
const searchLower = searchTerm.toLowerCase();
const nameMatches = name.toLowerCase().includes(searchLower);
return nameMatches;
});
2024-07-08 20:39:43 +05:30
const tableHeadRow = [
2024-11-14 12:08:17 +05:30
"Sr No.",
"Transaction date",
2024-07-08 20:39:43 +05:30
"Amount",
"Comments",
2024-11-14 12:08:17 +05:30
"Update by",
2024-07-08 20:39:43 +05:30
"Update On",
2024-11-14 12:08:17 +05:30
"Status",
2024-07-08 20:39:43 +05:30
];
2024-08-12 12:22:01 +05:30
const extractedArray = filteredData?.map((item, index) => ({
2024-07-08 20:39:43 +05:30
id: item?.id,
2024-11-14 12:08:17 +05:30
"Sr No.": (
<Text as={"span"} color={"gray.800"} fontWeight={"500"}>
{index + 1}.
2024-07-08 20:39:43 +05:30
</Text>
),
2024-11-14 12:08:17 +05:30
"Transaction date": (
<Text as={"span"} color={"gray.600"} fontWeight={"500"}>
{formatDate(item?.transactionDate)}
2024-07-08 20:39:43 +05:30
</Text>
),
2024-08-28 19:35:39 +05:30
Amount: (
2024-11-14 12:08:17 +05:30
<Text as={"span"} color={"gray.800"} fontWeight={"500"}>
2024-08-28 19:35:39 +05:30
<Badge ms={1} colorScheme="green" me={1}>
$
</Badge>
2024-11-14 12:08:17 +05:30
{item?.transactionAmount}
2024-07-08 20:39:43 +05:30
</Text>
),
2024-08-28 19:35:39 +05:30
Comments: (
2024-11-14 12:08:17 +05:30
<Text w={"100px"} as={"span"} color={"gray.800"} fontWeight={"500"}>
{item?.comments}
2024-07-08 20:39:43 +05:30
</Text>
),
2024-11-14 12:08:17 +05:30
"Update by": (
2024-07-08 20:39:43 +05:30
<Text
2024-11-14 12:08:17 +05:30
w={"100px"}
2024-07-08 20:39:43 +05:30
as={"span"}
2024-11-14 12:08:17 +05:30
color={"gray.800"}
2024-07-08 20:39:43 +05:30
fontWeight={"500"}
2024-11-14 12:08:17 +05:30
display={"flex"}
alignItems={"center"}
2024-07-08 20:39:43 +05:30
>
2024-08-28 19:35:39 +05:30
<Avatar
2024-11-14 12:08:17 +05:30
mr={2}
2024-08-28 19:35:39 +05:30
size="sm"
name={item.creator?.firstName}
src={item.creator?.profilePhoto}
/>
2024-11-14 12:08:17 +05:30
{item?.creator?.firstName}
2024-07-08 20:39:43 +05:30
</Text>
),
"Update On": (
2024-11-14 12:08:17 +05:30
<Text w={"100px"} as={"span"} color={"gray.800"} fontWeight={"500"}>
2024-10-18 13:19:23 +05:30
{formatDate(item.updatedAt)}
2024-07-08 20:39:43 +05:30
</Text>
),
2024-11-14 12:08:17 +05:30
Status: (
<Box display={"flex"} justifyContent={"center"} gap={2}>
<Tooltip
rounded={"sm"}
fontSize={"xs"}
label="Approve"
bg="#fff"
color={"green.500"}
placement="left-start"
>
<Button
// colorScheme="forestGreen"
// color="green.500"
rounded={"sm"}
size={"xs"}
textTransform={"inherit"}
fontWeight={500}
px={2}
py={1}
onClick={() => {
setActionId(item.id);
onConfirmOpen();
}}
colorScheme="green"
variant={"solid"}
cursor={"pointer"}
>
<CheckIcon fontSize={"12px"} />
</Button>
</Tooltip>
<Tooltip
rounded={"sm"}
fontSize={"xs"}
label="Reject"
bg="#fff"
color={"red.500"}
placement="left-start"
>
<Button
colorScheme="red"
// color="red.500"
rounded={"sm"}
size={"xs"}
textTransform={"inherit"}
fontWeight={500}
px={2}
onClick={() => {
setActionId(item.id);
onRejectOpen();
}}
py={1}
// variant={"solid"}
>
<CloseIcon fontSize={"10px"} />
</Button>
</Tooltip>
</Box>
),
2024-08-12 12:22:01 +05:30
}));
2024-07-08 20:39:43 +05:30
const handleDelete = () => {
const updatedSponsors = sponser.filter(
(sponsor) => sponsor.id !== actionId
);
setTimeout(() => {
setCaseDetails(updatedSponsors);
setDeleteAlert(false);
setIsLoading(false);
}, 100);
setIsLoading(true);
};
const Total = () => {
return (
<Table size="sm">
<Tbody backgroundColor="gray.50">
2024-08-28 19:35:39 +05:30
<Tr>
2024-07-08 20:39:43 +05:30
<Th
textAlign={"center"}
p={3}
2024-11-14 12:08:17 +05:30
width="130px"
2024-07-08 20:39:43 +05:30
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
>
2024-11-14 12:08:17 +05:30
Balance in IO Cash
2024-07-08 20:39:43 +05:30
</Th>
<Th
textAlign={"center"}
p={3}
2024-11-14 12:08:17 +05:30
width="150px"
2024-07-08 20:39:43 +05:30
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
>
{" "}
</Th>
<Th
textAlign={"center"}
p={3}
2024-11-14 12:08:17 +05:30
width="150px"
2024-07-08 20:39:43 +05:30
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
>
2024-11-14 12:08:17 +05:30
{}
2024-07-08 20:39:43 +05:30
</Th>
<Th
textAlign={"center"}
p={3}
2024-11-14 12:08:17 +05:30
width="100px"
2024-07-08 20:39:43 +05:30
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
>
2024-11-14 12:08:17 +05:30
{"48,000.00"}
2024-07-08 20:39:43 +05:30
</Th>
<Th
textAlign={"center"}
p={3}
width="100px"
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
>
{" "}
</Th>
<Th
textAlign={"center"}
p={3}
width="100px"
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
2024-11-14 12:08:17 +05:30
></Th>
<Th
textAlign={"center"}
p={3}
width="80px"
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
></Th>
<Th
textAlign={"center"}
p={3}
width="50px"
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
></Th>
2024-07-08 20:39:43 +05:30
</Tr>
</Tbody>
</Table>
);
};
2024-11-14 16:04:20 +05:30
const handleAdd = async () =>{
try {
const res = await updateIOCase(id)
if (res?.data) {
toast({
render: () => (
<ToastBox status={"success"} message={res?.data?.message} />
),
});
setIsLoading(false);
onOpen()
} else if (res?.error) {
toast({
render: () => (
<ToastBox status={"error"} message={res?.error?.data?.message} />
),
});
setIsLoading(false);
}
} catch (error) {
}
}
2024-07-05 15:28:02 +05:30
return (
2024-07-08 20:39:43 +05:30
<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-11-14 12:08:17 +05:30
<HStack display={"flex"} alignItems={"center"}>
2024-08-28 19:35:39 +05:30
<Button
2024-11-14 16:04:20 +05:30
onClick={handleAdd}
2024-08-28 19:35:39 +05:30
leftIcon={<AddIcon />}
2024-11-14 12:08:17 +05:30
colorScheme={"forestGreen"}
2024-08-28 19:35:39 +05:30
rounded={"sm"}
fontSize={"xs"}
2024-11-14 12:08:17 +05:30
size={"sm"}
fontWeight={500}
2024-08-28 19:35:39 +05:30
>
2024-11-14 12:08:17 +05:30
Add
2024-08-28 19:35:39 +05:30
</Button>
2024-11-14 12:08:17 +05:30
</HStack>
2024-08-30 16:09:07 +05:30
</HStack>
2024-07-08 20:39:43 +05:30
</Box>
2024-08-12 12:22:01 +05:30
<NormalTable
2024-07-08 20:39:43 +05:30
emptyMessage={`We don't have any Sponers`}
tableHeadRow={tableHeadRow}
2024-08-28 19:35:39 +05:30
data={extractedArray}
2024-07-08 20:39:43 +05:30
isLoading={isLoading}
viewActionId={actionId}
setViewActionId={setActionId}
2024-11-14 12:08:17 +05:30
total={<Total />}
2024-07-08 20:39:43 +05:30
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-07 20:18:36 +05:30
2024-11-14 12:08:17 +05:30
<AddPending isOpen={isOpen} onClose={onClose} firstField={firstField} />
2024-07-08 20:39:43 +05:30
</Box>
);
};
2024-07-05 15:28:02 +05:30
2024-11-14 12:08:17 +05:30
export default Pending;