feat: add private business intake review and reserved objects
This commit is contained in:
@@ -0,0 +1,286 @@
|
||||
import { router } from "@inertiajs/react";
|
||||
import { useState } from "react";
|
||||
import { Field, input, button, card, api } from "./shared";
|
||||
|
||||
export type BusinessObject = {
|
||||
id: string;
|
||||
kind: string;
|
||||
verification_status: string;
|
||||
payload: Record<string, string>;
|
||||
};
|
||||
const kinds: Record<string, string> = {
|
||||
company: "Empresa",
|
||||
participation: "Participação",
|
||||
asset: "Activo físico",
|
||||
property: "Imóvel/propriedade",
|
||||
unit: "Unidade imobiliária",
|
||||
improvement: "Benfeitoria",
|
||||
agricultural_investment: "Investimento agrícola",
|
||||
land_right: "Direito fundiário",
|
||||
contract: "Contrato",
|
||||
license: "Licença",
|
||||
authorization: "Autorização",
|
||||
encumbrance: "Ónus ou encargo",
|
||||
valuation: "Avaliação declarada",
|
||||
capital_request: "Pedido de capital",
|
||||
};
|
||||
const fields: Record<string, string> = {
|
||||
label: "Designação reservada",
|
||||
declared_holder: "Titular declarado",
|
||||
document_reference: "Referência documental",
|
||||
source_reference: "Fonte da informação",
|
||||
competent_entity: "Entidade emissora/competente declarada",
|
||||
purpose: "Finalidade autorizada declarada",
|
||||
location_description: "Localização reservada",
|
||||
boundaries_description: "Limites declarados",
|
||||
occupancy: "Ocupação/utilização",
|
||||
condition: "Conservação/operação",
|
||||
encumbrances: "Ónus, garantias ou litígios declarados",
|
||||
restrictions: "Restrições declaradas",
|
||||
required_authorizations: "Autorizações necessárias declaradas",
|
||||
transfer_condition: "Condição de cessão/transmissão declarada",
|
||||
valid_from: "Início de validade",
|
||||
valid_until: "Fim de validade",
|
||||
area: "Área (decimal com ponto)",
|
||||
participation_percent: "Participação (%)",
|
||||
amount: "Valor (decimal com ponto)",
|
||||
currency: "Moeda (código de três letras)",
|
||||
};
|
||||
export default function BusinessObjects({
|
||||
businessId,
|
||||
version,
|
||||
editable,
|
||||
objects,
|
||||
objectKinds,
|
||||
}: {
|
||||
businessId: string;
|
||||
version: number;
|
||||
editable: boolean;
|
||||
objects: BusinessObject[];
|
||||
objectKinds: string[];
|
||||
}) {
|
||||
const [kind, setKind] = useState(objectKinds[0]);
|
||||
const [objectId, setObjectId] = useState<string | null>(null);
|
||||
const [payload, setPayload] = useState<Record<string, string>>({});
|
||||
const [reason, setReason] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
return (
|
||||
<section className={`${card} space-y-4`}>
|
||||
<h2 className="text-xl font-bold">Activos, contratos e direitos declarados</h2>
|
||||
<p>
|
||||
Registe separadamente cada elemento. Todos ficam pendentes de verificação; a
|
||||
declaração não confirma titularidade, validade ou transmissibilidade. Não use este
|
||||
formulário para anexar ficheiros.
|
||||
</p>
|
||||
{!objects.length && <p>Nenhum elemento registado.</p>}
|
||||
{objects.map((o) => (
|
||||
<article key={o.id} className="rounded border p-4">
|
||||
<h3 className="font-bold">
|
||||
{kinds[o.kind]} · {o.payload.label}
|
||||
</h3>
|
||||
<p>Pendente de verificação</p>
|
||||
<dl>
|
||||
{Object.entries(o.payload)
|
||||
.filter(([key, value]) => key !== "label" && value)
|
||||
.map(([key, value]) => (
|
||||
<div key={key}>
|
||||
<dt className="font-semibold">
|
||||
{fields[key] ??
|
||||
(
|
||||
{
|
||||
area_unit: "Unidade da área",
|
||||
value_kind: "Natureza do valor",
|
||||
contract_type: "Tipo de contrato",
|
||||
} as Record<string, string>
|
||||
)[key] ??
|
||||
key}
|
||||
</dt>
|
||||
<dd className="break-words">
|
||||
{key === "value_kind"
|
||||
? ((
|
||||
{
|
||||
asking: "Pedido",
|
||||
indicative: "Indicativo",
|
||||
appraised: "Avaliado — declaração pendente",
|
||||
proposed: "Proposto",
|
||||
negotiated: "Negociado — declaração pendente",
|
||||
confirmed: "Confirmado — declaração pendente",
|
||||
} as Record<string, string>
|
||||
)[value] ?? value)
|
||||
: value}
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
{editable && (
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
onClick={() => {
|
||||
setObjectId(o.id);
|
||||
setKind(o.kind);
|
||||
setPayload(o.payload);
|
||||
setReason("");
|
||||
}}
|
||||
>
|
||||
Editar elemento
|
||||
</button>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
{editable && (
|
||||
<form
|
||||
className="space-y-4"
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError("");
|
||||
try {
|
||||
await api(
|
||||
`/api/v1/existing-business/listings/${businessId}/objects${objectId ? `/${objectId}` : ""}`,
|
||||
{
|
||||
...(objectId ? { _method: "PUT" } : {}),
|
||||
kind,
|
||||
payload,
|
||||
reason,
|
||||
version_no: version,
|
||||
},
|
||||
);
|
||||
router.reload();
|
||||
} catch (err) {
|
||||
setError(
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: "Não foi possível guardar o elemento.",
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<h3 className="font-bold">
|
||||
{objectId ? "Editar elemento reservado" : "Acrescentar elemento reservado"}
|
||||
</h3>
|
||||
<Field label="Natureza">
|
||||
<select
|
||||
className={input}
|
||||
value={kind}
|
||||
disabled={!!objectId || busy}
|
||||
onChange={(e) => setKind(e.target.value)}
|
||||
>
|
||||
{objectKinds.map((k) => (
|
||||
<option key={k} value={k}>
|
||||
{kinds[k]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{Object.entries(fields).map(([key, label]) => (
|
||||
<Field key={key} label={label}>
|
||||
<input
|
||||
className={input}
|
||||
type={key.startsWith("valid_") ? "date" : "text"}
|
||||
value={payload[key] ?? ""}
|
||||
maxLength={key === "label" ? 200 : 2000}
|
||||
required={key === "label" || key === "source_reference"}
|
||||
onChange={(e) =>
|
||||
setPayload({ ...payload, [key]: e.target.value })
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
))}
|
||||
<Field label="Unidade da área">
|
||||
<select
|
||||
className={input}
|
||||
value={payload.area_unit ?? ""}
|
||||
onChange={(e) =>
|
||||
setPayload({ ...payload, area_unit: e.target.value })
|
||||
}
|
||||
>
|
||||
<option value="">Não indicada</option>
|
||||
{["m2", "ha", "km2"].map((x) => (
|
||||
<option key={x}>{x}</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Natureza do valor">
|
||||
<select
|
||||
className={input}
|
||||
value={payload.value_kind ?? ""}
|
||||
onChange={(e) =>
|
||||
setPayload({ ...payload, value_kind: e.target.value })
|
||||
}
|
||||
>
|
||||
<option value="">Não indicada</option>
|
||||
{Object.entries({
|
||||
asking: "Pedido",
|
||||
indicative: "Indicativo",
|
||||
appraised: "Avaliado (declaração por verificar)",
|
||||
proposed: "Proposto",
|
||||
negotiated: "Negociado (declaração por verificar)",
|
||||
confirmed: "Confirmado (declaração por verificar)",
|
||||
}).map(([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Tipo de contrato">
|
||||
<select
|
||||
className={input}
|
||||
value={payload.contract_type ?? ""}
|
||||
onChange={(e) =>
|
||||
setPayload({ ...payload, contract_type: e.target.value })
|
||||
}
|
||||
>
|
||||
<option value="">Não indicado</option>
|
||||
{Object.entries({
|
||||
purchase: "Compra",
|
||||
sale: "Venda",
|
||||
lease: "Arrendamento",
|
||||
operation: "Exploração",
|
||||
management: "Gestão",
|
||||
other: "Outro",
|
||||
}).map(([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
</div>
|
||||
<Field label="Motivo do registo ou alteração">
|
||||
<textarea
|
||||
className={input}
|
||||
value={reason}
|
||||
minLength={10}
|
||||
maxLength={1000}
|
||||
required
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
<button className={button} disabled={busy}>
|
||||
{busy ? "A guardar…" : "Guardar elemento reservado"}
|
||||
</button>
|
||||
{objectId && (
|
||||
<button
|
||||
type="button"
|
||||
className="ml-4 underline"
|
||||
onClick={() => {
|
||||
setObjectId(null);
|
||||
setPayload({});
|
||||
setReason("");
|
||||
}}
|
||||
>
|
||||
Cancelar edição
|
||||
</button>
|
||||
)}
|
||||
</form>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user