import { useState } from "react"; import { fetchClient } from "@/lib/api-client"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Copy, Check, Ticket, Loader2, RefreshCw } from "lucide-react"; import { useToast } from "@/hooks/use-toast"; export default function InviteVendorCard() { const [loading, setLoading] = useState(false); const [code, setCode] = useState(null); const [copied, setCopied] = useState(false); const { toast } = useToast(); async function handleInvite() { setLoading(true); setCode(null); setCopied(false); try { const res = await fetchClient<{ code: string }>("/admin/invitations", { method: "POST" }); setCode(res.code); toast({ title: "Invitation Created", description: "New vendor invitation code generated successfully.", }); } catch (e: any) { toast({ title: "Error", description: e?.message || "Failed to generate invitation", variant: "destructive", }); } finally { setLoading(false); } } const copyToClipboard = () => { if (!code) return; navigator.clipboard.writeText(code); setCopied(true); toast({ title: "Copied", description: "Invitation code copied to clipboard", }); setTimeout(() => setCopied(false), 2000); }; return (
Invite Vendor
Generate a one-time invitation code.
{code ? (
{code}

Share this code with the new vendor. It expires in 7 days.

) : (
Click generate to create a new code.
)}
); }