fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -645,15 +645,61 @@ export default function OpportunityCanonicalFields({
|
||||
missingPaths?: string[];
|
||||
}) {
|
||||
const initiative = (value.initiative ?? {}) as Data;
|
||||
const isInitiative = category === 'investment_project' && ['program', 'portfolio'].includes(valueText(initiative.kind ?? ''));
|
||||
const applicability = (initiative.applicability ?? {}) as Record<string, string>;
|
||||
const isInitiative =
|
||||
category === 'investment_project' &&
|
||||
['program', 'portfolio'].includes(valueText(initiative.kind ?? ''));
|
||||
const applicability = (initiative.applicability ?? {}) as Record<
|
||||
string,
|
||||
string
|
||||
>;
|
||||
const groups: Record<string, { label: string; fields: string[] }> = {
|
||||
physical_site: { label: 'Implantação física, obra e licenças próprias', fields: ['location_mode', 'licenses', 'environmental_social'] },
|
||||
individual_business: { label: 'Empresa ou operação individual', fields: ['promoter_id', 'promoter_type', 'opportunity_type', 'investor_profiles', 'products', 'assets', 'inputs', 'markets', 'competitive_advantage', 'employment', 'impact_indicators', 'enterprise_size'] },
|
||||
unit_investment: { label: 'Investimento e financiamento por projecto', fields: ['total_investment', 'currency', 'investment_breakdown', 'secured_financing', 'funding_sought', 'financial_indicators'] },
|
||||
physical_site: {
|
||||
label: 'Implantação física, obra e licenças próprias',
|
||||
fields: ['location_mode', 'licenses', 'environmental_social'],
|
||||
},
|
||||
individual_business: {
|
||||
label: 'Empresa ou operação individual',
|
||||
fields: [
|
||||
'promoter_id',
|
||||
'promoter_type',
|
||||
'opportunity_type',
|
||||
'investor_profiles',
|
||||
'products',
|
||||
'assets',
|
||||
'inputs',
|
||||
'markets',
|
||||
'competitive_advantage',
|
||||
'employment',
|
||||
'impact_indicators',
|
||||
'enterprise_size',
|
||||
],
|
||||
},
|
||||
unit_investment: {
|
||||
label: 'Investimento e financiamento por projecto',
|
||||
fields: [
|
||||
'total_investment',
|
||||
'currency',
|
||||
'investment_breakdown',
|
||||
'secured_financing',
|
||||
'funding_sought',
|
||||
'financial_indicators',
|
||||
],
|
||||
},
|
||||
};
|
||||
const ignoredFields = isInitiative ? ['promoter_type', ...Object.entries(groups).flatMap(([key, group]) => applicability[key] === 'not_applicable' ? group.fields : [])] : [];
|
||||
const setInitiative = (key: string, next: unknown) => onChange({ ...value, opportunity_category: category, initiative: { ...initiative, [key]: next } });
|
||||
const ignoredFields = isInitiative
|
||||
? [
|
||||
'promoter_type',
|
||||
...Object.entries(groups).flatMap(([key, group]) =>
|
||||
applicability[key] === 'not_applicable' ? group.fields : [],
|
||||
),
|
||||
]
|
||||
: [];
|
||||
const setInitiative = (key: string, next: unknown) =>
|
||||
onChange({
|
||||
...value,
|
||||
opportunity_category: category,
|
||||
initiative: { ...initiative, [key]: next },
|
||||
});
|
||||
const set = (key: string, v: unknown) =>
|
||||
onChange({
|
||||
...value,
|
||||
@@ -827,7 +873,10 @@ export default function OpportunityCanonicalFields({
|
||||
: ['classified_other'];
|
||||
return (
|
||||
<fieldset disabled={disabled} className="space-y-4 rounded border p-4">
|
||||
<legend>Preparar oportunidade — {modalityLabels[category] ?? 'Modalidade por escolher'}</legend>
|
||||
<legend>
|
||||
Preparar oportunidade —{' '}
|
||||
{modalityLabels[category] ?? 'Modalidade por escolher'}
|
||||
</legend>
|
||||
<p>
|
||||
O rascunho pode ficar incompleto. A submissão verifica os campos
|
||||
aplicáveis e os recursos guardados. Validação interna não
|
||||
@@ -843,343 +892,513 @@ export default function OpportunityCanonicalFields({
|
||||
</p>
|
||||
)}
|
||||
{category === 'investment_project' && (
|
||||
<section aria-label="Enquadramento e aplicabilidade" className="space-y-4 rounded border p-4">
|
||||
<label className="block">Natureza da ficha
|
||||
<select className={control} aria-label="Natureza da ficha" value={valueText(initiative.kind ?? '')} onChange={(e) => {
|
||||
if (!e.target.value) { const next = { ...value }; delete next.initiative; onChange(next); }
|
||||
else setInitiative('kind', e.target.value);
|
||||
}}>
|
||||
<option value="">Projecto ou componente concreta</option>
|
||||
<option value="program">Programa ou iniciativa agregadora</option>
|
||||
<option value="portfolio">Carteira de oportunidades/PME</option>
|
||||
<section
|
||||
aria-label="Enquadramento e aplicabilidade"
|
||||
className="space-y-4 rounded border p-4"
|
||||
>
|
||||
<label className="block">
|
||||
Natureza da ficha
|
||||
<select
|
||||
className={control}
|
||||
aria-label="Natureza da ficha"
|
||||
value={valueText(initiative.kind ?? '')}
|
||||
onChange={(e) => {
|
||||
if (!e.target.value) {
|
||||
const next = { ...value };
|
||||
delete next.initiative;
|
||||
onChange(next);
|
||||
} else setInitiative('kind', e.target.value);
|
||||
}}
|
||||
>
|
||||
<option value="">
|
||||
Projecto ou componente concreta
|
||||
</option>
|
||||
<option value="program">
|
||||
Programa ou iniciativa agregadora
|
||||
</option>
|
||||
<option value="portfolio">
|
||||
Carteira de oportunidades/PME
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
{isInitiative && <>
|
||||
<p>O responsável do programa/carteira não substitui os promotores das componentes. Abrangência não comprova implantação. A classificação não confirma financiamento, licenças ou disponibilidade.</p>
|
||||
<label className="block">Responsável do programa ou carteira
|
||||
<input className={control} aria-label="Responsável do programa ou carteira" value={valueText(initiative.responsible_name ?? '')} onChange={(e) => setInitiative('responsible_name', e.target.value || null)} />
|
||||
</label>
|
||||
<FieldErrors path="canonical.initiative.responsible_name" errors={errors} />
|
||||
<label className="block">Abrangência territorial documentada
|
||||
<textarea className={control} aria-label="Abrangência territorial documentada" value={valueText(initiative.coverage_statement ?? '')} onChange={(e) => setInitiative('coverage_statement', e.target.value || null)} />
|
||||
</label>
|
||||
<FieldErrors path="canonical.initiative.coverage_statement" errors={errors} />
|
||||
<label className="block">Orçamento agregado — fonte e situação, sem confirmação automática
|
||||
<textarea className={control} aria-label="Orçamento agregado" value={valueText(initiative.aggregate_budget_statement ?? '')} onChange={(e) => setInitiative('aggregate_budget_statement', e.target.value || null)} />
|
||||
</label>
|
||||
{Object.entries(groups).map(([key, group]) => <div key={key}>
|
||||
<label className="block">{group.label}
|
||||
<select className={control} aria-label={group.label} value={applicability[key] ?? 'missing'} onChange={(e) => setInitiative('applicability', { ...applicability, [key]: e.target.value })}>
|
||||
<option value="missing">Informação em falta — aplicabilidade por determinar</option>
|
||||
<option value="not_applicable">Não aplicável a esta ficha agregadora</option>
|
||||
<option value="applicable">Aplicável — preencher os dados próprios</option>
|
||||
</select>
|
||||
{isInitiative && (
|
||||
<>
|
||||
<p>
|
||||
O responsável do programa/carteira não substitui
|
||||
os promotores das componentes. Abrangência não
|
||||
comprova implantação. A classificação não
|
||||
confirma financiamento, licenças ou
|
||||
disponibilidade.
|
||||
</p>
|
||||
<label className="block">
|
||||
Responsável do programa ou carteira
|
||||
<input
|
||||
className={control}
|
||||
aria-label="Responsável do programa ou carteira"
|
||||
value={valueText(
|
||||
initiative.responsible_name ?? '',
|
||||
)}
|
||||
onChange={(e) =>
|
||||
setInitiative(
|
||||
'responsible_name',
|
||||
e.target.value || null,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<FieldErrors path={'canonical.initiative.applicability.' + key} errors={errors} />
|
||||
{applicability[key] === 'not_applicable' && <details><summary>Não aplicável — consultar dados anteriores preservados</summary><pre className="overflow-auto whitespace-pre-wrap">{JSON.stringify(Object.fromEntries(group.fields.filter((field) => field in value).map((field) => [field, value[field]])), null, 2)}</pre><p>Sem eliminação dos valores. As componentes concretas mantêm os seus requisitos.</p></details>}
|
||||
</div>)}
|
||||
<p>Os recursos territoriais abaixo documentam a abrangência quando a implantação não é aplicável. A informação em falta continua pendente; não é convertida em “não aplicável”.</p>
|
||||
</>}
|
||||
<FieldErrors
|
||||
path="canonical.initiative.responsible_name"
|
||||
errors={errors}
|
||||
/>
|
||||
<label className="block">
|
||||
Abrangência territorial documentada
|
||||
<textarea
|
||||
className={control}
|
||||
aria-label="Abrangência territorial documentada"
|
||||
value={valueText(
|
||||
initiative.coverage_statement ?? '',
|
||||
)}
|
||||
onChange={(e) =>
|
||||
setInitiative(
|
||||
'coverage_statement',
|
||||
e.target.value || null,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<FieldErrors
|
||||
path="canonical.initiative.coverage_statement"
|
||||
errors={errors}
|
||||
/>
|
||||
<label className="block">
|
||||
Orçamento agregado — fonte e situação, sem
|
||||
confirmação automática
|
||||
<textarea
|
||||
className={control}
|
||||
aria-label="Orçamento agregado"
|
||||
value={valueText(
|
||||
initiative.aggregate_budget_statement ??
|
||||
'',
|
||||
)}
|
||||
onChange={(e) =>
|
||||
setInitiative(
|
||||
'aggregate_budget_statement',
|
||||
e.target.value || null,
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
{Object.entries(groups).map(([key, group]) => (
|
||||
<div key={key}>
|
||||
<label className="block">
|
||||
{group.label}
|
||||
<select
|
||||
className={control}
|
||||
aria-label={group.label}
|
||||
value={
|
||||
applicability[key] ?? 'missing'
|
||||
}
|
||||
onChange={(e) =>
|
||||
setInitiative('applicability', {
|
||||
...applicability,
|
||||
[key]: e.target.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="missing">
|
||||
Informação em falta —
|
||||
aplicabilidade por determinar
|
||||
</option>
|
||||
<option value="not_applicable">
|
||||
Não aplicável a esta ficha
|
||||
agregadora
|
||||
</option>
|
||||
<option value="applicable">
|
||||
Aplicável — preencher os dados
|
||||
próprios
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<FieldErrors
|
||||
path={
|
||||
'canonical.initiative.applicability.' +
|
||||
key
|
||||
}
|
||||
errors={errors}
|
||||
/>
|
||||
{applicability[key] ===
|
||||
'not_applicable' && (
|
||||
<details>
|
||||
<summary>
|
||||
Não aplicável — consultar dados
|
||||
anteriores preservados
|
||||
</summary>
|
||||
<pre className="overflow-auto whitespace-pre-wrap">
|
||||
{JSON.stringify(
|
||||
Object.fromEntries(
|
||||
group.fields
|
||||
.filter(
|
||||
(field) =>
|
||||
field in
|
||||
value,
|
||||
)
|
||||
.map((field) => [
|
||||
field,
|
||||
value[field],
|
||||
]),
|
||||
),
|
||||
null,
|
||||
2,
|
||||
)}
|
||||
</pre>
|
||||
<p>
|
||||
Sem eliminação dos valores. As
|
||||
componentes concretas mantêm os
|
||||
seus requisitos.
|
||||
</p>
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<p>
|
||||
Os recursos territoriais abaixo documentam a
|
||||
abrangência quando a implantação não é
|
||||
aplicável. A informação em falta continua
|
||||
pendente; não é convertida em “não aplicável”.
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
<OpportunityFillFlow groups={opportunityFillGroups([...new Set([...common, ...specialized])].filter((key) => !ignoredFields.includes(key)))} errors={errors} missingPaths={missingPaths} onOpenResources={onOpenResources} renderField={(key) => {
|
||||
if (ignoredFields.includes(key)) return null;
|
||||
<OpportunityFillFlow
|
||||
groups={opportunityFillGroups(
|
||||
[...new Set([...common, ...specialized])].filter(
|
||||
(key) => !ignoredFields.includes(key),
|
||||
),
|
||||
)}
|
||||
errors={errors}
|
||||
missingPaths={missingPaths}
|
||||
onOpenResources={onOpenResources}
|
||||
renderField={(key) => {
|
||||
if (ignoredFields.includes(key)) return null;
|
||||
|
||||
if (key === 'relations' && options.classification) {
|
||||
const rows = (value.relations ??
|
||||
[]) as ClassificationRelation[];
|
||||
const legacySchema = options.definitions.relationCreate;
|
||||
return (
|
||||
<div key={key} className="space-y-4">
|
||||
<ClassificationEditor
|
||||
rows={rows}
|
||||
onChange={(rows) => set('relations', rows)}
|
||||
options={options.classification}
|
||||
documents={options.resources.documents ?? []}
|
||||
authorities={options.authorities}
|
||||
errors={errors}
|
||||
/>
|
||||
{rows.map((row, i) =>
|
||||
!row.classification ? (
|
||||
<Editor
|
||||
key={i}
|
||||
name={`Relação anterior ${i + 1}`}
|
||||
path={`canonical.relations.${i}`}
|
||||
schema={{
|
||||
...legacySchema,
|
||||
properties: Object.fromEntries(
|
||||
Object.entries(
|
||||
legacySchema.properties ??
|
||||
{},
|
||||
).filter(
|
||||
([k]) =>
|
||||
k !== 'classification',
|
||||
if (key === 'relations' && options.classification) {
|
||||
const rows = (value.relations ??
|
||||
[]) as ClassificationRelation[];
|
||||
const legacySchema = options.definitions.relationCreate;
|
||||
return (
|
||||
<div key={key} className="space-y-4">
|
||||
<ClassificationEditor
|
||||
rows={rows}
|
||||
onChange={(rows) => set('relations', rows)}
|
||||
options={options.classification}
|
||||
documents={
|
||||
options.resources.documents ?? []
|
||||
}
|
||||
authorities={options.authorities}
|
||||
errors={errors}
|
||||
/>
|
||||
{rows.map((row, i) =>
|
||||
!row.classification ? (
|
||||
<Editor
|
||||
key={i}
|
||||
name={`Relação anterior ${i + 1}`}
|
||||
path={`canonical.relations.${i}`}
|
||||
schema={{
|
||||
...legacySchema,
|
||||
properties: Object.fromEntries(
|
||||
Object.entries(
|
||||
legacySchema.properties ??
|
||||
{},
|
||||
).filter(
|
||||
([k]) =>
|
||||
k !==
|
||||
'classification',
|
||||
),
|
||||
),
|
||||
),
|
||||
}}
|
||||
value={row}
|
||||
options={options}
|
||||
errors={errors}
|
||||
onChange={(v) =>
|
||||
set(
|
||||
'relations',
|
||||
rows.map((r, j) =>
|
||||
j === i ? v : r,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : null,
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (key === 'module_profile_version') {
|
||||
const current = valueText(value[key] ?? '');
|
||||
const version =
|
||||
options.modularProfiles?.[category] ??
|
||||
([
|
||||
'business_sale',
|
||||
'business_partnership',
|
||||
'franchise',
|
||||
].includes(category)
|
||||
? options.historyVersion
|
||||
: null);
|
||||
return (
|
||||
<label key={key} className="block">
|
||||
{labels[key]}
|
||||
<select
|
||||
className={control}
|
||||
value={current}
|
||||
onChange={(e) =>
|
||||
set(key, e.target.value || null)
|
||||
}
|
||||
>
|
||||
<option value="">
|
||||
Contrato original / por selecionar
|
||||
</option>
|
||||
{current && current !== version && (
|
||||
<option value={current}>
|
||||
{current} — versão existente preservada
|
||||
}}
|
||||
value={row}
|
||||
options={options}
|
||||
errors={errors}
|
||||
onChange={(v) =>
|
||||
set(
|
||||
'relations',
|
||||
rows.map((r, j) =>
|
||||
j === i ? v : r,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : null,
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (key === 'module_profile_version') {
|
||||
const current = valueText(value[key] ?? '');
|
||||
const version =
|
||||
options.modularProfiles?.[category] ??
|
||||
([
|
||||
'business_sale',
|
||||
'business_partnership',
|
||||
'franchise',
|
||||
].includes(category)
|
||||
? options.historyVersion
|
||||
: null);
|
||||
return (
|
||||
<label key={key} className="block">
|
||||
{labels[key]}
|
||||
<select
|
||||
className={control}
|
||||
value={current}
|
||||
onChange={(e) =>
|
||||
set(key, e.target.value || null)
|
||||
}
|
||||
>
|
||||
<option value="">
|
||||
Contrato original / por selecionar
|
||||
</option>
|
||||
)}
|
||||
{version && (
|
||||
<option value={version}>{version}</option>
|
||||
)}
|
||||
</select>
|
||||
<FieldErrors
|
||||
path={'canonical.' + key}
|
||||
errors={errors}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
if (
|
||||
[
|
||||
'sector_id',
|
||||
'subsector_id',
|
||||
'economic_activity_id',
|
||||
'internal_contact_id',
|
||||
'public_contact_id',
|
||||
].includes(key)
|
||||
) {
|
||||
const rows =
|
||||
key === 'sector_id'
|
||||
? sectors.map((s) => ({ id: s.id, label: s.name }))
|
||||
: [
|
||||
'internal_contact_id',
|
||||
'public_contact_id',
|
||||
].includes(key)
|
||||
? options.contacts.map((c) => ({
|
||||
id: c.id,
|
||||
label: c.full_name,
|
||||
}))
|
||||
: options.activities
|
||||
.filter((a) => {
|
||||
if (a.id === value[key]) return true;
|
||||
if (a.historical_only) return false;
|
||||
if (a.level) {
|
||||
{current && current !== version && (
|
||||
<option value={current}>
|
||||
{current} — versão existente
|
||||
preservada
|
||||
</option>
|
||||
)}
|
||||
{version && (
|
||||
<option value={version}>
|
||||
{version}
|
||||
</option>
|
||||
)}
|
||||
</select>
|
||||
<FieldErrors
|
||||
path={'canonical.' + key}
|
||||
errors={errors}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
if (
|
||||
[
|
||||
'sector_id',
|
||||
'subsector_id',
|
||||
'economic_activity_id',
|
||||
'internal_contact_id',
|
||||
'public_contact_id',
|
||||
].includes(key)
|
||||
) {
|
||||
const rows =
|
||||
key === 'sector_id'
|
||||
? sectors.map((s) => ({
|
||||
id: s.id,
|
||||
label: s.name,
|
||||
}))
|
||||
: [
|
||||
'internal_contact_id',
|
||||
'public_contact_id',
|
||||
].includes(key)
|
||||
? options.contacts.map((c) => ({
|
||||
id: c.id,
|
||||
label: c.full_name,
|
||||
}))
|
||||
: options.activities
|
||||
.filter((a) => {
|
||||
if (a.id === value[key])
|
||||
return true;
|
||||
if (a.historical_only) return false;
|
||||
if (a.level) {
|
||||
return key === 'subsector_id'
|
||||
? a.level === 2 &&
|
||||
a.code === '01' &&
|
||||
a.sector_id ===
|
||||
Number(
|
||||
value.sector_id,
|
||||
)
|
||||
: a.level === 5 &&
|
||||
a.code === '01120' &&
|
||||
!!a.path?.some(
|
||||
(p) =>
|
||||
p.id ===
|
||||
value.subsector_id,
|
||||
);
|
||||
}
|
||||
return key === 'subsector_id'
|
||||
? a.level === 2 &&
|
||||
a.code === '01' &&
|
||||
a.sector_id ===
|
||||
Number(
|
||||
value.sector_id,
|
||||
)
|
||||
: a.level === 5 &&
|
||||
a.code === '01120' &&
|
||||
!!a.path?.some(
|
||||
(p) =>
|
||||
p.id ===
|
||||
value.subsector_id,
|
||||
);
|
||||
}
|
||||
return key === 'subsector_id'
|
||||
? options.activities.some(
|
||||
(root) =>
|
||||
root.sector_id ===
|
||||
Number(
|
||||
value.sector_id,
|
||||
) &&
|
||||
a.parent_id === root.id,
|
||||
)
|
||||
: a.parent_id ===
|
||||
value.subsector_id;
|
||||
})
|
||||
.map((a) => ({
|
||||
id: a.id,
|
||||
label:
|
||||
(a.display_label ?? a.label_pt_mz) +
|
||||
(a.historical_only
|
||||
? ' — histórico preservado'
|
||||
: ''),
|
||||
}));
|
||||
return (
|
||||
<label key={key} className="block">
|
||||
{labels[key]}
|
||||
<FieldErrors
|
||||
path={'canonical.' + key}
|
||||
errors={errors}
|
||||
/>
|
||||
<select
|
||||
className={control}
|
||||
value={valueText(value[key] ?? '')}
|
||||
onChange={(e) =>
|
||||
set(
|
||||
key,
|
||||
e.target.value === ''
|
||||
? null
|
||||
: key === 'sector_id'
|
||||
? Number(e.target.value)
|
||||
: e.target.value,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">Por indicar</option>
|
||||
{rows.map((r) => (
|
||||
<option key={r.id} value={r.id}>
|
||||
{r.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{key === 'economic_activity_id' &&
|
||||
options.activities.find(
|
||||
(a) => a.id === value[key],
|
||||
)?.level && (
|
||||
<p
|
||||
className="mt-1 text-sm"
|
||||
data-economic-path="five-levels"
|
||||
>
|
||||
{options.activities
|
||||
.find((a) => a.id === value[key])
|
||||
?.path?.map(
|
||||
(p) => `${p.code} — ${p.label}`,
|
||||
)
|
||||
.join(' → ')}
|
||||
{
|
||||
' · Exemplar eBAU; edição normativa não determinada; divergência 600/579 aberta.'
|
||||
}
|
||||
? options.activities.some(
|
||||
(root) =>
|
||||
root.sector_id ===
|
||||
Number(
|
||||
value.sector_id,
|
||||
) &&
|
||||
a.parent_id ===
|
||||
root.id,
|
||||
)
|
||||
: a.parent_id ===
|
||||
value.subsector_id;
|
||||
})
|
||||
.map((a) => ({
|
||||
id: a.id,
|
||||
label:
|
||||
(a.display_label ??
|
||||
a.label_pt_mz) +
|
||||
(a.historical_only
|
||||
? ' — histórico preservado'
|
||||
: ''),
|
||||
}));
|
||||
return (
|
||||
<label key={key} className="block">
|
||||
{labels[key]}
|
||||
<FieldErrors
|
||||
path={'canonical.' + key}
|
||||
errors={errors}
|
||||
/>
|
||||
<select
|
||||
className={control}
|
||||
value={valueText(value[key] ?? '')}
|
||||
onChange={(e) =>
|
||||
set(
|
||||
key,
|
||||
e.target.value === ''
|
||||
? null
|
||||
: key === 'sector_id'
|
||||
? Number(e.target.value)
|
||||
: e.target.value,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">Por indicar</option>
|
||||
{rows.map((r) => (
|
||||
<option key={r.id} value={r.id}>
|
||||
{r.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{key === 'economic_activity_id' &&
|
||||
options.activities.find(
|
||||
(a) => a.id === value[key],
|
||||
)?.level && (
|
||||
<p
|
||||
className="mt-1 text-sm"
|
||||
data-economic-path="five-levels"
|
||||
>
|
||||
{options.activities
|
||||
.find(
|
||||
(a) => a.id === value[key],
|
||||
)
|
||||
?.path?.map(
|
||||
(p) =>
|
||||
`${p.code} — ${p.label}`,
|
||||
)
|
||||
.join(' → ')}
|
||||
{
|
||||
' · Exemplar eBAU; edição normativa não determinada; divergência 600/579 aberta.'
|
||||
}
|
||||
</p>
|
||||
)}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
if (['locations', 'documents', 'images'].includes(key)) {
|
||||
const selected = Array.isArray(value[key])
|
||||
? (value[key] as string[])
|
||||
: [];
|
||||
return (
|
||||
<fieldset key={key}>
|
||||
<legend>
|
||||
{isInitiative && key === 'locations'
|
||||
? 'Abrangência territorial — recursos guardados'
|
||||
: labels[key]}
|
||||
</legend>
|
||||
{key === 'locations' && (
|
||||
<p>
|
||||
Seleccione os locais já guardados em
|
||||
Recursos; não volte a introduzir a
|
||||
hierarquia. O local principal, os
|
||||
adicionais e a finalidade de cada um são
|
||||
definidos nesse registo. Abrangência,
|
||||
impacto e contexto não significam
|
||||
implantação. Pode guardar incompleto; a
|
||||
submissão conserva as verificações
|
||||
existentes.
|
||||
</p>
|
||||
)}
|
||||
</label>
|
||||
);
|
||||
}
|
||||
if (['locations', 'documents', 'images'].includes(key)) {
|
||||
const selected = Array.isArray(value[key])
|
||||
? (value[key] as string[])
|
||||
: [];
|
||||
return (
|
||||
<fieldset key={key}>
|
||||
<legend>{isInitiative && key === 'locations' ? 'Abrangência territorial — recursos guardados' : labels[key]}</legend>
|
||||
{key === 'locations' && (
|
||||
<p>
|
||||
Seleccione os locais já guardados em
|
||||
Recursos; não volte a introduzir a
|
||||
hierarquia. O local principal, os adicionais
|
||||
e a finalidade de cada um são definidos
|
||||
nesse registo. Abrangência, impacto e
|
||||
contexto não significam implantação. Pode
|
||||
guardar incompleto; a submissão conserva as
|
||||
verificações existentes.
|
||||
</p>
|
||||
)}
|
||||
<FieldErrors
|
||||
path={'canonical.' + key}
|
||||
errors={errors}
|
||||
/>
|
||||
{(options.resources[key] ?? []).map((r) => (
|
||||
<label key={r.id} className="block">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selected.includes(r.id)}
|
||||
onChange={(e) =>
|
||||
set(
|
||||
key,
|
||||
e.target.checked
|
||||
? [...selected, r.id]
|
||||
: selected.filter(
|
||||
(id) => id !== r.id,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>{' '}
|
||||
{r.payload.title ??
|
||||
r.payload.role ??
|
||||
r.file?.file_name ??
|
||||
r.id}
|
||||
<FieldErrors
|
||||
path={`canonical.${key}.${r.id}`}
|
||||
errors={errors}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
{key === 'locations' &&
|
||||
selected.map((id) => (
|
||||
<TerritoryGeometryPreview
|
||||
key={id}
|
||||
territoryId={resourceTerritory(
|
||||
options.resources.locations?.find(
|
||||
(r) => r.id === id,
|
||||
),
|
||||
)}
|
||||
endpoint="/minhas-oportunidades/territory-geometries"
|
||||
label={`Cobertura cartográfica da localização ${options.resources.locations?.find((r) => r.id === id)?.payload.title ?? selected.indexOf(id) + 1}`}
|
||||
/>
|
||||
<FieldErrors
|
||||
path={'canonical.' + key}
|
||||
errors={errors}
|
||||
/>
|
||||
{(options.resources[key] ?? []).map((r) => (
|
||||
<label key={r.id} className="block">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selected.includes(r.id)}
|
||||
onChange={(e) =>
|
||||
set(
|
||||
key,
|
||||
e.target.checked
|
||||
? [...selected, r.id]
|
||||
: selected.filter(
|
||||
(id) =>
|
||||
id !== r.id,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>{' '}
|
||||
{r.payload.title ??
|
||||
r.payload.role ??
|
||||
r.file?.file_name ??
|
||||
r.id}
|
||||
<FieldErrors
|
||||
path={`canonical.${key}.${r.id}`}
|
||||
errors={errors}
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
{!options.resources[key]?.length && (
|
||||
<p>
|
||||
Guarde primeiro em Recursos e regresse a
|
||||
este contrato.
|
||||
</p>
|
||||
)}
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
let schema = options.schema.properties?.[key];
|
||||
if (key === 'module_details' && schema?.properties) {
|
||||
schema = {
|
||||
...schema,
|
||||
properties: Object.fromEntries(
|
||||
Object.entries(schema.properties).filter(
|
||||
([field]) => modularFields.includes(field),
|
||||
{key === 'locations' &&
|
||||
selected.map((id) => (
|
||||
<TerritoryGeometryPreview
|
||||
key={id}
|
||||
territoryId={resourceTerritory(
|
||||
options.resources.locations?.find(
|
||||
(r) => r.id === id,
|
||||
),
|
||||
)}
|
||||
endpoint="/minhas-oportunidades/territory-geometries"
|
||||
label={`Cobertura cartográfica da localização ${options.resources.locations?.find((r) => r.id === id)?.payload.title ?? selected.indexOf(id) + 1}`}
|
||||
/>
|
||||
))}
|
||||
{!options.resources[key]?.length && (
|
||||
<p>
|
||||
Guarde primeiro em Recursos e regresse a
|
||||
este contrato.
|
||||
</p>
|
||||
)}
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
let schema = options.schema.properties?.[key];
|
||||
if (key === 'module_details' && schema?.properties) {
|
||||
schema = {
|
||||
...schema,
|
||||
properties: Object.fromEntries(
|
||||
Object.entries(schema.properties).filter(
|
||||
([field]) => modularFields.includes(field),
|
||||
),
|
||||
),
|
||||
),
|
||||
};
|
||||
schema.properties!.mode = { enum: modes };
|
||||
}
|
||||
return schema ? (
|
||||
<Editor
|
||||
key={key}
|
||||
name={key}
|
||||
path={'canonical.' + key}
|
||||
errors={errors}
|
||||
schema={schema}
|
||||
value={value[key]}
|
||||
options={options}
|
||||
onChange={(v) => set(key, v)}
|
||||
/>
|
||||
) : null;
|
||||
}} />
|
||||
};
|
||||
schema.properties!.mode = { enum: modes };
|
||||
}
|
||||
return schema ? (
|
||||
<Editor
|
||||
key={key}
|
||||
name={key}
|
||||
path={'canonical.' + key}
|
||||
errors={errors}
|
||||
schema={schema}
|
||||
value={value[key]}
|
||||
options={options}
|
||||
onChange={(v) => set(key, v)}
|
||||
/>
|
||||
) : null;
|
||||
}}
|
||||
/>
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user