import React, { useState, useRef, useEffect, use } from "react"; import { featureEnabled } from "../domainContext"; import getApi from "../../lib/getApi"; import { useFiefUserinfo } from "@fief/fief/nextjs/react"; import SelectSearch from "react-select-search"; import "react-select-search/style.css"; import "../../styles/button.css"; import "../../styles/form.scss"; type ShareLinkProps = { protectedPath: boolean; transcriptId: string; userId: string | null; shareMode: string; }; const ShareLink = (props: ShareLinkProps) => { const [isCopied, setIsCopied] = useState(false); const inputRef = useRef(null); const [currentUrl, setCurrentUrl] = useState(""); const requireLogin = featureEnabled("requireLogin"); const [isOwner, setIsOwner] = useState(false); const [shareMode, setShareMode] = useState(props.shareMode); const api = getApi(props.protectedPath); const userinfo = useFiefUserinfo(); useEffect(() => { setCurrentUrl(window.location.href); }, []); useEffect(() => { setIsOwner(!!(requireLogin && userinfo?.sub === props.userId)); }, [userinfo, props.userId]); const handleCopyClick = () => { if (inputRef.current) { let text_to_copy = inputRef.current.value; text_to_copy && navigator.clipboard.writeText(text_to_copy).then(() => { setIsCopied(true); // Reset the copied state after 2 seconds setTimeout(() => setIsCopied(false), 2000); }); } }; const updateShareMode = async (selectedShareMode: string) => { if (!api) return; const updatedTranscript = await api.v1TranscriptUpdate({ transcriptId: props.transcriptId, updateTranscript: { shareMode: selectedShareMode, }, }); setShareMode(updatedTranscript.shareMode); }; const privacyEnabled = featureEnabled("privacy"); return (
{requireLogin && (

{shareMode === "private" && (

This transcript is only accessible by you.

)} {shareMode === "semi-private" && (

This transcript is accessible by any authenticated users.

)} {shareMode === "public" && (

This transcript is accessible by anyone.

)} {isOwner && api && (

)}

)} {!requireLogin && ( <> {privacyEnabled ? (

You can share this link with others. Anyone with the link will have access to the page, including the full audio recording, for the next 7 days.

) : (

You can share this link with others. Anyone with the link will have access to the page, including the full audio recording.

)} )}
{}} className="border rounded-lg md:rounded-xl p-2 flex-grow flex-shrink overflow-auto mr-2 text-sm bg-slate-100 outline-slate-400" />
); }; export default ShareLink;