import { Link, Role } from "@prisma/client"; import clsx from "clsx"; import { useTranslation } from "next-i18next"; import { usePlausible } from "next-plausible"; import * as React from "react"; import toast from "react-hot-toast"; import { useCopyToClipboard } from "react-use"; import Button from "./button"; export interface SharingProps { links: Link[]; } const useRoleData = (): Record< Role, { path: string; label: string; description: string } > => { const { t } = useTranslation("app"); return { admin: { path: "admin", label: t("admin"), description: t("adminDescription"), }, participant: { path: "p", label: t("participant"), description: t("participantDescription"), }, }; }; const Sharing: React.VoidFunctionComponent = ({ links }) => { const [state, copyToClipboard] = useCopyToClipboard(); const plausible = usePlausible(); React.useEffect(() => { if (state.error) { toast.error(`Unable to copy value: ${state.error.message}`); } }, [state]); const [role, setRole] = React.useState("participant"); const link = links.find((link) => link.role === role); if (!link) { throw new Error(`Missing link for role: ${role}`); } const roleData = useRoleData(); const { path } = roleData[link.role]; const pollUrl = `${window.location.origin}/${path}/${link.urlId}`; const [didCopy, setDidCopy] = React.useState(false); return (
{roleData[link.role].description}
); }; export default Sharing;