import { ActionIcon, Box, Button, Center, Group, Stack, Table, Text, Title, Tooltip, } from "@mantine/core"; import { useClipboard } from "@mantine/hooks"; import { useModals } from "@mantine/modals"; import moment from "moment"; import { useEffect, useState } from "react"; import { TbInfoCircle, TbLink, TbPlus, TbTrash } from "react-icons/tb"; import showShareLinkModal from "../../components/account/showShareLinkModal"; import CenterLoader from "../../components/core/CenterLoader"; import Meta from "../../components/Meta"; import showCreateReverseShareModal from "../../components/share/modals/showCreateReverseShareModal"; import useConfig from "../../hooks/config.hook"; import shareService from "../../services/share.service"; import { MyReverseShare } from "../../types/share.type"; import { byteToHumanSizeString } from "../../utils/fileSize.util"; import toast from "../../utils/toast.util"; const MyShares = () => { const modals = useModals(); const clipboard = useClipboard(); const config = useConfig(); const [reverseShares, setReverseShares] = useState(); const getReverseShares = () => { shareService .getMyReverseShares() .then((shares) => setReverseShares(shares)); }; useEffect(() => { getReverseShares(); }, []); if (!reverseShares) return ; return ( <> My reverse shares {reverseShares.length == 0 ? (
It's empty here 👀 You don't have any reverse shares.
) : ( {reverseShares.map((reverseShare) => ( ))}
Name Visitors Max share size Expires at
{reverseShare.share ? ( reverseShare.share?.id ) : ( No share created yet )} {reverseShare.share?.views ?? "0"} {byteToHumanSizeString(parseInt(reverseShare.maxShareSize))} {moment(reverseShare.shareExpiration).unix() === 0 ? "Never" : moment(reverseShare.shareExpiration).format("LLL")} {reverseShare.share && ( { if (window.isSecureContext) { clipboard.copy( `${config.get("APP_URL")}/share/${ reverseShare.share!.id }` ); toast.success( "The share link was copied to the keyboard." ); } else { showShareLinkModal( modals, reverseShare.share!.id, config.get("APP_URL") ); } }} > )} { modals.openConfirmModal({ title: `Delete reverse share`, children: ( Do you really want to delete this reverse share? If you do, the share will be deleted as well. ), confirmProps: { color: "red", }, labels: { confirm: "Confirm", cancel: "Cancel" }, onConfirm: () => { shareService.removeReverseShare(reverseShare.id); setReverseShares( reverseShares.filter( (item) => item.id !== reverseShare.id ) ); }, }); }} >
)} ); }; export default MyShares;