import { Accordion, ActionIcon, Anchor, 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 { FormattedMessage } from "react-intl"; import Meta from "../../components/Meta"; import showReverseShareLinkModal from "../../components/account/showReverseShareLinkModal"; import showShareLinkModal from "../../components/account/showShareLinkModal"; import CenterLoader from "../../components/core/CenterLoader"; import showCreateReverseShareModal from "../../components/share/modals/showCreateReverseShareModal"; import useConfig from "../../hooks/config.hook"; import useTranslate from "../../hooks/useTranslate.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 t = useTranslate(); const config = useConfig(); const appUrl = config.get("general.appUrl"); const [reverseShares, setReverseShares] = useState(); const getReverseShares = () => { shareService .getMyReverseShares() .then((shares) => setReverseShares(shares)); }; useEffect(() => { getReverseShares(); }, []); if (!reverseShares) return ; return ( <> <FormattedMessage id="account.reverseShares.title" /> {reverseShares.length == 0 ? (
<FormattedMessage id="account.reverseShares.title.empty" />
) : ( {reverseShares.map((reverseShare) => ( ))}
{reverseShare.shares.length == 0 ? ( ) : ( {reverseShare.shares.length == 1 ? `1 ${t( "account.reverseShares.table.count.singular" )}` : `${reverseShare.shares.length} ${t( "account.reverseShares.table.count.plural" )}`} {reverseShare.shares.map((share) => ( {share.id} { if (window.isSecureContext) { clipboard.copy( `${appUrl}/s/${share.id}` ); toast.success(t("common.notify.copied")); } 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")} { if (window.isSecureContext) { clipboard.copy( `${config.get("general.appUrl")}/upload/${ reverseShare.token }` ); toast.success(t("common.notify.copied")); } else { showReverseShareLinkModal( modals, reverseShare.token, config.get("general.appUrl") ); } }} > { modals.openConfirmModal({ title: t( "account.reverseShares.modal.delete.title" ), children: ( ), confirmProps: { color: "red", }, labels: { confirm: t("common.button.delete"), cancel: t("common.button.cancel"), }, onConfirm: () => { shareService.removeReverseShare(reverseShare.id); setReverseShares( reverseShares.filter( (item) => item.id !== reverseShare.id ) ); }, }); }} >
)} ); }; export default MyShares;