vrsao 2
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-08 14:02:01 +02:00
parent bdd766c68a
commit 1106509116
354 changed files with 48275 additions and 24635 deletions
+162 -82
View File
@@ -1,14 +1,14 @@
import { Link, router } from "@inertiajs/react";
import { useState } from "react";
import { Frame, Field, input, button, card, api } from "./shared";
import { businessModalities, businessStates } from "./business-types";
import type { Business } from "./business-types";
import BusinessObjects from "./business-objects";
import type { BusinessObject } from "./business-objects";
import BusinessVerifications from "./business-verifications";
import type { BusinessVerification } from "./business-verifications";
import BusinessWizard from "./business-wizard";
import type { FormSchema } from "./business-wizard";
import { Link, router } from '@inertiajs/react';
import { useState } from 'react';
import { Frame, Field, input, button, card, api } from './shared';
import { businessModalities, businessStates } from './business-types';
import type { Business } from './business-types';
import BusinessObjects from './business-objects';
import type { BusinessObject } from './business-objects';
import BusinessVerifications from './business-verifications';
import type { BusinessVerification } from './business-verifications';
import BusinessWizard from './business-wizard';
import type { FormSchema } from './business-wizard';
type Props = {
formSchema: FormSchema;
@@ -26,12 +26,27 @@ type Props = {
objectKinds: string[];
verificationChecks: string[];
verifications: BusinessVerification[];
history: { version_no: number; action: string; created_at: string; note: string }[];
history: {
version_no: number;
action: string;
created_at: string;
note: string;
}[];
};
export default function BusinessPage(props: Props) {
if (props.canEdit)
return <BusinessWizard key={props.record.id + ":" + props.record.version_no} {...props} />;
return <Editor key={`${props.record.id}:${props.record.version_no}`} {...props} />;
return (
<BusinessWizard
key={props.record.id + ':' + props.record.version_no}
{...props}
/>
);
return (
<Editor
key={`${props.record.id}:${props.record.version_no}`}
{...props}
/>
);
}
function Editor({
record,
@@ -53,22 +68,28 @@ function Editor({
}: Props) {
const [payload, setPayload] = useState(record.payload);
const [modality, setModality] = useState(record.modality);
const [note, setNote] = useState("");
const [note, setNote] = useState('');
const [consent, setConsent] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState("");
const [error, setError] = useState('');
const dirty =
JSON.stringify(payload) !== JSON.stringify(record.payload) || modality !== record.modality;
JSON.stringify(payload) !== JSON.stringify(record.payload) ||
modality !== record.modality;
const run = async (action?: string) => {
setBusy(true);
setError("");
setError('');
try {
await api(
`/api/v1/existing-business/listings/${record.id}${action ? "/transitions" : ""}`,
`/api/v1/existing-business/listings/${record.id}${action ? '/transitions' : ''}`,
action
? { action, version_no: record.version_no, note, review_consent: consent }
? {
action,
version_no: record.version_no,
note,
review_consent: consent,
}
: {
_method: "PUT",
_method: 'PUT',
modality,
classification: record.classification,
payload,
@@ -81,7 +102,7 @@ function Editor({
setError(
err instanceof Error
? err.message
: "Não foi possível guardar. Recarregue se a versão mudou.",
: 'Não foi possível guardar. Recarregue se a versão mudou.',
);
} finally {
setBusy(false);
@@ -91,41 +112,45 @@ function Editor({
<Frame title={record.payload.title}>
<Link
className="underline"
href={owner ? "/investidor/negocios" : "/management/negocios"}
href={owner ? '/investidor/negocios' : '/management/negocios'}
>
Voltar à lista
</Link>
<p>
{businessStates[record.status]} · versão {record.version_no} · informação reservada
{businessStates[record.status]} · versão {record.version_no} ·
informação reservada
</p>
<p>
Informação declarada, pendente de validação. Não constitui anúncio público,
certificação, avaliação ou autorização de transmissão.
Informação declarada, pendente de validação. Não constitui
anúncio público, certificação, avaliação ou autorização de
transmissão.
</p>
{!canEdit && (
<dl className={`${card} space-y-3 break-words`}>
<div>
<dt className="font-bold">Sector</dt>
<dd>
{sectors.find((sector) => sector.id === record.sector_id)?.name ?? "—"}
{sectors.find(
(sector) => sector.id === record.sector_id,
)?.name ?? '—'}
</dd>
</div>
{Object.entries(formSchema)
.filter(
([key]) =>
![
"title",
"description",
"declared_reason",
"source_reference",
"valid_until",
'title',
'description',
'declared_reason',
'source_reference',
'valid_until',
].includes(key),
)
.map(([key, field]) => (
<div key={key}>
<dt className="font-bold">{field.pt}</dt>
<dd className="whitespace-pre-wrap">
{record.payload[key] || "—"}
{record.payload[key] || '—'}
</dd>
</div>
))}
@@ -154,32 +179,40 @@ function Editor({
</Field>
{(
[
["title", "Título privado"],
["description", "Descrição reservada"],
["declared_reason", "Motivo declarado"],
["source_reference", "Referência da fonte"],
["valid_until", "Validade declarada"],
['title', 'Título privado'],
['description', 'Descrição reservada'],
['declared_reason', 'Motivo declarado'],
['source_reference', 'Referência da fonte'],
['valid_until', 'Validade declarada'],
] as const
).map(([key, label]) => (
<Field key={key} label={label}>
{key === "description" ? (
{key === 'description' ? (
<textarea
className={input}
rows={5}
maxLength={10000}
value={payload[key] ?? ""}
value={payload[key] ?? ''}
onChange={(e) =>
setPayload({ ...payload, [key]: e.target.value })
setPayload({
...payload,
[key]: e.target.value,
})
}
/>
) : (
<input
className={input}
type={key === "valid_until" ? "date" : "text"}
maxLength={key === "title" ? 200 : 2000}
value={payload[key] ?? ""}
type={
key === 'valid_until' ? 'date' : 'text'
}
maxLength={key === 'title' ? 200 : 2000}
value={payload[key] ?? ''}
onChange={(e) =>
setPayload({ ...payload, [key]: e.target.value })
setPayload({
...payload,
[key]: e.target.value,
})
}
/>
)}
@@ -198,11 +231,18 @@ function Editor({
</Field>
{error && <p role="alert">{error}</p>}
{canEdit && (
<button className={button} disabled={busy || note.trim().length < 10}>
<button
className={button}
disabled={busy || note.trim().length < 10}
>
Guardar rascunho
</button>
)}
{dirty && <p role="status">Guarde as alterações antes de mudar de estado.</p>}
{dirty && (
<p role="status">
Guarde as alterações antes de mudar de estado.
</p>
)}
</form>
{owner && canEdit && (
<label className="flex gap-3">
@@ -211,88 +251,126 @@ function Editor({
checked={consent}
onChange={(e) => setConsent(e.target.checked)}
/>
Autorizo a análise interna desta submissão pelos revisores designados. Esta
autorização não permite publicação.
Autorizo a análise interna desta submissão pelos revisores
designados. Esta autorização não permite publicação.
</label>
)}
<div className="flex flex-wrap gap-3">
{owner && canEdit && (
<button
className={button}
disabled={busy || dirty || !consent || note.trim().length < 10}
onClick={() => void run("submitted")}
disabled={
busy || dirty || !consent || note.trim().length < 10
}
onClick={() => void run('submitted')}
>
Submeter para análise
</button>
)}
{canReview && record.status === "submitted" && (
{canReview && record.status === 'submitted' && (
<button
className={button}
disabled={busy || note.trim().length < 10}
onClick={() => void run("in_review")}
onClick={() => void run('in_review')}
>
Iniciar revisão
</button>
)}
{canReview && record.status === "in_review" && (
{canReview && record.status === 'in_review' && (
<button
className={button}
disabled={busy || note.trim().length < 10}
onClick={() => void run("needs_information")}
onClick={() => void run('needs_information')}
>
Pedir informação
</button>
)}
{canTriage && record.status === "submitted" && (
<button className={button} disabled={busy || note.trim().length < 10} onClick={() => void run("triage")}>
{canTriage && record.status === 'submitted' && (
<button
className={button}
disabled={busy || note.trim().length < 10}
onClick={() => void run('triage')}
>
Iniciar triagem
</button>
)}
{canReview && record.status === "triage" && (
<button className={button} disabled={busy || note.trim().length < 10} onClick={() => void run("in_review")}>
{canReview && record.status === 'triage' && (
<button
className={button}
disabled={busy || note.trim().length < 10}
onClick={() => void run('in_review')}
>
Encaminhar para revisão
</button>
)}
{canReview && record.status === "in_review" && (
{canReview && record.status === 'in_review' && (
<>
<button className={button} disabled={busy || note.trim().length < 10} onClick={() => void run("approval_l1")}>
<button
className={button}
disabled={busy || note.trim().length < 10}
onClick={() => void run('approval_l1')}
>
Enviar para aprovação nível 1
</button>
<button className={button} disabled={busy || note.trim().length < 10} onClick={() => void run("rejected")}>
<button
className={button}
disabled={busy || note.trim().length < 10}
onClick={() => void run('rejected')}
>
Rejeitar
</button>
</>
)}
{canApproveLevelOne && record.status === "approval_l1" && (
{canApproveLevelOne && record.status === 'approval_l1' && (
<>
<button className={button} disabled={busy || note.trim().length < 10} onClick={() => void run("approval_l2")}>
<button
className={button}
disabled={busy || note.trim().length < 10}
onClick={() => void run('approval_l2')}
>
Aprovar nível 1 e enviar ao nível 2
</button>
<button className={button} disabled={busy || note.trim().length < 10} onClick={() => void run("rejected")}>
<button
className={button}
disabled={busy || note.trim().length < 10}
onClick={() => void run('rejected')}
>
Rejeitar
</button>
</>
)}
{canApproveLevelTwo && record.status === "approval_l2" && (
{canApproveLevelTwo && record.status === 'approval_l2' && (
<>
<button className={button} disabled={busy || note.trim().length < 10} onClick={() => void run("approved")}>
<button
className={button}
disabled={busy || note.trim().length < 10}
onClick={() => void run('approved')}
>
Aprovar nível 2
</button>
<button className={button} disabled={busy || note.trim().length < 10} onClick={() => void run("rejected")}>
<button
className={button}
disabled={busy || note.trim().length < 10}
onClick={() => void run('rejected')}
>
Rejeitar
</button>
</>
)}
{canPublish && record.status === "approved" && (
<button className={button} disabled={busy || note.trim().length < 10} onClick={() => void run("published")}>
{canPublish && record.status === 'approved' && (
<button
className={button}
disabled={busy || note.trim().length < 10}
onClick={() => void run('published')}
>
Publicar
</button>
)}
{owner && record.status !== "withdrawn" && (
{owner && record.status !== 'withdrawn' && (
<button
className={button}
disabled={busy || dirty || note.trim().length < 10}
onClick={() => void run("withdrawn")}
onClick={() => void run('withdrawn')}
>
Retirar submissão
</button>
@@ -308,7 +386,7 @@ function Editor({
<BusinessVerifications
id={record.id}
version={record.version_no}
editable={canReview && record.status === "in_review" && !busy}
editable={canReview && record.status === 'in_review' && !busy}
checks={verificationChecks}
findings={verifications}
objects={objects}
@@ -318,20 +396,22 @@ function Editor({
<ol>
{history.map((h) => (
<li key={h.version_no}>
Versão {h.version_no} ·{" "}
Versão {h.version_no} ·{' '}
{businessStates[h.action] ??
(
{
created: "Criado",
updated: "Alterado",
archived: "Arquivado",
object_added: "Elemento declarado acrescentado",
object_updated: "Elemento declarado alterado",
verification: "Verificação registada",
created: 'Criado',
updated: 'Alterado',
archived: 'Arquivado',
object_added:
'Elemento declarado acrescentado',
object_updated:
'Elemento declarado alterado',
verification: 'Verificação registada',
} as Record<string, string>
)[h.action] ??
h.action}{" "}
· {new Date(h.created_at).toLocaleString("pt-MZ")}
h.action}{' '}
· {new Date(h.created_at).toLocaleString('pt-MZ')}
<p>{h.note}</p>
</li>
))}