import type { PlaceContribFieldSwitches, PlaceContribState } from '@trek/shared'; import { Check, HeartHandshake, ShieldCheck, TriangleAlert, X } from 'lucide-react'; import { useState } from 'react'; import { useTranslation } from '../../i18n'; import { getApiErrorMessage } from '../../utils/apiError'; import ToggleSwitch from '../Settings/ToggleSwitch'; import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, fs, NEUTRAL_TINT, } from '../shared/DialogShell'; import { useToast } from '../shared/Toast'; import { ALL_FIELDS_ON, fieldEntries, fieldLabel, refusalReason } from './placeContribModel'; import type { usePlaceContrib } from './usePlaceContrib'; const NEVER = ['notes', 'files', 'trips', 'people', 'providers'] as const; /** * The question an admin gets once: share what this installation's users type * about places with every other TREK. Asked warmly and with every field already * on, because saying yes is the point of asking; but nothing leaves before the * admin presses Agree, and "not now" and "no" are as easy to reach. * * Closing the dialog decides nothing: it comes back on the next visit until one * of the three buttons is pressed. */ export default function PlaceContribPrompt({ state, contrib, onClose, }: { state: PlaceContribState; contrib: ReturnType; onClose: () => void; }) { const { t } = useTranslation(); const toast = useToast(); const [fields, setFields] = useState(() => state.consent.decision === 'agreed' || state.consent.decision === 'off' ? state.consent.fields : ALL_FIELDS_ON ); const none = !Object.values(fields).some(Boolean); const run = async (body: Parameters[0], done?: string) => { try { await contrib.decide(body); if (done) toast.success(done); onClose(); } catch (err) { const reason = refusalReason(err); toast.error( reason === 'terms_outdated' || reason === 'no_field' ? t(`admin.contribute.refused.${reason}`) : getApiErrorMessage(err, t('common.error')) ); } }; return ( ); }