@@ -1,4 +1,7 @@
|
||||
import { createOperationKey } from '@/lib/operation-key';
|
||||
import { valueText } from '@/lib/value-text';
|
||||
import OpportunityProfileActions from '@/components/opportunity-profile-actions';
|
||||
import OpportunityContactForm from '@/components/opportunity-contact-form';
|
||||
import OpportunityCanonicalFields, {
|
||||
type CanonicalOptions,
|
||||
} from '@/components/opportunity-canonical-fields';
|
||||
@@ -64,6 +67,7 @@ export default function OpportunityDraft({
|
||||
profileActions = [],
|
||||
canonicalOptions,
|
||||
workflowState,
|
||||
canonicalResponse,
|
||||
workflowTasks = [],
|
||||
workflowParticipants,
|
||||
publicationPreview,
|
||||
@@ -77,7 +81,12 @@ export default function OpportunityDraft({
|
||||
profileActions?: string[];
|
||||
profileContext?: Record<string, unknown> | null;
|
||||
profileAccess?: {
|
||||
contexts: { organization_id: string | null; type: string }[];
|
||||
internalPromoter?: boolean;
|
||||
contexts: {
|
||||
organization_id: string | null;
|
||||
organization_name?: string;
|
||||
type: string;
|
||||
}[];
|
||||
} | null;
|
||||
publicationPreview?: {
|
||||
title: string;
|
||||
@@ -85,6 +94,7 @@ export default function OpportunityDraft({
|
||||
description: string;
|
||||
};
|
||||
workflowParticipants?: {
|
||||
condition_responsibles?: { id: number; name: string }[];
|
||||
publishers: { id: number; name: string }[];
|
||||
validators: {
|
||||
id: number;
|
||||
@@ -95,6 +105,15 @@ export default function OpportunityDraft({
|
||||
};
|
||||
canonicalOptions?: CanonicalOptions;
|
||||
workflowState?: string;
|
||||
canonicalResponse?: {
|
||||
completion: {
|
||||
percentage: number;
|
||||
filled: number;
|
||||
applicable: number;
|
||||
missing_paths: string[];
|
||||
};
|
||||
materiality?: { reopened: string[]; retained: string[] } | null;
|
||||
};
|
||||
publicationState?: {
|
||||
scope: string;
|
||||
label: string;
|
||||
@@ -116,14 +135,16 @@ export default function OpportunityDraft({
|
||||
? {
|
||||
organization_id: record
|
||||
? (profileOrganization ?? null)
|
||||
: (profileAccess?.contexts[0]?.organization_id ?? null),
|
||||
: profileAccess?.internalPromoter
|
||||
? null
|
||||
: (profileAccess?.contexts[0]?.organization_id ?? null),
|
||||
opportunity_category:
|
||||
values.opportunity_category ??
|
||||
profileAccess?.contexts[0]?.type ??
|
||||
'',
|
||||
}
|
||||
: {}),
|
||||
creation_key: crypto.randomUUID(),
|
||||
creation_key: createOperationKey(),
|
||||
});
|
||||
const [busy, setBusy] = useState(false),
|
||||
[errors, setErrors] = useState<Record<string, string>>({}),
|
||||
@@ -132,6 +153,9 @@ export default function OpportunityDraft({
|
||||
[confirm, setConfirm] = useState(false),
|
||||
[token, setToken] = useState(etag);
|
||||
useEffect(() => setToken(etag), [etag]);
|
||||
const [savedContacts, setSavedContacts] = useState<
|
||||
{ id: string; full_name: string }[]
|
||||
>([]);
|
||||
const [path, setPath] = useState(territoryPath);
|
||||
const unavailable = Boolean(
|
||||
record?.deleted_at || record?.status === 'archived',
|
||||
@@ -175,7 +199,7 @@ export default function OpportunityDraft({
|
||||
Object.fromEntries(
|
||||
Object.entries(result.errors ?? {}).map(([k, v]) => [
|
||||
k,
|
||||
Array.isArray(v) ? v.join(' ') : String(v),
|
||||
Array.isArray(v) ? v.join(' ') : valueText(v),
|
||||
]),
|
||||
),
|
||||
);
|
||||
@@ -211,6 +235,42 @@ export default function OpportunityDraft({
|
||||
<Link href={basePath}>
|
||||
{profileMode ? 'Minhas oportunidades' : 'Voltar à gestão'}
|
||||
</Link>
|
||||
{profileMode && (
|
||||
<section
|
||||
aria-label="Âmbito desta entrega"
|
||||
className="rounded border p-3"
|
||||
>
|
||||
<h2>Âmbito desta entrega</h2>
|
||||
<p>
|
||||
Seis categorias base: projeto de investimento,
|
||||
imobiliário, fundiário, venda de negócio, parceria e
|
||||
franquia. Rascunho, correção, revisão independente e
|
||||
publicação são ações distintas; uma aprovação interna
|
||||
não atribui direitos nem substitui uma decisão externa.
|
||||
</p>
|
||||
<p>
|
||||
No imobiliário, a submissão inclui venda e arrendamento
|
||||
de imóvel concluído, desocupado e sem encargos ou
|
||||
limitações urbanísticas adicionais. Pode guardar e
|
||||
recuperar as outras variantes em preparação; a sua
|
||||
submissão permanece indisponível.
|
||||
</p>
|
||||
<p>
|
||||
Concessão, financiamento, fornecimento e outros,
|
||||
partilha individual de anexos, restauração de
|
||||
oportunidades e exportação normativa integral
|
||||
Response/§27 não estão incluídos. O Response disponível
|
||||
conserva o contrato de compatibilidade e o histórico.
|
||||
</p>
|
||||
<p>
|
||||
As restantes variantes económicas, societárias,
|
||||
territoriais, de contribuições e licenças exigem
|
||||
documentação e revisão aplicáveis. Esta entrega não
|
||||
certifica a viabilidade, a titularidade ou a decisão
|
||||
externa de cada caso.
|
||||
</p>
|
||||
</section>
|
||||
)}
|
||||
{profileMode && record && readOnly && canEditDraft && (
|
||||
<Link
|
||||
className="block underline"
|
||||
@@ -221,10 +281,11 @@ export default function OpportunityDraft({
|
||||
)}
|
||||
{profileMode && !record && (
|
||||
<label className="block">
|
||||
Organização e tipo autorizados
|
||||
Promotor real e categoria autorizada
|
||||
<select
|
||||
aria-label="Promotor real e categoria autorizada"
|
||||
className={control}
|
||||
value={`${String(data.organization_id ?? '')}|${String(data.opportunity_category ?? '')}`}
|
||||
value={`${valueText(data.organization_id ?? '')}|${valueText(data.opportunity_category ?? '')}`}
|
||||
onChange={(e) => {
|
||||
const [organization, type] =
|
||||
e.target.value.split('|');
|
||||
@@ -235,27 +296,57 @@ export default function OpportunityDraft({
|
||||
}));
|
||||
}}
|
||||
>
|
||||
{profileAccess?.internalPromoter && (
|
||||
<option value="">
|
||||
Selecionar o promotor real da oportunidade
|
||||
</option>
|
||||
)}
|
||||
{(profileAccess?.contexts ?? []).map((c) => (
|
||||
<option
|
||||
key={`${c.organization_id}|${c.type}`}
|
||||
value={`${c.organization_id ?? ''}|${c.type}`}
|
||||
>
|
||||
{c.organization_id ?? 'Âmbito individual'} —{' '}
|
||||
{c.type}
|
||||
{c.organization_name ??
|
||||
c.organization_id ??
|
||||
'Âmbito individual'}{' '}
|
||||
— {c.type}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)}
|
||||
{profileMode && record && (
|
||||
<p>
|
||||
<p
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
aria-label="Estado da oportunidade"
|
||||
>
|
||||
Estado da preparação:{' '}
|
||||
{(workflowState ?? record.status) === 'published'
|
||||
? 'Versão disponibilizada'
|
||||
: (states[workflowState ?? record.status] ??
|
||||
: ((
|
||||
{
|
||||
draft: 'Rascunho',
|
||||
submitted: 'Submetida para validação',
|
||||
needs_information: 'Correções solicitadas',
|
||||
information_pending: 'Aguarda parecer',
|
||||
in_review: 'Em validação interna',
|
||||
approved: 'Aprovada internamente',
|
||||
rejected: 'Rejeitada',
|
||||
suspended: 'Suspensa',
|
||||
archived: 'Arquivada',
|
||||
} as Record<string, string>
|
||||
)[workflowState ?? record.status] ??
|
||||
states[workflowState ?? record.status] ??
|
||||
workflowState ??
|
||||
record.status)}
|
||||
. {publicationState?.label}.{' '}
|
||||
{profileContext?.review_cycle != null && (
|
||||
<>
|
||||
Ciclo de revisão interna:{' '}
|
||||
{valueText(profileContext.review_cycle)}.{' '}
|
||||
</>
|
||||
)}
|
||||
{profileContext?.request_archive
|
||||
? 'Pedido de arquivo registado; aguarda decisão independente.'
|
||||
: ''}{' '}
|
||||
@@ -264,8 +355,15 @@ export default function OpportunityDraft({
|
||||
</p>
|
||||
)}
|
||||
<p>
|
||||
Classificação de origem: {classification}. Esta classificação
|
||||
não cria associações territoriais.
|
||||
Classificação de origem:{' '}
|
||||
{(
|
||||
{
|
||||
real: 'Oportunidade real',
|
||||
example: 'Exemplo demonstrativo',
|
||||
undetermined: 'Origem ainda indeterminada',
|
||||
} as Record<string, string>
|
||||
)[classification] ?? classification}
|
||||
. Esta classificação não cria associações territoriais.
|
||||
</p>
|
||||
{closedVersion && (
|
||||
<p>
|
||||
@@ -275,6 +373,47 @@ export default function OpportunityDraft({
|
||||
revisão, aprovação e publicação independentes.
|
||||
</p>
|
||||
)}
|
||||
{profileMode && record && canonicalResponse && (
|
||||
<section
|
||||
aria-label="Preenchimento e revisões"
|
||||
aria-live="polite"
|
||||
className="rounded border p-3"
|
||||
>
|
||||
<p>
|
||||
Preenchimento gravado:{' '}
|
||||
{canonicalResponse.completion.percentage}% (
|
||||
{canonicalResponse.completion.filled}/
|
||||
{canonicalResponse.completion.applicable} campos
|
||||
aplicáveis). Não equivale a validação ou aprovação.
|
||||
</p>
|
||||
{canonicalResponse.materiality && (
|
||||
<>
|
||||
<p>
|
||||
Revisões reabertas:{' '}
|
||||
{canonicalResponse.materiality.reopened.join(
|
||||
', ',
|
||||
) || 'Nenhuma'}
|
||||
.
|
||||
</p>
|
||||
<p>
|
||||
Revisões conservadas:{' '}
|
||||
{canonicalResponse.materiality.retained.join(
|
||||
', ',
|
||||
) || 'Nenhuma'}
|
||||
.
|
||||
</p>
|
||||
<p>
|
||||
A versão alterada exige nova aprovação
|
||||
independente; as assinaturas dos pareceres
|
||||
conservados permanecem no histórico.
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
<a href={`${basePath}/${record.id}/response`}>
|
||||
Abrir resposta canónica gravada
|
||||
</a>
|
||||
</section>
|
||||
)}
|
||||
<div
|
||||
id="opportunity-result"
|
||||
tabIndex={-1}
|
||||
@@ -364,7 +503,9 @@ export default function OpportunityDraft({
|
||||
>
|
||||
<select
|
||||
className={control}
|
||||
value={String(data.opportunity_category ?? '')}
|
||||
value={valueText(
|
||||
data.opportunity_category ?? '',
|
||||
)}
|
||||
onChange={(e) =>
|
||||
set('opportunity_category', e.target.value)
|
||||
}
|
||||
@@ -385,7 +526,7 @@ export default function OpportunityDraft({
|
||||
{key === 'description' || key === 'summary' ? (
|
||||
<textarea
|
||||
className={control}
|
||||
value={String(data[key] ?? '')}
|
||||
value={valueText(data[key] ?? '')}
|
||||
onChange={(e) =>
|
||||
set(key, e.target.value)
|
||||
}
|
||||
@@ -393,7 +534,7 @@ export default function OpportunityDraft({
|
||||
) : (
|
||||
<input
|
||||
className={control}
|
||||
value={String(data[key] ?? '')}
|
||||
value={valueText(data[key] ?? '')}
|
||||
onChange={(e) =>
|
||||
set(key, e.target.value)
|
||||
}
|
||||
@@ -404,7 +545,7 @@ export default function OpportunityDraft({
|
||||
<Field label="Sector" error={errors.sector_id}>
|
||||
<select
|
||||
className={control}
|
||||
value={String(data.sector_id ?? '')}
|
||||
value={valueText(data.sector_id ?? '')}
|
||||
onChange={(e) =>
|
||||
set('sector_id', e.target.value)
|
||||
}
|
||||
@@ -423,7 +564,7 @@ export default function OpportunityDraft({
|
||||
>
|
||||
<select
|
||||
className={control}
|
||||
value={String(data.promoter_type ?? '')}
|
||||
value={valueText(data.promoter_type ?? '')}
|
||||
onChange={(e) =>
|
||||
set('promoter_type', e.target.value)
|
||||
}
|
||||
@@ -439,12 +580,14 @@ export default function OpportunityDraft({
|
||||
'community',
|
||||
'other',
|
||||
].includes(
|
||||
String(values.promoter_type),
|
||||
valueText(values.promoter_type),
|
||||
) && (
|
||||
<option
|
||||
value={String(values.promoter_type)}
|
||||
value={valueText(
|
||||
values.promoter_type,
|
||||
)}
|
||||
>
|
||||
{String(values.promoter_type)}{' '}
|
||||
{valueText(values.promoter_type)}{' '}
|
||||
(valor existente)
|
||||
</option>
|
||||
)}
|
||||
@@ -472,9 +615,9 @@ export default function OpportunityDraft({
|
||||
value={
|
||||
data.maturity_catalogue_version ===
|
||||
maturityCatalogue.version
|
||||
? String(data.maturity_stage ?? '')
|
||||
? valueText(data.maturity_stage ?? '')
|
||||
: data.maturity_level
|
||||
? `legacy:${data.maturity_level}`
|
||||
? `legacy:${valueText(data.maturity_level)}`
|
||||
: ''
|
||||
}
|
||||
onChange={(e) => {
|
||||
@@ -509,11 +652,11 @@ export default function OpportunityDraft({
|
||||
values.maturity_catalogue_version !==
|
||||
maturityCatalogue.version && (
|
||||
<option
|
||||
value={`legacy:${values.maturity_level}`}
|
||||
value={`legacy:${valueText(values.maturity_level)}`}
|
||||
>
|
||||
{
|
||||
maturityCatalogue.legacyLabels[
|
||||
String(
|
||||
valueText(
|
||||
values.maturity_level,
|
||||
)
|
||||
]
|
||||
@@ -541,7 +684,7 @@ export default function OpportunityDraft({
|
||||
>
|
||||
<input
|
||||
className={control}
|
||||
value={String(data.financing_modality ?? '')}
|
||||
value={valueText(data.financing_modality ?? '')}
|
||||
onChange={(e) =>
|
||||
set('financing_modality', e.target.value)
|
||||
}
|
||||
@@ -553,7 +696,7 @@ export default function OpportunityDraft({
|
||||
>
|
||||
<textarea
|
||||
className={control}
|
||||
value={String(data.expected_impact ?? '')}
|
||||
value={valueText(data.expected_impact ?? '')}
|
||||
onChange={(e) =>
|
||||
set('expected_impact', e.target.value)
|
||||
}
|
||||
@@ -569,7 +712,7 @@ export default function OpportunityDraft({
|
||||
>
|
||||
<input
|
||||
className={control}
|
||||
value={String(
|
||||
value={valueText(
|
||||
data.estimated_investment_amount ??
|
||||
'',
|
||||
)}
|
||||
@@ -587,7 +730,7 @@ export default function OpportunityDraft({
|
||||
>
|
||||
<select
|
||||
className={control}
|
||||
value={String(
|
||||
value={valueText(
|
||||
data.estimated_investment_currency ??
|
||||
'',
|
||||
)}
|
||||
@@ -712,6 +855,35 @@ export default function OpportunityDraft({
|
||||
)}
|
||||
{profileMode && canonicalOptions && (
|
||||
<section>
|
||||
{record && !readOnly && !unavailable && (
|
||||
<OpportunityContactForm
|
||||
id={record.id}
|
||||
etag={token ?? ''}
|
||||
organization={
|
||||
(data.organization_id ?? null) as string | null
|
||||
}
|
||||
investors={canonicalOptions.contactInvestors ?? []}
|
||||
disabled={busy || !token}
|
||||
onSaved={(contact) => {
|
||||
setSavedContacts((prior) => [
|
||||
...prior.filter(
|
||||
(row) => row.id !== contact.id,
|
||||
),
|
||||
contact,
|
||||
]);
|
||||
setData((prior) => ({
|
||||
...prior,
|
||||
canonical: {
|
||||
...((prior.canonical as Record<
|
||||
string,
|
||||
unknown
|
||||
>) ?? {}),
|
||||
internal_contact_id: contact.id,
|
||||
},
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<OpportunityCanonicalFields
|
||||
value={
|
||||
(data.canonical ?? {}) as Record<string, unknown>
|
||||
@@ -719,9 +891,20 @@ export default function OpportunityDraft({
|
||||
onChange={(v) =>
|
||||
setData((d) => ({ ...d, canonical: v }))
|
||||
}
|
||||
options={canonicalOptions}
|
||||
options={{
|
||||
...canonicalOptions,
|
||||
contacts: [
|
||||
...canonicalOptions.contacts.filter(
|
||||
(row) =>
|
||||
!savedContacts.some(
|
||||
(saved) => saved.id === row.id,
|
||||
),
|
||||
),
|
||||
...savedContacts,
|
||||
],
|
||||
}}
|
||||
errors={errors}
|
||||
category={String(data.opportunity_category ?? '')}
|
||||
category={valueText(data.opportunity_category ?? '')}
|
||||
organization={
|
||||
(data.organization_id ?? null) as string | null
|
||||
}
|
||||
@@ -770,6 +953,20 @@ export default function OpportunityDraft({
|
||||
)}
|
||||
{profileMode && record && etag && (
|
||||
<OpportunityProfileActions
|
||||
conditions={
|
||||
Object.values(profileContext?.conditions ?? {}) as {
|
||||
id: string;
|
||||
gate: string;
|
||||
description: string;
|
||||
responsible_name: string;
|
||||
due_on: string | null;
|
||||
blocking_action: string;
|
||||
status: string;
|
||||
}[]
|
||||
}
|
||||
conditionResponsibles={
|
||||
workflowParticipants?.condition_responsibles
|
||||
}
|
||||
participants={workflowParticipants?.validators}
|
||||
publishers={workflowParticipants?.publishers}
|
||||
opinions={Object.values(
|
||||
@@ -787,7 +984,7 @@ export default function OpportunityDraft({
|
||||
id={record.id}
|
||||
etag={token ?? etag}
|
||||
actions={profileActions}
|
||||
publicationVisibility={String(
|
||||
publicationVisibility={valueText(
|
||||
(data.canonical as Record<string, unknown> | undefined)
|
||||
?.visibility ?? 'internal',
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user