import type { CommentPolicy } from '@dorfteich/shared'; import { useQueryClient } from '@tanstack/react-query'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { FormError, FormSuccess } from '../components/forms'; import { apiPatch } from '../lib/api'; /** * The pond's "who may comment" setting (issue #91/#92): every reader, or * pond-wide editors only. Rides the generic pond PATCH. */ export function CommentPolicySetting({ pondId, pondSlug, value, }: { pondId: string; pondSlug: string; value: CommentPolicy; }): React.JSX.Element { const { t } = useTranslation('comments'); const queryClient = useQueryClient(); const [error, setError] = useState(null); const [saved, setSaved] = useState(false); const save = async (policy: CommentPolicy): Promise => { setError(null); setSaved(false); try { await apiPatch(`/ponds/${pondId}`, { commentPolicy: policy }); await queryClient.invalidateQueries({ queryKey: ['pond', pondSlug] }); setSaved(true); } catch (err) { setError(err); } }; return (

{t('policy.hint')}

); }