Add scoped private business verification evidence and expiry
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,8 @@ 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";
|
||||
|
||||
type Props = {
|
||||
record: Business;
|
||||
@@ -14,6 +16,8 @@ type Props = {
|
||||
modalities: string[];
|
||||
objects: BusinessObject[];
|
||||
objectKinds: string[];
|
||||
verificationChecks: string[];
|
||||
verifications: BusinessVerification[];
|
||||
history: { version_no: number; action: string; created_at: string; note: string }[];
|
||||
};
|
||||
export default function BusinessPage(props: Props) {
|
||||
@@ -28,6 +32,8 @@ function Editor({
|
||||
history,
|
||||
objects,
|
||||
objectKinds,
|
||||
verificationChecks,
|
||||
verifications,
|
||||
}: Props) {
|
||||
const [payload, setPayload] = useState(record.payload);
|
||||
const [modality, setModality] = useState(record.modality);
|
||||
@@ -209,6 +215,14 @@ function Editor({
|
||||
objects={objects}
|
||||
objectKinds={objectKinds}
|
||||
/>
|
||||
<BusinessVerifications
|
||||
id={record.id}
|
||||
version={record.version_no}
|
||||
editable={canReview && record.status === "in_review" && !busy}
|
||||
checks={verificationChecks}
|
||||
findings={verifications}
|
||||
objects={objects}
|
||||
/>
|
||||
<section className={card}>
|
||||
<h2 className="text-xl font-bold">Histórico</h2>
|
||||
<ol>
|
||||
@@ -223,6 +237,7 @@ function Editor({
|
||||
archived: "Arquivado",
|
||||
object_added: "Elemento declarado acrescentado",
|
||||
object_updated: "Elemento declarado alterado",
|
||||
verification: "Verificação registada",
|
||||
} as Record<string, string>
|
||||
)[h.action] ??
|
||||
h.action}{" "}
|
||||
|
||||
Reference in New Issue
Block a user