1324 lines
66 KiB
TypeScript
1324 lines
66 KiB
TypeScript
import { DossierPrefill } from '@/components/dossier-prefill';
|
|
import { contextApi } from '@/lib/investor-context';
|
|
import { valueText } from '@/lib/value-text';
|
|
import { Link, useForm } from '@inertiajs/react';
|
|
import { useState } from 'react';
|
|
import { Frame, Field, input, button, card } from './shared';
|
|
import type { References } from './shared';
|
|
import { Conversation } from './conversation';
|
|
import type { Message } from './conversation';
|
|
import CountrySelect, { type Country } from '@/components/country-select';
|
|
type Payload = {
|
|
context_opportunity?: string;
|
|
context_opportunity_snapshot?: string;
|
|
simple_participation?: boolean;
|
|
opportunity_title?: string;
|
|
opportunity_reference?: string;
|
|
full_name: string;
|
|
email: string;
|
|
phone: string;
|
|
country: string;
|
|
residence_country_code: string;
|
|
incorporation_country_code: string;
|
|
organization_country_snapshot?: {
|
|
organization_id: string;
|
|
organization_version: number;
|
|
country: string;
|
|
};
|
|
declared_origin_country_code: string;
|
|
organisation: string;
|
|
representative_role: string;
|
|
experience: string;
|
|
investment_capacity: string;
|
|
other_details: string;
|
|
profile_id: string;
|
|
sector: string;
|
|
objective: string;
|
|
participation_id: string;
|
|
partnership_id: string;
|
|
estimated_amount: string;
|
|
currency: string;
|
|
horizon: string;
|
|
location: string;
|
|
cluster_ids: string[];
|
|
corridor_ids: string[];
|
|
project_ids: string[];
|
|
contact_consent: boolean;
|
|
};
|
|
type Need = {
|
|
category_id: string;
|
|
option_id: string;
|
|
unit_id: string;
|
|
priority_id: string;
|
|
quantity: string;
|
|
deadline: string;
|
|
details: {
|
|
description: string;
|
|
location: string;
|
|
observations: string;
|
|
qualification: string;
|
|
specialty: string;
|
|
experience: string;
|
|
certifications: string;
|
|
availability: string;
|
|
institution: string;
|
|
training_mode: string;
|
|
duration: string;
|
|
status: string;
|
|
};
|
|
};
|
|
type Props = {
|
|
contextDossierId?: string | null;
|
|
contextChoices?: { id: string; title: string; version: number }[];
|
|
boundContextRevision?: number;
|
|
countries: Country[];
|
|
zone_origin?: {
|
|
zone_id: string;
|
|
zone_version: number;
|
|
intent: 'interest' | 'dossier' | 'meeting';
|
|
} | null;
|
|
submission: {
|
|
id: string;
|
|
version: number;
|
|
payload: Partial<Payload>;
|
|
opportunity_id?: number | null;
|
|
dossier_id?: string | null;
|
|
status: string;
|
|
};
|
|
references: References;
|
|
needs: Need[];
|
|
attachments: { id: string; file_name: string }[];
|
|
events: { action: string; version: number; created_at: string }[];
|
|
receipt: {
|
|
reference: string;
|
|
status: string;
|
|
next_action?: string | null;
|
|
next_action_due_at?: string | null;
|
|
} | null;
|
|
target: string | null;
|
|
management: boolean;
|
|
messages: Message[];
|
|
revisions: { version: number; created_at: string }[];
|
|
};
|
|
const emptyNeed = (): Need => ({
|
|
category_id: '',
|
|
option_id: '',
|
|
unit_id: '',
|
|
priority_id: '',
|
|
quantity: '',
|
|
deadline: '',
|
|
details: {
|
|
description: '',
|
|
location: '',
|
|
observations: '',
|
|
qualification: '',
|
|
specialty: '',
|
|
experience: '',
|
|
certifications: '',
|
|
availability: '',
|
|
institution: '',
|
|
training_mode: '',
|
|
duration: '',
|
|
status: '',
|
|
},
|
|
});
|
|
export default function Submission(props: Props) {
|
|
const [step, setStep] = useState(0);
|
|
return (
|
|
<Editor
|
|
key={props.submission.version}
|
|
{...props}
|
|
step={step}
|
|
setStep={setStep}
|
|
/>
|
|
);
|
|
}
|
|
function Editor({
|
|
zone_origin,
|
|
contextDossierId: initialContextId,
|
|
contextChoices = [],
|
|
boundContextRevision = 0,
|
|
submission: s,
|
|
references: r,
|
|
needs,
|
|
attachments,
|
|
events,
|
|
receipt,
|
|
target,
|
|
management,
|
|
messages,
|
|
revisions,
|
|
step,
|
|
setStep,
|
|
countries,
|
|
}: Props & { step: number; setStep: (step: number) => void }) {
|
|
const [contextDossierId, setContextDossierId] = useState(initialContextId);
|
|
const [chosenContext, setChosenContext] = useState('');
|
|
const [bindingBusy, setBindingBusy] = useState(false);
|
|
const [bindingMessage, setBindingMessage] = useState('');
|
|
const initial: Payload = {
|
|
full_name: '',
|
|
email: '',
|
|
phone: '',
|
|
country: '',
|
|
residence_country_code: '',
|
|
incorporation_country_code: '',
|
|
declared_origin_country_code: '',
|
|
organisation: '',
|
|
representative_role: '',
|
|
experience: '',
|
|
investment_capacity: '',
|
|
other_details: '',
|
|
profile_id: '',
|
|
sector: '',
|
|
objective: '',
|
|
participation_id: '',
|
|
partnership_id: '',
|
|
estimated_amount: '',
|
|
currency: '',
|
|
horizon: '',
|
|
location: '',
|
|
cluster_ids: [],
|
|
corridor_ids: [],
|
|
project_ids: [],
|
|
contact_consent: false,
|
|
...s.payload,
|
|
};
|
|
const form = useForm({
|
|
version: s.version,
|
|
context_revision: 0,
|
|
context_reviewed: false,
|
|
payload: initial,
|
|
needs: needs.map((n) => ({
|
|
...emptyNeed(),
|
|
...Object.fromEntries(
|
|
Object.entries(n).filter(([k]) =>
|
|
[
|
|
'category_id',
|
|
'option_id',
|
|
'unit_id',
|
|
'priority_id',
|
|
'quantity',
|
|
'deadline',
|
|
'details',
|
|
].includes(k),
|
|
),
|
|
),
|
|
details: { ...emptyNeed().details, ...n.details },
|
|
})) as Need[],
|
|
});
|
|
const upload = useForm<{ version: number; file: File | null }>({
|
|
version: s.version,
|
|
file: null,
|
|
});
|
|
const [note, setNote] = useState('');
|
|
const readonly = s.status !== 'draft' || management;
|
|
const base = '/investidor/manifestacoes/' + s.id;
|
|
const update = <K extends keyof Payload>(key: K, value: Payload[K]) =>
|
|
form.setData('payload', { ...form.data.payload, [key]: value });
|
|
const text = (
|
|
key: keyof Payload,
|
|
label: string,
|
|
required = false,
|
|
type = 'text',
|
|
) => (
|
|
<Field label={label}>
|
|
<input
|
|
className={input}
|
|
type={type}
|
|
required={required}
|
|
disabled={readonly}
|
|
name={key}
|
|
min={type === 'number' ? 0 : undefined}
|
|
minLength={
|
|
key === 'objective'
|
|
? 20
|
|
: key === 'full_name'
|
|
? 3
|
|
: undefined
|
|
}
|
|
onBlur={(e) => {
|
|
if (!e.target.validity.valid)
|
|
setNote(
|
|
`Verifique o campo ${label}: ${e.target.validationMessage}`,
|
|
);
|
|
else setNote('');
|
|
}}
|
|
value={valueText(form.data.payload[key] ?? '')}
|
|
onChange={(e) => update(key, e.target.value as never)}
|
|
maxLength={key === 'objective' ? 5000 : 2000}
|
|
/>
|
|
</Field>
|
|
);
|
|
const option = (
|
|
key: 'profile_id' | 'participation_id' | 'partnership_id',
|
|
group: string,
|
|
label: string,
|
|
) => (
|
|
<Field label={label}>
|
|
<select
|
|
className={input}
|
|
disabled={readonly}
|
|
value={form.data.payload[key] ?? ''}
|
|
onChange={(e) => update(key, e.target.value)}
|
|
>
|
|
<option value="">Seleccionar</option>
|
|
{r.options
|
|
.filter(
|
|
(o) =>
|
|
o.group === group &&
|
|
(o.active ||
|
|
valueText(o.id) ===
|
|
valueText(form.data.payload[key])),
|
|
)
|
|
.map((o) => (
|
|
<option value={o.id} key={o.id} disabled={!o.active}>
|
|
{o.label}
|
|
{!o.active ? ' (inactiva)' : ''}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
);
|
|
const updateNeed = (index: number, value: Need) =>
|
|
form.setData(
|
|
'needs',
|
|
form.data.needs.map((n, i) => (i === index ? value : n)),
|
|
);
|
|
const errorStep = (key: string) =>
|
|
key.startsWith('needs.')
|
|
? 2
|
|
: /payload\.(full_name|email|phone|country|profile_id|organisation|representative_role|sector|experience|investment_capacity)/.test(
|
|
key,
|
|
)
|
|
? 0
|
|
: key === 'payload.contact_consent'
|
|
? 4
|
|
: 1;
|
|
return (
|
|
<Frame
|
|
title={
|
|
receipt
|
|
? 'Manifestação ' + receipt.reference
|
|
: 'Preparar manifestação de interesse'
|
|
}
|
|
>
|
|
<p>
|
|
{target ??
|
|
(zone_origin
|
|
? 'Pedido relativo a zona de investimento'
|
|
: 'Interesse geral')}{' '}
|
|
· Versão {s.version} ·{' '}
|
|
{s.status === 'draft' ? 'Rascunho privado' : 'Submetido'}
|
|
</p>
|
|
<Link
|
|
className="underline"
|
|
href={`/balcao-virtual/painel?submission_id=${s.id}`}
|
|
>
|
|
Preparar apoio e acompanhamento deste projecto no Balcão Virtual
|
|
</Link>
|
|
{zone_origin && (
|
|
<p className={card}>
|
|
<Link
|
|
className="underline"
|
|
href={`/zonas/${zone_origin.zone_id}`}
|
|
>
|
|
Consultar zona de origem
|
|
</Link>{' '}
|
|
· Versão da ficha {zone_origin.zone_version} ·{' '}
|
|
{
|
|
{
|
|
interest: 'Manifestação de interesse',
|
|
dossier: 'Pedido de dossier',
|
|
meeting: 'Pedido de reunião',
|
|
}[zone_origin.intent]
|
|
}
|
|
. Atendimento assistido, sem decisão administrativa
|
|
automática.
|
|
</p>
|
|
)}
|
|
{receipt && (
|
|
<p role="status" className={card}>
|
|
Protocolo: <strong>{receipt.reference}</strong> · Estado:{' '}
|
|
{(
|
|
{
|
|
received: 'Recebido',
|
|
in_review: 'Em análise',
|
|
contacted: 'Contactado',
|
|
closed: 'Encerrado',
|
|
} as Record<string, string>
|
|
)[receipt.status] ?? receipt.status}
|
|
</p>
|
|
)}
|
|
{receipt?.next_action && (
|
|
<p role="status">
|
|
Próxima acção: {receipt.next_action}{' '}
|
|
{receipt.next_action_due_at &&
|
|
new Date(receipt.next_action_due_at).toLocaleDateString(
|
|
'pt-MZ',
|
|
)}
|
|
</p>
|
|
)}
|
|
{s.status === 'submitted' && s.payload.simple_participation ? (
|
|
<section className={card}>
|
|
<h2 className="text-xl font-bold">Dados da manifestação</h2>
|
|
<dl className="mt-3 space-y-3">
|
|
{[
|
|
['Nome', s.payload.full_name],
|
|
['Email', s.payload.email],
|
|
['Telefone', s.payload.phone],
|
|
['País declarado', s.payload.country],
|
|
['Sector', s.payload.sector],
|
|
['Oportunidade', target],
|
|
['Mensagem', s.payload.objective],
|
|
]
|
|
.filter(([, value]) => value)
|
|
.map(([label, value]) => (
|
|
<div key={label}>
|
|
<dt className="font-semibold">{label}</dt>
|
|
<dd className="whitespace-pre-wrap">
|
|
{value}
|
|
</dd>
|
|
</div>
|
|
))}
|
|
</dl>
|
|
</section>
|
|
) : (
|
|
<>
|
|
<nav
|
|
aria-label="Etapas da manifestação"
|
|
className="flex flex-wrap gap-2"
|
|
>
|
|
{[
|
|
'Identificação',
|
|
'Investimento',
|
|
'Necessidades',
|
|
'Anexos',
|
|
'Rever e enviar',
|
|
].map((label, i) => (
|
|
<button
|
|
key={label}
|
|
type="button"
|
|
aria-current={step === i ? 'step' : undefined}
|
|
className={
|
|
step === i
|
|
? button
|
|
: 'rounded border px-4 py-2'
|
|
}
|
|
onClick={() => setStep(i)}
|
|
>
|
|
{i + 1}. {label}
|
|
</button>
|
|
))}
|
|
</nav>
|
|
<p className="text-sm">
|
|
Etapa {step + 1} de 5. Guarde antes de sair. A
|
|
informação declarada não é publicada.
|
|
</p>
|
|
{!contextDossierId &&
|
|
!management &&
|
|
s.status === 'draft' && (
|
|
<section
|
|
className={card + ' space-y-3'}
|
|
aria-label="Associar dossier existente"
|
|
>
|
|
<h2 className="text-xl font-bold">
|
|
Reutilizar um dossier existente (opcional)
|
|
</h2>
|
|
<p>
|
|
Pode continuar e submeter directamente sem
|
|
criar um dossier. Associar reutiliza o
|
|
contexto autorizado; campos já editados
|
|
conservam-se.
|
|
</p>
|
|
{s.dossier_id && (
|
|
<p>
|
|
<Link
|
|
className="underline"
|
|
href={
|
|
'/investimentos/iniciar?source=' +
|
|
encodeURIComponent(
|
|
'portfolio:' + s.dossier_id,
|
|
) +
|
|
'&submission=' +
|
|
encodeURIComponent(s.id)
|
|
}
|
|
>
|
|
Preparar investimento com a ficha de
|
|
origem
|
|
</Link>
|
|
. A manifestação ficará ligada ao
|
|
dossier que escolher.
|
|
</p>
|
|
)}
|
|
<label className="grid gap-1">
|
|
Dossier autorizado para esta manifestação
|
|
<select
|
|
className={input}
|
|
value={chosenContext}
|
|
disabled={bindingBusy}
|
|
onChange={(e) =>
|
|
setChosenContext(e.target.value)
|
|
}
|
|
>
|
|
<option value="">
|
|
Continuar sem dossier
|
|
</option>
|
|
{contextChoices.map((c) => (
|
|
<option key={c.id} value={c.id}>
|
|
{c.title}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
disabled={
|
|
!chosenContext ||
|
|
bindingBusy ||
|
|
form.processing
|
|
}
|
|
onClick={async () => {
|
|
const choice = contextChoices.find(
|
|
(c) => c.id === chosenContext,
|
|
);
|
|
if (!choice) return;
|
|
setBindingBusy(true);
|
|
setBindingMessage('');
|
|
try {
|
|
const result = await contextApi<{
|
|
case_id: string;
|
|
version: number;
|
|
}>(
|
|
`/investidor/manifestacoes/${s.id}/contexto`,
|
|
{
|
|
case_id: choice.id,
|
|
case_version:
|
|
choice.version,
|
|
version: form.data.version,
|
|
},
|
|
);
|
|
form.setData((d) => ({
|
|
...d,
|
|
version: result.version,
|
|
}));
|
|
setContextDossierId(result.case_id);
|
|
setBindingMessage(
|
|
'Dossier associado. As suas edições foram preservadas; reveja os campos antes de submeter.',
|
|
);
|
|
} catch (e) {
|
|
setBindingMessage(
|
|
e instanceof Error
|
|
? e.message
|
|
: 'Não foi possível associar. Os campos foram preservados.',
|
|
);
|
|
} finally {
|
|
setBindingBusy(false);
|
|
}
|
|
}}
|
|
>
|
|
Associar este dossier e recuperar dados
|
|
</button>
|
|
{bindingMessage && (
|
|
<p role="status">{bindingMessage}</p>
|
|
)}
|
|
</section>
|
|
)}
|
|
{contextDossierId && (
|
|
<DossierPrefill
|
|
contextId={contextDossierId}
|
|
consumer="submission"
|
|
initialOpportunity={
|
|
s.opportunity_id
|
|
? `opportunity:${s.opportunity_id}`
|
|
: undefined
|
|
}
|
|
values={form.data.payload}
|
|
boundRevision={boundContextRevision}
|
|
readOnly={readonly}
|
|
onReview={(revision, reviewed) =>
|
|
form.setData((d) => ({
|
|
...d,
|
|
context_revision: revision,
|
|
context_reviewed: reviewed,
|
|
}))
|
|
}
|
|
onApply={(patch, replace) =>
|
|
form.setData((d) => ({
|
|
...d,
|
|
payload: {
|
|
...d.payload,
|
|
...Object.fromEntries(
|
|
Object.entries(patch)
|
|
.filter(
|
|
([k]) =>
|
|
replace ||
|
|
!d.payload[
|
|
k as keyof Payload
|
|
],
|
|
)
|
|
.map(([k, v]) => [
|
|
k,
|
|
typeof v === 'string'
|
|
? v
|
|
: '',
|
|
]),
|
|
),
|
|
},
|
|
}))
|
|
}
|
|
/>
|
|
)}
|
|
<form
|
|
className={card + ' space-y-5'}
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
form.put(base, { preserveScroll: true });
|
|
}}
|
|
>
|
|
{step === 0 && (
|
|
<div className="grid gap-4 md:grid-cols-2">
|
|
{text('full_name', 'Nome completo', true)}
|
|
{text('email', 'Email', true, 'email')}
|
|
{text('phone', 'Telefone')}
|
|
{form.data.payload.country && (
|
|
<p>
|
|
País anteriormente registado:{' '}
|
|
{form.data.payload.country}. Não foi
|
|
convertido em residência, constituição
|
|
ou origem.
|
|
</p>
|
|
)}
|
|
{(
|
|
[
|
|
'residence_country_code',
|
|
'incorporation_country_code',
|
|
'declared_origin_country_code',
|
|
] as const
|
|
).map((key) => (
|
|
<Field
|
|
key={key}
|
|
label={
|
|
{
|
|
residence_country_code:
|
|
'País de residência',
|
|
incorporation_country_code:
|
|
'País de constituição da entidade',
|
|
declared_origin_country_code:
|
|
'País de origem do pedido (opcional)',
|
|
}[key]
|
|
}
|
|
>
|
|
<CountrySelect
|
|
disabled={readonly}
|
|
id={key}
|
|
label={
|
|
{
|
|
residence_country_code:
|
|
'País de residência',
|
|
incorporation_country_code:
|
|
'País de constituição da entidade',
|
|
declared_origin_country_code:
|
|
'País de origem do pedido (opcional)',
|
|
}[key]
|
|
}
|
|
error={
|
|
form.errors[`payload.${key}`]
|
|
}
|
|
countries={countries}
|
|
value={form.data.payload[key] ?? ''}
|
|
onChange={(value) =>
|
|
form.setData('payload', {
|
|
...form.data.payload,
|
|
[key]: value,
|
|
})
|
|
}
|
|
/>
|
|
</Field>
|
|
))}
|
|
{s.payload.organization_country_snapshot && (
|
|
<p className="md:col-span-2">
|
|
País copiado do{' '}
|
|
<Link
|
|
href="/investidor/profile"
|
|
className="underline"
|
|
>
|
|
cadastro mestre da organização
|
|
</Link>
|
|
, versão{' '}
|
|
{
|
|
s.payload
|
|
.organization_country_snapshot
|
|
.organization_version
|
|
}
|
|
:{' '}
|
|
{
|
|
s.payload
|
|
.organization_country_snapshot
|
|
.country
|
|
}
|
|
. Esta cópia conserva a origem;
|
|
alterações posteriores do cadastro não
|
|
alteram esta manifestação.
|
|
</p>
|
|
)}
|
|
<p>
|
|
Indique o país de onde apresenta este
|
|
pedido, se desejar. Pode ser diferente do
|
|
país de residência ou de constituição da
|
|
entidade.
|
|
</p>
|
|
{option(
|
|
'profile_id',
|
|
'investor_profile',
|
|
'Perfil do investidor',
|
|
)}
|
|
{text('organisation', 'Organização / empresa')}
|
|
{text(
|
|
'representative_role',
|
|
'Função do representante',
|
|
)}
|
|
{text('sector', 'Sector de interesse', true)}
|
|
{text('experience', 'Experiência relevante')}
|
|
{text(
|
|
'investment_capacity',
|
|
'Capacidade de investimento / especificação do perfil',
|
|
)}
|
|
</div>
|
|
)}
|
|
{step === 1 && (
|
|
<div className="space-y-5">
|
|
{text(
|
|
'objective',
|
|
'Objectivo do investimento (mínimo 20 caracteres)',
|
|
true,
|
|
)}
|
|
<div className="grid gap-4 md:grid-cols-2">
|
|
{option(
|
|
'participation_id',
|
|
'participation',
|
|
'Modalidade de participação',
|
|
)}
|
|
{option(
|
|
'partnership_id',
|
|
'partnership',
|
|
'Modelo de parceria',
|
|
)}
|
|
{text(
|
|
'estimated_amount',
|
|
'Investimento estimado',
|
|
false,
|
|
'number',
|
|
)}
|
|
{text(
|
|
'currency',
|
|
'Moeda (código de três letras)',
|
|
)}
|
|
{text('horizon', 'Prazo / horizonte', true)}
|
|
{text('location', 'Localização pretendida')}
|
|
</div>
|
|
<div className="grid gap-4 md:grid-cols-3">
|
|
{(
|
|
[
|
|
'clusters',
|
|
'corridors',
|
|
'projects',
|
|
] as const
|
|
).map((group, i) => {
|
|
const key = (
|
|
[
|
|
'cluster_ids',
|
|
'corridor_ids',
|
|
'project_ids',
|
|
] as const
|
|
)[i];
|
|
return (
|
|
<fieldset
|
|
className="max-h-64 space-y-2 overflow-auto rounded border p-3"
|
|
key={group}
|
|
>
|
|
<legend>
|
|
{
|
|
[
|
|
'Clusters',
|
|
'Corredores',
|
|
'Projectos âncora',
|
|
][i]
|
|
}
|
|
</legend>
|
|
{r[group].map((entity) => (
|
|
<label
|
|
key={entity.id}
|
|
className="flex gap-2"
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
disabled={readonly}
|
|
checked={(
|
|
form.data
|
|
.payload[
|
|
key
|
|
] ?? []
|
|
).includes(
|
|
entity.id,
|
|
)}
|
|
onChange={(e) =>
|
|
update(
|
|
key,
|
|
e.target
|
|
.checked
|
|
? [
|
|
...(form
|
|
.data
|
|
.payload[
|
|
key
|
|
] ??
|
|
[]),
|
|
entity.id,
|
|
]
|
|
: form.data.payload[
|
|
key
|
|
].filter(
|
|
(
|
|
id,
|
|
) =>
|
|
id !==
|
|
entity.id,
|
|
),
|
|
)
|
|
}
|
|
/>
|
|
{entity.name}
|
|
</label>
|
|
))}
|
|
</fieldset>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
)}
|
|
{step === 2 && (
|
|
<section className="space-y-5">
|
|
<h2 className="text-xl font-bold">
|
|
Mão de obra, infraestruturas, formação e
|
|
apoios
|
|
</h2>
|
|
<p>
|
|
Acrescente o que existe no local e o que
|
|
necessita. As opções são mantidas pela
|
|
gestão; use Outro para especificar casos
|
|
adicionais.
|
|
</p>
|
|
{form.data.needs.map((need, index) => {
|
|
const category =
|
|
r.options.find(
|
|
(o) =>
|
|
valueText(o.id) ===
|
|
valueText(need.category_id),
|
|
)?.code ?? '';
|
|
const group = category.startsWith('labour')
|
|
? 'labour'
|
|
: category.startsWith('infrastructure')
|
|
? 'infrastructure'
|
|
: category === 'education'
|
|
? 'education'
|
|
: 'support';
|
|
const needSelect = (
|
|
field:
|
|
| 'category_id'
|
|
| 'option_id'
|
|
| 'unit_id'
|
|
| 'priority_id',
|
|
optionGroup: string,
|
|
label: string,
|
|
) => (
|
|
<Field label={label}>
|
|
<select
|
|
className={input}
|
|
disabled={readonly}
|
|
value={need[field] ?? ''}
|
|
onChange={(e) =>
|
|
updateNeed(index, {
|
|
...need,
|
|
[field]: e.target.value,
|
|
...(field ===
|
|
'category_id'
|
|
? { option_id: '' }
|
|
: {}),
|
|
})
|
|
}
|
|
>
|
|
<option value="">
|
|
Seleccionar
|
|
</option>
|
|
{r.options
|
|
.filter(
|
|
(o) =>
|
|
o.group ===
|
|
optionGroup &&
|
|
(o.active ||
|
|
valueText(
|
|
o.id,
|
|
) ===
|
|
valueText(
|
|
need[
|
|
field
|
|
],
|
|
)),
|
|
)
|
|
.map((o) => (
|
|
<option
|
|
value={o.id}
|
|
key={o.id}
|
|
>
|
|
{o.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
);
|
|
return (
|
|
<fieldset
|
|
key={index}
|
|
className="space-y-4 rounded-lg border p-4"
|
|
>
|
|
<legend className="font-bold">
|
|
Necessidade {index + 1}
|
|
</legend>
|
|
<div className="grid gap-4 md:grid-cols-2">
|
|
{needSelect(
|
|
'category_id',
|
|
'need_category',
|
|
'Categoria',
|
|
)}
|
|
{needSelect(
|
|
'option_id',
|
|
group,
|
|
'Tipo',
|
|
)}
|
|
{needSelect(
|
|
'unit_id',
|
|
'unit',
|
|
'Unidade',
|
|
)}
|
|
{needSelect(
|
|
'priority_id',
|
|
'priority',
|
|
'Prioridade',
|
|
)}
|
|
<Field label="Quantidade">
|
|
<input
|
|
className={input}
|
|
type="number"
|
|
min="0"
|
|
step="0.01"
|
|
disabled={readonly}
|
|
value={
|
|
need.quantity ?? ''
|
|
}
|
|
onChange={(e) =>
|
|
updateNeed(index, {
|
|
...need,
|
|
quantity:
|
|
e.target
|
|
.value,
|
|
})
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Prazo">
|
|
<input
|
|
className={input}
|
|
type="date"
|
|
disabled={readonly}
|
|
value={
|
|
need.deadline ?? ''
|
|
}
|
|
onChange={(e) =>
|
|
updateNeed(index, {
|
|
...need,
|
|
deadline:
|
|
e.target
|
|
.value,
|
|
})
|
|
}
|
|
/>
|
|
</Field>
|
|
</div>
|
|
{(
|
|
[
|
|
'description',
|
|
'location',
|
|
'observations',
|
|
...(group === 'labour'
|
|
? [
|
|
'qualification',
|
|
'specialty',
|
|
'experience',
|
|
'certifications',
|
|
'availability',
|
|
'institution',
|
|
]
|
|
: []),
|
|
...(group === 'education'
|
|
? [
|
|
'qualification',
|
|
'institution',
|
|
'training_mode',
|
|
'duration',
|
|
'certifications',
|
|
]
|
|
: []),
|
|
] as (keyof Need['details'])[]
|
|
).map((field) => (
|
|
<Field
|
|
key={field}
|
|
label={
|
|
{
|
|
description:
|
|
'Descrição / especificação',
|
|
location:
|
|
'Localização',
|
|
observations:
|
|
'Observações e referência dos anexos de suporte',
|
|
qualification:
|
|
'Nível de qualificação',
|
|
specialty:
|
|
'Profissão / especialidade',
|
|
experience:
|
|
'Experiência',
|
|
certifications:
|
|
'Certificações',
|
|
availability:
|
|
'Disponibilidade',
|
|
institution:
|
|
'Instituições ou centros de formação',
|
|
training_mode:
|
|
'Modalidade de formação',
|
|
duration: 'Duração',
|
|
status: 'Estado',
|
|
}[field]
|
|
}
|
|
>
|
|
<textarea
|
|
className={input}
|
|
rows={2}
|
|
disabled={readonly}
|
|
value={
|
|
need.details[
|
|
field
|
|
] ?? ''
|
|
}
|
|
onChange={(e) =>
|
|
updateNeed(index, {
|
|
...need,
|
|
details: {
|
|
...need.details,
|
|
[field]:
|
|
e.target
|
|
.value,
|
|
},
|
|
})
|
|
}
|
|
/>
|
|
</Field>
|
|
))}
|
|
{!readonly && (
|
|
<button
|
|
type="button"
|
|
className="underline"
|
|
onClick={() =>
|
|
form.setData(
|
|
'needs',
|
|
form.data.needs.filter(
|
|
(_, i) =>
|
|
i !== index,
|
|
),
|
|
)
|
|
}
|
|
>
|
|
Retirar esta necessidade
|
|
</button>
|
|
)}
|
|
</fieldset>
|
|
);
|
|
})}
|
|
{!readonly && (
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
disabled={form.data.needs.length >= 40}
|
|
onClick={() =>
|
|
form.setData('needs', [
|
|
...form.data.needs,
|
|
emptyNeed(),
|
|
])
|
|
}
|
|
>
|
|
Acrescentar necessidade
|
|
</button>
|
|
)}
|
|
</section>
|
|
)}
|
|
{step === 3 && (
|
|
<p>
|
|
Guarde primeiro o rascunho e carregue os anexos
|
|
no formulário abaixo. Identifique o nome do
|
|
ficheiro nas observações da necessidade a que
|
|
corresponde.
|
|
</p>
|
|
)}
|
|
{step === 4 && (
|
|
<section className="space-y-5">
|
|
<h2 className="text-xl font-bold">
|
|
Rever antes de enviar
|
|
</h2>
|
|
<dl className="space-y-3">
|
|
{[
|
|
[
|
|
'Investidor',
|
|
form.data.payload.full_name,
|
|
],
|
|
['Email', form.data.payload.email],
|
|
[
|
|
'Organização',
|
|
form.data.payload.organisation,
|
|
],
|
|
[
|
|
'Objectivo',
|
|
form.data.payload.objective,
|
|
],
|
|
['Prazo', form.data.payload.horizon],
|
|
[
|
|
'Necessidades',
|
|
valueText(form.data.needs.length),
|
|
],
|
|
[
|
|
'Anexos',
|
|
valueText(attachments.length),
|
|
],
|
|
].map(([label, value]) => (
|
|
<div key={label}>
|
|
<dt className="font-semibold">
|
|
{label}
|
|
</dt>
|
|
<dd className="whitespace-pre-line">
|
|
{value || 'Não indicado'}
|
|
</dd>
|
|
</div>
|
|
))}
|
|
</dl>
|
|
<label className="flex gap-3">
|
|
<input
|
|
type="checkbox"
|
|
disabled={readonly}
|
|
checked={
|
|
form.data.payload.contact_consent
|
|
}
|
|
onChange={(e) =>
|
|
update(
|
|
'contact_consent',
|
|
e.target.checked,
|
|
)
|
|
}
|
|
/>
|
|
Autorizo o tratamento destes dados e o
|
|
contacto pela equipa para analisar e
|
|
acompanhar esta manifestação. Os anexos são
|
|
privados. Não constitui consentimento para
|
|
utilização em IA.
|
|
</label>
|
|
</section>
|
|
)}
|
|
{r.options.some(
|
|
(o) =>
|
|
o.requires_description &&
|
|
[
|
|
form.data.payload.profile_id,
|
|
form.data.payload.participation_id,
|
|
form.data.payload.partnership_id,
|
|
]
|
|
.map(String)
|
|
.includes(valueText(o.id)),
|
|
) &&
|
|
text(
|
|
'other_details',
|
|
'Outro — especifique o perfil, participação ou parceria seleccionados',
|
|
true,
|
|
)}
|
|
{Object.entries(form.errors).map(([key, value]) => (
|
|
<p key={key} role="alert" className="text-red-700">
|
|
<button
|
|
type="button"
|
|
className="underline"
|
|
onClick={() => setStep(errorStep(key))}
|
|
>
|
|
Corrigir na etapa {errorStep(key) + 1}
|
|
</button>
|
|
: {value}
|
|
</p>
|
|
))}
|
|
{note && <p role="status">{note}</p>}
|
|
<div className="flex flex-wrap gap-4">
|
|
{step > 0 && (
|
|
<button
|
|
type="button"
|
|
className="underline"
|
|
onClick={() => setStep(step - 1)}
|
|
>
|
|
Anterior
|
|
</button>
|
|
)}
|
|
{step < 4 && (
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
onClick={() => {
|
|
setNote('');
|
|
setStep(step + 1);
|
|
}}
|
|
>
|
|
Continuar
|
|
</button>
|
|
)}
|
|
{!readonly && (
|
|
<button
|
|
formNoValidate
|
|
className="rounded border px-4 py-2"
|
|
disabled={form.processing}
|
|
>
|
|
Guardar rascunho
|
|
</button>
|
|
)}
|
|
{step === 4 && !readonly && (
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
disabled={
|
|
form.processing ||
|
|
!form.data.payload.contact_consent
|
|
}
|
|
onClick={() =>
|
|
form.post(base + '/submit', {
|
|
preserveScroll: true,
|
|
onError: (errors) =>
|
|
setStep(
|
|
errorStep(
|
|
Object.keys(
|
|
errors,
|
|
)[0] ?? '',
|
|
),
|
|
),
|
|
})
|
|
}
|
|
>
|
|
Submeter manifestação
|
|
</button>
|
|
)}
|
|
</div>
|
|
</form>
|
|
{step === 3 && (
|
|
<section className={card + ' space-y-4'}>
|
|
<h2 className="text-xl font-bold">
|
|
Anexos privados
|
|
</h2>
|
|
<p>
|
|
PDF ou TXT, até 10 MiB cada, máximo de dez
|
|
anexos. Guardar um anexo actualiza a versão do
|
|
rascunho.
|
|
</p>
|
|
{attachments.map((a) => (
|
|
<p key={a.id}>
|
|
<a
|
|
className="underline"
|
|
href={base + '/attachments/' + a.id}
|
|
>
|
|
{a.file_name}
|
|
</a>
|
|
</p>
|
|
))}
|
|
{!readonly && (
|
|
<form
|
|
className="space-y-4"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
if (form.isDirty) {
|
|
setNote(
|
|
'Guarde as alterações do formulário antes de carregar o anexo.',
|
|
);
|
|
return;
|
|
}
|
|
upload.post(base + '/attachments', {
|
|
forceFormData: true,
|
|
preserveScroll: true,
|
|
});
|
|
}}
|
|
>
|
|
<Field label="Documento de suporte">
|
|
<input
|
|
type="file"
|
|
accept="application/pdf,text/plain"
|
|
required
|
|
onChange={(e) =>
|
|
upload.setData(
|
|
'file',
|
|
e.target.files?.[0] ?? null,
|
|
)
|
|
}
|
|
/>
|
|
</Field>
|
|
{Object.entries(upload.errors).map(
|
|
([key, value]) => (
|
|
<p role="alert" key={key}>
|
|
{value}
|
|
</p>
|
|
),
|
|
)}
|
|
<button
|
|
className={button}
|
|
disabled={upload.processing}
|
|
>
|
|
Carregar anexo
|
|
</button>
|
|
</form>
|
|
)}
|
|
</section>
|
|
)}
|
|
</>
|
|
)}
|
|
<details className={card}>
|
|
<summary className="cursor-pointer font-bold">
|
|
Histórico do pedido
|
|
</summary>
|
|
<ol className="mt-3 space-y-2">
|
|
{events.map((e, i) => (
|
|
<li key={i}>
|
|
{new Date(e.created_at).toLocaleString('pt-MZ')} —{' '}
|
|
{(
|
|
{
|
|
draft_created: 'Rascunho criado',
|
|
draft_saved: 'Rascunho guardado',
|
|
attachment_added: 'Anexo acrescentado',
|
|
submitted: 'Submetido',
|
|
received: 'Recebido',
|
|
in_review: 'Em análise',
|
|
contacted: 'Contactado',
|
|
closed: 'Encerrado',
|
|
} as Record<string, string>
|
|
)[e.action] ?? e.action}{' '}
|
|
· versão {e.version}
|
|
</li>
|
|
))}
|
|
</ol>
|
|
</details>
|
|
<Conversation
|
|
id={s.id}
|
|
messages={messages}
|
|
revisions={revisions}
|
|
submitted={s.status === 'submitted'}
|
|
/>
|
|
</Frame>
|
|
);
|
|
}
|