import { useState } from 'react' import { Modal } from '@/components/ui/Modal' import { Alert } from '@/components/ui/Alert' import { Button } from '@/components/ui/Button' import { errorMessage } from '@/lib/api' import { useMe } from '@/lib/auth' import type { Garden } from '@/lib/gardens' import { useRemoveShare } from '@/lib/shares' /** Confirmation for a recipient leaving a garden shared with them (removes their * own share). */ export function LeaveGardenModal({ garden, onClose }: { garden: Garden; onClose: () => void }) { const me = useMe() const remove = useRemoveShare(garden.id) const [error, setError] = useState(null) async function onConfirm() { if (!me.data) return setError(null) try { await remove.mutateAsync(me.data.id) onClose() } catch (err) { setError(errorMessage(err, 'Could not leave the garden.')) } } return (

Leave {garden.name}? You'll lose access until the owner shares it with you again.

{error && {error}}
) }