import { ActionIcon, Button, Center, Group, LoadingOverlay, Space, Table, Text, Title, } from "@mantine/core"; import { useClipboard } from "@mantine/hooks"; import { useModals } from "@mantine/modals"; import { NextLink } from "@mantine/next"; import { Query } from "appwrite"; import moment from "moment"; import { useEffect, useState } from "react"; import { Link, Trash } from "tabler-icons-react"; import Meta from "../../components/Meta"; import shareService from "../../services/share.service"; import { ShareDocument } from "../../types/Appwrite.type"; import aw from "../../utils/appwrite.util"; import toast from "../../utils/toast.util"; const MyShares = () => { const modals = useModals(); const clipboard = useClipboard(); const [shares, setShares] = useState(); useEffect(() => { aw.database .listDocuments( "shares", [Query.equal("enabled", true)], 100 ) .then((res) => setShares(res.documents)); }, []); if (!shares) return ; return ( <> My shares {shares.length == 0 ? (
It's empty here 👀 You don't have any shares.
) : ( {shares.map((share) => ( ))}
Name Visitors Security enabled Email Expires at
{share.$id} {share.visitorCount} {share.securityID ? "Yes" : "No"} {share.users!.length > 0 ? "Yes" : "No"} {moment(share.expiresAt).format("MMMM DD YYYY, HH:mm")} { clipboard.copy( `${window.location.origin}/share/${share.$id}` ); toast.success("Your link was copied to the keyboard."); }} > { 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;