import { Button, Dialog, Input, Select } from "@cloudflare/kumo"; import { useLingui } from "@lingui/react/macro"; import { Check, Copy, X } from "@phosphor-icons/react"; import * as React from "react"; import { useRolesConfig } from "./useRolesConfig.js"; export interface InviteUserModalProps { open: boolean; isSending?: boolean; error?: string | null; /** When set, shows a copy-link view instead of the form (no email provider) */ inviteUrl?: string | null; onOpenChange: (open: boolean) => void; onInvite: (email: string, role: number) => void; } /** * Invite user modal — sends invite email or shows copy-link fallback */ export function InviteUserModal({ open, isSending, error, inviteUrl, onOpenChange, onInvite, }: InviteUserModalProps) { const { t } = useLingui(); const { roles, roleLabels } = useRolesConfig(); const [email, setEmail] = React.useState(""); const [role, setRole] = React.useState(30); // Default to Author const [copied, setCopied] = React.useState(false); const [copyError, setCopyError] = React.useState(false); const copyTimeoutRef = React.useRef | undefined>(undefined); // Reset form when modal opens React.useEffect(() => { if (open) { setEmail(""); setRole(30); setCopied(false); setCopyError(false); } }, [open]); // Clean up timeout on unmount React.useEffect(() => { return () => { if (copyTimeoutRef.current) clearTimeout(copyTimeoutRef.current); }; }, []); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); onInvite(email, role); }; const handleCopyUrl = async () => { if (!inviteUrl) return; try { await navigator.clipboard.writeText(inviteUrl); setCopied(true); setCopyError(false); copyTimeoutRef.current = setTimeout(setCopied, 2000, false); } catch { // Clipboard API can fail in insecure contexts setCopyError(true); } }; return (
{inviteUrl ? t`Invite Link Created` : t`Invite User`} {inviteUrl ? t`No email provider configured. Share this link manually.` : t`Send an invitation email to a new team member.`}
( )} />
{inviteUrl ? ( /* Copy-link view — shown when no email provider is configured */

{t`Share this link with the invited user`}

{t`This link expires in 7 days and can only be used once.`}

{inviteUrl}
{copied && (

{t`Copied to clipboard`}

)} {copyError && (

{t`Could not copy automatically. Please select the URL above and copy manually.`}

)}
) : ( /* Standard invite form */
{/* Email */} setEmail(e.target.value)} placeholder={t`colleague@example.com`} required autoComplete="off" /> {/* Role */}

{t`The invited user will have this role once they complete registration.`}

{/* Error message */} {error && (
{error}
)}
)}
); }