import { useQueryClient } from '@tanstack/react-query'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import { FormError } from '../components/forms'; import { apiDelete } from '../lib/api'; /** * The pond's danger zone: move a shared pond to the site-level trash * (`DELETE /ponds/:id`, Pond-Admin-gated in the api; a site admin can * restore it). Type-to-confirm with the pond name — the same backstop * pattern as the backup restore. Personal ponds never render this * section: they are the account's home and the api refuses anyway. */ export function DeletePondSection({ pondId, pondName, }: { pondId: string; pondName: string; }): React.JSX.Element { const { t } = useTranslation(); const navigate = useNavigate(); const queryClient = useQueryClient(); const [confirm, setConfirm] = useState(''); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const remove = async (event: React.FormEvent): Promise => { event.preventDefault(); setError(null); setBusy(true); try { await apiDelete(`/ponds/${pondId}`); await queryClient.invalidateQueries({ queryKey: ['ponds'] }); navigate('/'); } catch (err) { setError(err); setBusy(false); } }; return (

{t('pond.delete.title')}

{t('pond.delete.hint')}

void remove(e)}>
); }