import { Accordion, 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) => ( ))}
Shares Remaining uses Max share size Expires at
{reverseShare.shares.length == 0 ? ( No shares created yet ) : ( {`${reverseShare.shares.length} share${ reverseShare.shares.length > 1 ? "s" : "" }`} {reverseShare.shares.map((share) => ( {share.id} { if (window.isSecureContext) { clipboard.copy( `${config.get( "general.appUrl" )}/share/${share.id}` ); toast.success( "The share link was copied to the keyboard." ); } else { showShareLinkModal( modals, share.id, config.get("general.appUrl") ); } }} > ))} )} {reverseShare.remainingUses} {byteToHumanSizeString(parseInt(reverseShare.maxShareSize))} {moment(reverseShare.shareExpiration).unix() === 0 ? "Never" : moment(reverseShare.shareExpiration).format("LLL")} { modals.openConfirmModal({ title: `Delete reverse share`, children: ( Do you really want to delete this reverse share? If you do, the associated shares will be deleted as well. ), confirmProps: { color: "red", }, labels: { confirm: "Delete", cancel: "Cancel" }, onConfirm: () => { shareService.removeReverseShare(reverseShare.id); setReverseShares( reverseShares.filter( (item) => item.id !== reverseShare.id ) ); }, }); }} >
)} ); }; export default MyShares;