import { Link, router, useForm } from '@inertiajs/react'; import { useState } from 'react'; import { Management, button, control } from './shared'; type Preview = { id: string; file_name: string; sha256: string; publication_version: string; status: string; report: { record_count: number; issue_counts: Record; issues: { code: string; sheet: string; cell: string; delta?: string }[]; }; matches: { key: string; province: string; territory: string; level: string; geo_location_id: string | null; state: string; }[]; territory_options: { id: string; name: string; location_type: string; parent_id: string | null; }[]; events: { id: number; action: string; reason: string; created_at: string; }[]; }; export default function DemographyManagement({ batches, preview, qa = true, editorialEnabled = false, editorialRevision = 0, }: { editorialEnabled?: boolean; editorialRevision?: number; qa?: boolean; batches: { id: string; file_name: string; publication_version: string; status: string; }[]; preview: Preview | null; }) { const [file, setFile] = useState(null); const [version, setVersion] = useState(''); const [year, setYear] = useState(''); const [reason, setReason] = useState(''); const [mapping, setMapping] = useState>({}); const [message, setMessage] = useState(''); const [busy, setBusy] = useState(false); const review = useForm({ expected_revision: editorialRevision }); async function execute(path: string, body: FormData | object) { setBusy(true); setMessage(''); try { const token = document.cookie .split('; ') .find((c) => c.startsWith('XSRF-TOKEN=')) ?.split('=') .slice(1) .join('=') ?? ''; const response = await fetch(path, { method: 'POST', headers: { Accept: 'application/json', 'X-XSRF-TOKEN': decodeURIComponent(token), ...(body instanceof FormData ? {} : { 'Content-Type': 'application/json' }), }, body: body instanceof FormData ? body : JSON.stringify(body), }); const data = await response.json().catch(() => null); if (!data) throw new Error( 'O servidor não confirmou a operação. Confira o estado guardado antes de repetir.', ); if (!response.ok) throw new Error( data.message ?? 'Não foi possível executar a operação.', ); setMapping({}); router.get('/management/demography', { batch: data.id }); } catch (error) { setMessage( error instanceof Error ? error.message : 'Erro de comunicação.', ); } finally { setBusy(false); } } return (

Preparar não grava observações. Confirmar importa para consulta administrativa.{' '} {editorialEnabled ? 'A revisão, a aprovação e a publicação dos novos lotes são operações distintas. Os lotes anteriormente disponibilizados permanecem preservados.' : 'Aprovar disponibiliza a série nas análises deste ambiente; desactivar conserva dados e histórico.'}

{ e.preventDefault(); if (!file) return; const body = new FormData(); body.append('file', file); body.append('publication_version', version); if (year) body.append('baseline_year', year); void execute('/management/demography/prepare', body); }} >
{message &&

{message}

}

Importações anteriores

{preview && (

{preview.file_name} — {preview.status}

{preview.report.record_count} observações extraídas. SHA256: {preview.sha256}

Erros e advertências
                            {JSON.stringify(
                                preview.report.issue_counts,
                                null,
                                2,
                            )}
                        
    {preview.report.issues.map((i, n) => (
  • {i.sheet}!{i.cell}: {i.code}{' '} {i.delta ?? ''}
  • ))}

Correspondências territoriais

{preview.matches.map((m) => ( ))}