import { ActionIcon, Box, Button, Center, Group, LoadingOverlay, Space, Stack, Table, Text, Title, } from "@mantine/core"; import { useClipboard } from "@mantine/hooks"; import { useModals } from "@mantine/modals"; import moment from "moment"; import Link from "next/link"; import { useEffect, useState } from "react"; import { TbLink, TbTrash } from "react-icons/tb"; import showShareLinkModal from "../../components/account/showShareLinkModal"; import Meta from "../../components/Meta"; import useConfig from "../../hooks/config.hook"; import shareService from "../../services/share.service"; import { MyShare } from "../../types/share.type"; import toast from "../../utils/toast.util"; const MyShares = () => { const modals = useModals(); const clipboard = useClipboard(); const config = useConfig(); const [shares, setShares] = useState(); useEffect(() => { shareService.getMyShares().then((shares) => setShares(shares)); }, []); if (!shares) return ; return ( <> My shares {shares.length == 0 ? (
It's empty here 👀 You don't have any shares.
) : ( {shares.map((share) => ( ))}
Name Visitors Expires at
{share.id} {share.views} {moment(share.expiration).unix() === 0 ? "Never" : moment(share.expiration).format("LLL")} { if (window.isSecureContext) { clipboard.copy( `${config.get("APP_URL")}/share/${share.id}` ); toast.success( "Your link was copied to the keyboard." ); } else { showShareLinkModal( modals, share.id, config.get("APP_URL") ); } }} > { modals.openConfirmModal({ title: `Delete share ${share.id}`, children: ( Do you really want to delete this share? ), confirmProps: { color: "red", }, labels: { confirm: "Confirm", cancel: "Cancel" }, onConfirm: () => { shareService.remove(share.id); setShares( shares.filter((item) => item.id !== share.id) ); }, }); }} >
)} ); }; export default MyShares;