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

357 lines
9.4 KiB
React
Raw Normal View History

2024-11-14 12:08:17 +05:30
import {
Avatar,
Badge,
Box,
Button,
HStack,
Input,
Table,
Tag,
Tbody,
Text,
Th,
Tooltip,
Tr,
useDisclosure,
useToast,
} from "@chakra-ui/react";
import React, { useContext, useEffect, useRef, useState } from "react";
import { AddIcon} from "@chakra-ui/icons";
import { OPACITY_ON_LOAD } from "../../../../Layout/animations";
import NormalTable from "../../../../Components/DataTable/NormalTable";
import GlobalStateContext from "../../../../Contexts/GlobalStateContext";
import CustomAlertDialog from "../../../../Components/CustomAlertDialog";
import AddCashDetails from "../AddCashDetails";
import AddRejected from "./AddRejected";
2024-11-14 16:04:20 +05:30
import { useUpdateIOCaseMutation } from "../../../../Services/io.service";
import { useParams } from "react-router-dom";
import ToastBox from "../../../../Components/ToastBox";
2024-11-18 17:54:23 +05:30
import AddCaseDetails from "./AddCaseDetails";
2024-11-14 12:08:17 +05:30
const formatDate = (date) => new Date(date).toLocaleDateString();
const Rejected = () => {
2024-11-14 16:04:20 +05:30
const params = useParams()
const id = params?.id
2024-11-14 12:08:17 +05:30
const toast = useToast();
const firstField = useRef();
const { isOpen, onOpen, onClose } = useDisclosure();
const { IODetails, approved, setApproved } =
useContext(GlobalStateContext);
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-11-14 12:08:17 +05:30
useEffect(() => {
// Simulate loading
const timer = setTimeout(() => {
setIsLoading(false);
}, 1500);
// Cleanup the timer on component unmount
return () => clearTimeout(timer);
}, []);
const formatDate = (date) => {
return new Date(date).toLocaleDateString("en-GB", {
day: "2-digit",
month: "2-digit",
year: "numeric",
});
};
// Table filter
const filteredData = IODetails?.ioCashStatusHistory?.Reject?.filter((item) => {
// Filter by name (case insensitive)
const name = item.transactionDate;
const searchLower = searchTerm.toLowerCase();
const nameMatches = name.toLowerCase().includes(searchLower);
return nameMatches;
});
const tableHeadRow = [
"Sr No.",
2024-12-02 12:23:27 +05:30
"Transaction Date",
2024-11-18 17:54:23 +05:30
"Transaction Type",
2024-11-14 12:08:17 +05:30
"Amount",
"Comments",
2024-12-02 12:23:27 +05:30
"Update By",
2024-11-14 12:08:17 +05:30
"Update On",
];
const extractedArray = filteredData?.map((item, index) => ({
id: item?.id,
"Sr No.": (
<Text
as={"span"}
color={"gray.800"}
fontWeight={"500"}
>
{index + 1}.
</Text>
),
2024-12-02 12:23:27 +05:30
"Transaction Date": (
2024-11-14 12:08:17 +05:30
<Text
as={"span"}
color={"gray.600"}
fontWeight={"500"}
>
{formatDate(item?.transactionDate)}
</Text>
),
2024-11-18 17:54:23 +05:30
"Transaction Type": (
<Text as={"span"} color={"gray.600"} fontWeight={"500"}>
{item?.transactionType}
</Text>
),
2024-11-14 12:08:17 +05:30
"Amount": (
<Text
as={"span"}
color={"gray.800"}
fontWeight={"500"}
>
<Badge ms={1} colorScheme="green" me={1}>
2024-11-22 12:48:02 +05:30
$
</Badge>
{parseFloat(IODetails?.ioCash || 0).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}
2024-11-14 12:08:17 +05:30
</Text>
),
"Comments": (
<Text
w={"100px"}
as={"span"}
color={"gray.800"}
fontWeight={"500"}
>
{item?.comments}
</Text>
),
2024-12-02 12:23:27 +05:30
"Update By": (
2024-11-14 12:08:17 +05:30
<Text
w={"100px"}
as={"span"}
color={"gray.800"}
fontWeight={"500"}
display={"flex"}
alignItems={"center"}
>
2024-11-22 13:32:28 +05:30
{/* <Avatar
2024-11-14 12:08:17 +05:30
mr={2}
size="sm"
name={item.creator?.firstName}
src={item.creator?.profilePhoto}
2024-11-22 13:32:28 +05:30
/> */}
2024-11-22 16:56:31 +05:30
{item?.modifier?.firstName}
2024-11-14 12:08:17 +05:30
</Text>
),
"Update On": (
<Text
w={"100px"}
as={"span"}
color={"gray.800"}
fontWeight={"500"}
>
{formatDate(item.updatedAt)}
</Text>
),
}));
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">
<Tr>
<Th
textAlign={"center"}
p={3}
width="130px"
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
>
Balance in IO Cash
</Th>
<Th
textAlign={"center"}
p={3}
width="150px"
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
>
{" "}
</Th>
<Th
textAlign={"center"}
p={3}
width="150px"
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
>
{}
</Th>
<Th
textAlign={"center"}
p={3}
width="100px"
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
>
{"48,000.00"}
</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"
></Th>
<Th
textAlign={"center"}
p={3}
width="100px"
color={"#004118"}
whiteSpace="normal"
wordBreak="normal"
overflowWrap="normal"
></Th>
</Tr>
</Tbody>
</Table>
);
};
2024-11-14 16:04:20 +05:30
const handleAdd = async () =>{
try {
const res = await updateIOCase(id)
if (res?.data) {
2024-11-22 16:19:59 +05:30
// toast({
// render: () => (
// <ToastBox status={"success"} message={res?.data?.message} />
// ),
// });
2024-11-14 16:04:20 +05:30
setIsLoading(false);
onOpen()
} else if (res?.error) {
toast({
render: () => (
<ToastBox status={"error"} message={res?.error?.data?.message} />
),
});
setIsLoading(false);
}
} catch (error) {
}
}
2024-11-14 12:08:17 +05:30
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-11-22 16:19:59 +05:30
{/* <HStack display={"flex"} alignItems={"center"}>
2024-11-18 17:54:23 +05:30
{IODetails?.isInvestedAmount ? (
localStorage?.getItem('role') ==="Maker"&& <Button
2024-11-14 16:04:20 +05:30
onClick={handleAdd}
2024-11-14 12:08:17 +05:30
leftIcon={<AddIcon />}
2024-11-14 16:04:20 +05:30
colorScheme="forestGreen"
size={"sm"}
2024-11-14 12:08:17 +05:30
rounded={"sm"}
fontSize={"xs"}
>
Add
</Button>
2024-11-14 16:04:20 +05:30
) : null}
2024-11-22 16:19:59 +05:30
</HStack> */}
2024-11-14 12:08:17 +05:30
</HStack>
</Box>
<NormalTable
emptyMessage={`We don't have any Sponers`}
tableHeadRow={tableHeadRow}
data={extractedArray}
isLoading={isLoading}
viewActionId={actionId}
setViewActionId={setActionId}
2024-11-22 12:48:02 +05:30
// total={<Total/>}
2024-11-14 12:08:17 +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-11-18 17:54:23 +05:30
<AddCaseDetails
2024-11-14 12:08:17 +05:30
isOpen={isOpen}
onClose={onClose}
firstField={firstField}
/>
</Box>
);
};
export default Rejected;