feat(editorial): review demographic batches before explicit publication

This commit is contained in:
2026-11-14 08:35:11 +02:00
parent 2459d0ca37
commit 3c4c2599f7
17 changed files with 825 additions and 62 deletions
+98 -33
View File
@@ -1,4 +1,4 @@
import { router } from '@inertiajs/react';
import { Link, router, useForm } from '@inertiajs/react';
import { useState } from 'react';
import { Management, button, control } from './shared';
@@ -38,7 +38,11 @@ export default function DemographyManagement({
batches,
preview,
qa = true,
editorialEnabled = false,
editorialRevision = 0,
}: {
editorialEnabled?: boolean;
editorialRevision?: number;
qa?: boolean;
batches: {
id: string;
@@ -55,6 +59,7 @@ export default function DemographyManagement({
const [mapping, setMapping] = useState<Record<string, string>>({});
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('');
@@ -77,7 +82,11 @@ export default function DemographyManagement({
},
body: body instanceof FormData ? body : JSON.stringify(body),
});
const data = await response.json();
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.',
@@ -100,8 +109,10 @@ export default function DemographyManagement({
>
<p>
Preparar não grava observações. Confirmar importa para consulta
administrativa. Aprovar disponibiliza a série nas análises deste
ambiente; desactivar conserva dados e histórico.
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.'}
</p>
<form
className="space-y-3"
@@ -257,36 +268,90 @@ export default function DemographyManagement({
</button>
) : (
<>
{preview.status !== 'approved' && (
<button
disabled={busy || reason.length < 10}
className={button}
onClick={() =>
void execute(
`/management/demography/${preview.id}/transition`,
{ action: 'approved', reason },
)
}
>
{qa
? 'Aprovar utilização em QA'
: 'Aprovar utilização'}
</button>
)}
{preview.status !== 'disabled' && (
<button
disabled={busy || reason.length < 10}
className={button}
onClick={() =>
void execute(
`/management/demography/${preview.id}/transition`,
{ action: 'disabled', reason },
)
}
>
Desactivar série
</button>
{editorialEnabled && (
<div className="space-y-2">
{editorialRevision > 0 && (
<Link
className="underline"
href={`/management/editorial/demography/${preview.id}`}
>
Continuar revisão e consultar
versões
</Link>
)}
{preview.status === 'approved' ? (
<p>
{editorialRevision
? 'Lote publicado; consulte a edição e o histórico.'
: 'Lote anteriormente disponibilizado, preservado sem nova aprovação.'}
</p>
) : (
<button
type="button"
className={button}
disabled={
busy || review.processing
}
onClick={() => {
review.transform(() => ({
expected_revision:
editorialRevision,
}));
review.post(
`/management/editorial/demography/${preview.id}/drafts`,
);
}}
>
{editorialRevision
? 'Preparar nova edição de revisão'
: 'Preparar revisão para publicação'}
</button>
)}
</div>
)}
{!editorialEnabled &&
preview.status !== 'approved' && (
<button
disabled={
busy || reason.length < 10
}
className={button}
onClick={() =>
void execute(
`/management/demography/${preview.id}/transition`,
{
action: 'approved',
reason,
},
)
}
>
{qa
? 'Aprovar utilização em QA'
: 'Aprovar utilização'}
</button>
)}
{preview.status !== 'disabled' &&
(!editorialEnabled ||
editorialRevision === 0) && (
<button
disabled={
busy || reason.length < 10
}
className={button}
onClick={() =>
void execute(
`/management/demography/${preview.id}/transition`,
{
action: 'disabled',
reason,
},
)
}
>
Desactivar série
</button>
)}
</>
)}
</div>