2024-07-30 12:50:44 +05:30
|
|
|
import React, { useState, useEffect } from "react";
|
2024-07-22 14:50:31 +05:30
|
|
|
import {
|
|
|
|
|
Modal,
|
|
|
|
|
ModalOverlay,
|
|
|
|
|
ModalContent,
|
|
|
|
|
ModalHeader,
|
|
|
|
|
ModalFooter,
|
|
|
|
|
ModalBody,
|
|
|
|
|
ModalCloseButton,
|
|
|
|
|
useDisclosure,
|
|
|
|
|
Button,
|
|
|
|
|
Box,
|
|
|
|
|
Text,
|
|
|
|
|
Image,
|
|
|
|
|
HStack,
|
2024-07-30 12:50:44 +05:30
|
|
|
useToast,
|
2024-08-22 12:10:07 +05:30
|
|
|
Badge,
|
|
|
|
|
Link,
|
2024-07-22 14:50:31 +05:30
|
|
|
} from "@chakra-ui/react";
|
|
|
|
|
|
2024-08-22 12:10:07 +05:30
|
|
|
import { AddIcon, DragHandleIcon, ExternalLinkIcon } from "@chakra-ui/icons";
|
2024-07-22 14:50:31 +05:30
|
|
|
import DataTable from "../../../Components/DataTable/DataTable";
|
2024-08-22 12:10:07 +05:30
|
|
|
import { useSetDisplayOrderIOArtifactsVideoMutation } from "../../../Services/io.service";
|
2024-07-30 12:50:44 +05:30
|
|
|
import ToastBox from "../../../Components/ToastBox";
|
2024-07-22 14:50:31 +05:30
|
|
|
|
2024-08-22 12:10:07 +05:30
|
|
|
const SetDisplayOrderIOArtifactsVideo = ({ data, }) => {
|
2024-08-02 16:56:53 +05:30
|
|
|
const toast = useToast();
|
2024-07-22 14:50:31 +05:30
|
|
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
2024-08-02 16:56:53 +05:30
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
2024-07-30 12:50:44 +05:30
|
|
|
|
2024-08-22 12:10:07 +05:30
|
|
|
const tableHeadRow = ["", "File Name", "Video streaming URL"];
|
2024-07-30 12:50:44 +05:30
|
|
|
|
|
|
|
|
const [extractedArray, setExtractedArray] = useState([]);
|
2024-08-02 16:56:53 +05:30
|
|
|
const [displayOrder, setDisplayOrder] = useState(null);
|
2024-08-22 12:10:07 +05:30
|
|
|
const [resetDisplayOrder] = useSetDisplayOrderIOArtifactsVideoMutation();
|
2024-07-30 12:50:44 +05:30
|
|
|
|
|
|
|
|
// Update state when `data` prop changes
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (data) {
|
|
|
|
|
const formattedData = data.map((item, index) => ({
|
|
|
|
|
id: item?.id,
|
|
|
|
|
displayOrder: index + 1, // Add displayOrder property
|
|
|
|
|
"": (
|
|
|
|
|
<Box w={"20px"} isTruncated={true}>
|
|
|
|
|
<DragHandleIcon />
|
|
|
|
|
</Box>
|
|
|
|
|
),
|
2024-08-22 12:10:07 +05:30
|
|
|
"File Name": (
|
|
|
|
|
<Box isTruncated={true}>
|
|
|
|
|
<Text as={"span"} color={"teal.900"} fontWeight={"500"}>
|
|
|
|
|
{item.artifactName}
|
2024-07-30 12:50:44 +05:30
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
),
|
2024-08-22 12:10:07 +05:30
|
|
|
"Video streaming URL": (
|
|
|
|
|
<Text
|
|
|
|
|
color={"green.500"}
|
|
|
|
|
justifyContent={"left"}
|
|
|
|
|
as={"span"}
|
|
|
|
|
fontWeight={"500"}
|
|
|
|
|
className="d-flex align-items-center web-text-small"
|
|
|
|
|
>
|
|
|
|
|
<Badge
|
|
|
|
|
px={2}
|
|
|
|
|
py={0.5}
|
2024-07-30 12:50:44 +05:30
|
|
|
display={"flex"}
|
|
|
|
|
alignItems={"center"}
|
2024-08-22 12:10:07 +05:30
|
|
|
textTransform={"inherit"}
|
|
|
|
|
fontWeight={500}
|
|
|
|
|
colorScheme={"forestGreen"}
|
|
|
|
|
>
|
|
|
|
|
<Link href={item?.artifactStreamingURL} isExternal>
|
|
|
|
|
<Box as="span">View</Box> <ExternalLinkIcon />
|
|
|
|
|
</Link>
|
|
|
|
|
</Badge>
|
|
|
|
|
</Text>
|
2024-07-30 12:50:44 +05:30
|
|
|
),
|
|
|
|
|
}));
|
|
|
|
|
setExtractedArray(formattedData);
|
|
|
|
|
}
|
|
|
|
|
}, [data]);
|
|
|
|
|
|
|
|
|
|
// Log the updated order in the desired format whenever `extractedArray` changes
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const displayOrderArray = extractedArray.map((item, index) => ({
|
|
|
|
|
id: item.id,
|
|
|
|
|
displayOrder: index + 1,
|
|
|
|
|
}));
|
2024-08-02 16:56:53 +05:30
|
|
|
setDisplayOrder(displayOrderArray);
|
2024-07-30 12:50:44 +05:30
|
|
|
}, [extractedArray]);
|
|
|
|
|
|
|
|
|
|
const handleSetOrder = async () => {
|
2024-08-02 16:56:53 +05:30
|
|
|
setIsLoading(true);
|
2024-07-30 12:50:44 +05:30
|
|
|
const data = {
|
2024-08-02 16:56:53 +05:30
|
|
|
displayOrder: displayOrder,
|
|
|
|
|
};
|
2024-07-30 12:50:44 +05:30
|
|
|
|
|
|
|
|
try {
|
2024-08-02 16:56:53 +05:30
|
|
|
const res = await resetDisplayOrder({ data });
|
2024-07-30 12:50:44 +05:30
|
|
|
console.log(res?.data?.statusCode);
|
|
|
|
|
if (res?.data?.statusCode === 200) {
|
|
|
|
|
toast({
|
|
|
|
|
render: () => <ToastBox message={res?.data?.message} />,
|
2024-08-02 16:56:53 +05:30
|
|
|
});
|
|
|
|
|
onClose();
|
2024-07-30 12:50:44 +05:30
|
|
|
}
|
2024-08-02 16:56:53 +05:30
|
|
|
|
|
|
|
|
setIsLoading(false);
|
2024-07-30 12:50:44 +05:30
|
|
|
} catch (error) {
|
|
|
|
|
console.log(res);
|
2024-08-02 16:56:53 +05:30
|
|
|
setIsLoading(false);
|
2024-07-30 12:50:44 +05:30
|
|
|
}
|
2024-08-02 16:56:53 +05:30
|
|
|
};
|
2024-07-22 14:50:31 +05:30
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Button
|
|
|
|
|
leftIcon={<AddIcon />}
|
|
|
|
|
size={"sm"}
|
|
|
|
|
fontSize={"xs"}
|
|
|
|
|
rounded={"sm"}
|
|
|
|
|
variant={"outline"}
|
|
|
|
|
colorScheme="forestGreen"
|
|
|
|
|
onClick={onOpen}
|
|
|
|
|
>
|
|
|
|
|
Set Display Order
|
|
|
|
|
</Button>
|
|
|
|
|
|
2024-07-30 12:50:44 +05:30
|
|
|
<Modal isCentered size={"xl"} isOpen={isOpen} onClose={onClose}>
|
2024-07-22 14:50:31 +05:30
|
|
|
<ModalOverlay />
|
2024-07-30 12:50:44 +05:30
|
|
|
<ModalContent>
|
2024-07-22 14:50:31 +05:30
|
|
|
<ModalHeader fontSize={"lg"}>Set Display Order</ModalHeader>
|
|
|
|
|
<ModalCloseButton />
|
|
|
|
|
<ModalBody>
|
2024-07-30 12:50:44 +05:30
|
|
|
<DataTable
|
|
|
|
|
emptyMessage={`We don't have any Sponsors`}
|
|
|
|
|
tableHeadRow={tableHeadRow}
|
|
|
|
|
data={extractedArray}
|
|
|
|
|
setData={setExtractedArray}
|
|
|
|
|
isDraggable={true}
|
|
|
|
|
/>
|
2024-07-22 14:50:31 +05:30
|
|
|
</ModalBody>
|
|
|
|
|
|
|
|
|
|
<ModalFooter>
|
|
|
|
|
<Button
|
|
|
|
|
size={"sm"}
|
|
|
|
|
fontSize={"xs"}
|
|
|
|
|
rounded={"sm"}
|
|
|
|
|
variant={"outline"}
|
|
|
|
|
colorScheme="forestGreen"
|
|
|
|
|
mr={3}
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
>
|
|
|
|
|
Reset order
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
size={"sm"}
|
|
|
|
|
fontSize={"xs"}
|
|
|
|
|
rounded={"sm"}
|
|
|
|
|
colorScheme="forestGreen"
|
|
|
|
|
variant="solid"
|
2024-07-30 12:50:44 +05:30
|
|
|
onClick={handleSetOrder}
|
|
|
|
|
isLoading={isLoading}
|
2024-07-22 14:50:31 +05:30
|
|
|
>
|
|
|
|
|
Set order
|
|
|
|
|
</Button>
|
|
|
|
|
</ModalFooter>
|
|
|
|
|
</ModalContent>
|
|
|
|
|
</Modal>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-22 12:10:07 +05:30
|
|
|
export default SetDisplayOrderIOArtifactsVideo;
|