177 lines
7.4 KiB
TypeScript
177 lines
7.4 KiB
TypeScript
import { router } from "@inertiajs/react";
|
|
import { useState } from "react";
|
|
import { api, button, card, Field, input } from "./shared";
|
|
import type { BusinessObject } from "./business-objects";
|
|
|
|
const labels: Record<string, string> = {
|
|
identity: "Identidade",
|
|
representation: "Representação",
|
|
declared_ownership: "Titularidade declarada",
|
|
documentary_ownership: "Titularidade documental",
|
|
document_received: "Documento recebido",
|
|
document_validated: "Documento validado",
|
|
independent_valuation: "Avaliação independente",
|
|
land_right_documented: "Direito fundiário documentado",
|
|
license_confirmed: "Licença confirmada",
|
|
validity: "Validade",
|
|
legal_transfer: "Transmissibilidade jurídica",
|
|
prior_authorization: "Autorização prévia",
|
|
confirmed: "Confirmado pelo revisor",
|
|
rejected: "Não confirmado",
|
|
inconclusive: "Inconclusivo",
|
|
revoked: "Revogado",
|
|
stale: "Rever após alteração dos dados",
|
|
expired: "Expirado",
|
|
};
|
|
export type BusinessVerification = {
|
|
check: string;
|
|
object_id?: string | null;
|
|
outcome: string;
|
|
effective_outcome: string;
|
|
evidence_reference: string;
|
|
note: string;
|
|
valid_until?: string | null;
|
|
version_no: number;
|
|
};
|
|
export default function BusinessVerifications({
|
|
id,
|
|
version,
|
|
editable,
|
|
checks,
|
|
findings,
|
|
objects,
|
|
}: {
|
|
id: string;
|
|
version: number;
|
|
editable: boolean;
|
|
checks: string[];
|
|
findings: BusinessVerification[];
|
|
objects: BusinessObject[];
|
|
}) {
|
|
const [busy, setBusy] = useState(false);
|
|
const [error, setError] = useState("");
|
|
const [outcome, setOutcome] = useState("inconclusive");
|
|
return (
|
|
<section className={`${card} space-y-4`}>
|
|
<h2 className="text-xl font-bold">Verificações e evidências</h2>
|
|
<p>
|
|
Cada conclusão corresponde apenas ao aspecto e à versão analisados. Não constitui
|
|
certificação global, autorização de publicação ou garantia de transmissão.
|
|
Alterações aos dados exigem nova revisão.
|
|
</p>
|
|
{findings.length === 0 && <p>Ainda não existem verificações registadas.</p>}
|
|
<ul className="space-y-4">
|
|
{findings.map((finding) => (
|
|
<li key={finding.version_no} className="break-words">
|
|
<strong>
|
|
{labels[finding.check]} · {labels[finding.effective_outcome]}
|
|
</strong>
|
|
<p>
|
|
{objects.find((object) => object.id === finding.object_id)?.payload
|
|
.label ?? "Negócio"}{" "}
|
|
· versão {finding.version_no}
|
|
</p>
|
|
<p>Evidência: {finding.evidence_reference}</p>
|
|
<p>{finding.note}</p>
|
|
{finding.valid_until && <p>Válido até {finding.valid_until}</p>}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
{editable && (
|
|
<form
|
|
className="space-y-4"
|
|
onSubmit={async (event) => {
|
|
event.preventDefault();
|
|
const data = Object.fromEntries(new FormData(event.currentTarget));
|
|
setBusy(true);
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/existing-business/listings/${id}/verifications`, {
|
|
...data,
|
|
version_no: version,
|
|
});
|
|
router.reload();
|
|
} catch (failure) {
|
|
setError(
|
|
failure instanceof Error
|
|
? failure.message
|
|
: "Não foi possível registar a verificação.",
|
|
);
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}}
|
|
>
|
|
<fieldset disabled={busy} className="space-y-4">
|
|
<Field label="Elemento analisado">
|
|
<select className={input} name="object_id">
|
|
<option value="">Negócio</option>
|
|
{objects.map((object) => (
|
|
<option key={object.id} value={object.id}>
|
|
{object.payload.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
<Field label="Aspecto verificado">
|
|
<select className={input} name="check">
|
|
{checks.map((check) => (
|
|
<option key={check} value={check}>
|
|
{labels[check]}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
<Field label="Conclusão">
|
|
<select
|
|
className={input}
|
|
name="outcome"
|
|
value={outcome}
|
|
onChange={(event) => setOutcome(event.target.value)}
|
|
>
|
|
{["inconclusive", "confirmed", "rejected", "revoked"].map(
|
|
(value) => (
|
|
<option key={value} value={value}>
|
|
{labels[value]}
|
|
</option>
|
|
),
|
|
)}
|
|
</select>
|
|
</Field>
|
|
<Field label="Referência da evidência consultada">
|
|
<textarea
|
|
className={input}
|
|
name="evidence_reference"
|
|
required
|
|
minLength={10}
|
|
maxLength={2000}
|
|
/>
|
|
</Field>
|
|
<Field label="Fundamentação e limites da conclusão">
|
|
<textarea
|
|
className={input}
|
|
name="note"
|
|
required
|
|
minLength={10}
|
|
maxLength={2000}
|
|
/>
|
|
</Field>
|
|
<Field label="Validade da conclusão">
|
|
<input
|
|
className={input}
|
|
type="date"
|
|
name="valid_until"
|
|
required={outcome === "confirmed"}
|
|
/>
|
|
</Field>
|
|
<button className={button} disabled={busy}>
|
|
Registar verificação
|
|
</button>
|
|
</fieldset>
|
|
{error && <p role="alert">{error}</p>}
|
|
</form>
|
|
)}
|
|
</section>
|
|
);
|
|
}
|