'use client' import { useState } from 'react' import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover' import { Button } from '@/ui/components/ui/button' import { Input } from '@/ui/components/ui/input' import { Label } from '@/ui/components/ui/label' import { client } from '@/ui/api/client' import { Loader2 } from 'lucide-react' interface GuestIdentityPopupProps { isOpen: boolean onClose: () => void onSuccess: (guestUserId: string) => void children?: React.ReactNode } export function GuestIdentityPopup({ isOpen, onClose, onSuccess, children, }: GuestIdentityPopupProps) { const [name, setName] = useState('') const [email, setEmail] = useState('') const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(null) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setError(null) try { const res = await client.api.identify.$post({ json: { username: name, email: email }, }) if (!res.ok) { const data = (await res.json()) as { error?: string } throw new Error(data.error || 'Failed to identify') } const { id } = await res.json() localStorage.setItem('guest_user_id', id) onSuccess(id) onClose() } catch (err) { setError((err as Error).message) } finally { setIsLoading(false) } } return ( !open && onClose()}> {children}

Enter your details

Please provide your name and email to add a comment.

setName(e.target.value)} placeholder="John Doe" size={32} required />
setEmail(e.target.value)} placeholder="john@example.com" required />
{error &&

{error}

}
) }