178 lines
6.4 KiB
TypeScript
178 lines
6.4 KiB
TypeScript
import { Link, router, useForm } from '@inertiajs/react';
|
|
import { Frame, Field, input, button, card } from './shared';
|
|
import PartnershipSourceLinks from '@/components/partnership-source-links';
|
|
|
|
type RecordData = { version: number; payload: Record<string, string> };
|
|
type Company = RecordData & { id: string };
|
|
const labels: Record<string, string> = {
|
|
phone: 'Telefone',
|
|
country: 'País',
|
|
sector: 'Sector de interesse',
|
|
experience: 'Experiência relevante',
|
|
investment_capacity: 'Capacidade de investimento declarada',
|
|
name: 'Nome da empresa',
|
|
registration: 'Referência de registo / NUIT',
|
|
role: 'Função ou relação com a empresa',
|
|
description: 'Actividade e observações',
|
|
};
|
|
|
|
export default function Profile({
|
|
account,
|
|
companies,
|
|
}: {
|
|
account: RecordData;
|
|
companies: Company[];
|
|
}) {
|
|
return (
|
|
<Frame title="Perfil de investimento e empresas">
|
|
<Link href="/investidor/manifestacoes" className="underline">
|
|
Voltar à área do investidor
|
|
</Link>
|
|
<p>
|
|
Estes dados são privados e servem para preencher novas
|
|
manifestações. Nome e email são mantidos nas{' '}
|
|
<Link className="underline" href="/settings/profile">
|
|
definições da conta
|
|
</Link>
|
|
.
|
|
</p>
|
|
<Editor
|
|
key={'account-' + account.version}
|
|
record={account}
|
|
fields={[
|
|
'phone',
|
|
'country',
|
|
'sector',
|
|
'experience',
|
|
'investment_capacity',
|
|
]}
|
|
/>
|
|
<h2 className="text-2xl font-bold">Empresas declaradas</h2>
|
|
<p>
|
|
Declarar uma empresa não comprova representação legal nem
|
|
concede acesso aos registos de outras pessoas. A equipa pode
|
|
pedir evidência durante o atendimento.
|
|
</p>
|
|
{companies.map((company) => (
|
|
<section key={company.id} className={card}>
|
|
<PartnershipSourceLinks type="company" id={company.id} />
|
|
<h3 className="text-xl font-bold">
|
|
{company.payload.name}
|
|
</h3>
|
|
<Editor
|
|
key={company.version}
|
|
record={company}
|
|
fields={[
|
|
'name',
|
|
'country',
|
|
'registration',
|
|
'sector',
|
|
'role',
|
|
'description',
|
|
]}
|
|
/>
|
|
<button
|
|
className={button + ' mt-4'}
|
|
onClick={() =>
|
|
router.post('/investidor/manifestacoes', {
|
|
company_id: company.id,
|
|
})
|
|
}
|
|
>
|
|
Preparar manifestação desta empresa
|
|
</button>
|
|
</section>
|
|
))}
|
|
{companies.length < 20 && (
|
|
<section className={card}>
|
|
<h3 className="text-xl font-bold">Acrescentar empresa</h3>
|
|
<Editor
|
|
key={'new-' + companies.length}
|
|
record={{ version: 0, payload: {} }}
|
|
company
|
|
fields={[
|
|
'name',
|
|
'country',
|
|
'registration',
|
|
'sector',
|
|
'role',
|
|
'description',
|
|
]}
|
|
/>
|
|
</section>
|
|
)}
|
|
</Frame>
|
|
);
|
|
}
|
|
function Editor({
|
|
record,
|
|
fields,
|
|
company = false,
|
|
}: {
|
|
record: RecordData & { id?: string };
|
|
fields: string[];
|
|
company?: boolean;
|
|
}) {
|
|
const isCompany = company || !!record.id;
|
|
const form = useForm({
|
|
version: record.version,
|
|
payload: Object.fromEntries(
|
|
fields.map((key) => [key, record.payload[key] ?? '']),
|
|
),
|
|
});
|
|
return (
|
|
<form
|
|
className="mt-4 space-y-4"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
const options = { preserveScroll: true };
|
|
if (isCompany)
|
|
form.post(
|
|
'/investidor/companies' +
|
|
(record.id ? '/' + record.id : ''),
|
|
options,
|
|
);
|
|
else form.put('/investidor/profile', options);
|
|
}}
|
|
>
|
|
<div className="grid gap-4 md:grid-cols-2">
|
|
{fields.map((key) => (
|
|
<Field key={key} label={labels[key]}>
|
|
<input
|
|
className={input}
|
|
value={form.data.payload[key]}
|
|
required={
|
|
isCompany &&
|
|
['name', 'country', 'role'].includes(key)
|
|
}
|
|
maxLength={
|
|
key === 'description' || key === 'experience'
|
|
? 2000
|
|
: key === 'investment_capacity'
|
|
? 1000
|
|
: 200
|
|
}
|
|
onChange={(e) =>
|
|
form.setData('payload', {
|
|
...form.data.payload,
|
|
[key]: e.target.value,
|
|
})
|
|
}
|
|
/>
|
|
</Field>
|
|
))}
|
|
</div>
|
|
{Object.entries(form.errors).map(([key, value]) => (
|
|
<p role="alert" key={key} className="text-red-700">
|
|
{value}
|
|
</p>
|
|
))}
|
|
<button className={button} disabled={form.processing}>
|
|
{isCompany
|
|
? 'Guardar declaração da empresa'
|
|
: 'Guardar perfil de investimento'}
|
|
</button>
|
|
</form>
|
|
);
|
|
}
|