249 lines
10 KiB
TypeScript
249 lines
10 KiB
TypeScript
import { createOperationKey } from '@/lib/operation-key';
|
|
import { Head, Link, router, useForm } from '@inertiajs/react';
|
|
import { useState } from 'react';
|
|
import {
|
|
companyComparisonUrl,
|
|
type CompanyAnswers,
|
|
} from '@/lib/company-comparison';
|
|
import type { LegacyArticle } from '@/pages/portal/legacy';
|
|
import { guideUrl, type GuideSelection } from '@/lib/investment-guides';
|
|
|
|
export type InvestmentContext = {
|
|
id: string;
|
|
title: string;
|
|
version: number;
|
|
updated_at: string;
|
|
};
|
|
|
|
export default function InvestmentContexts({
|
|
contexts,
|
|
contentSource,
|
|
sectorSource,
|
|
zoneSource,
|
|
companyComparisonAnswers,
|
|
guideSelection,
|
|
}: {
|
|
contexts: InvestmentContext[];
|
|
companyComparisonAnswers?: CompanyAnswers | null;
|
|
guideSelection?: GuideSelection | null;
|
|
contentSource?: LegacyArticle;
|
|
zoneSource?: {
|
|
zone_id: string;
|
|
consulted_public_version: number;
|
|
title: string;
|
|
href: string;
|
|
notice: string;
|
|
};
|
|
sectorSource?: { id: number; name: string; slug: string; href: string };
|
|
}) {
|
|
const [key] = useState(() => createOperationKey());
|
|
const form = useForm({
|
|
zone_id: zoneSource?.zone_id,
|
|
consulted_public_version: zoneSource?.consulted_public_version,
|
|
confirm: !!zoneSource,
|
|
title: '',
|
|
client_key: key,
|
|
reuse_consent: false,
|
|
content_resource_id: contentSource?.id,
|
|
sector_slug: sectorSource?.slug,
|
|
...(companyComparisonAnswers
|
|
? { company_comparison: companyComparisonAnswers }
|
|
: {}),
|
|
...(guideSelection ? { investment_guide: guideSelection } : {}),
|
|
});
|
|
return (
|
|
<main className="mx-auto max-w-5xl space-y-6 p-4 md:p-8">
|
|
<Head title="Os meus investimentos" />
|
|
<h1 className="text-2xl font-semibold">Os meus investimentos</h1>
|
|
{guideSelection && (
|
|
<p>
|
|
Escolha ou crie o dossier onde pretende preparar esta
|
|
referência. O guia e a nota só serão guardados quando
|
|
confirmar nesse dossier.
|
|
</p>
|
|
)}
|
|
{companyComparisonAnswers && (
|
|
<p>
|
|
Escolha o dossier para continuar a comparação de formas
|
|
jurídicas. As respostas só serão guardadas quando confirmar
|
|
nesse dossier.
|
|
</p>
|
|
)}
|
|
{zoneSource && (
|
|
<section className="rounded border p-4">
|
|
<h2>Parque escolhido: {zoneSource.title}</h2>
|
|
<Link className="underline" href={zoneSource.href}>
|
|
Consultar parque
|
|
</Link>
|
|
</section>
|
|
)}
|
|
{sectorSource && (
|
|
<p>
|
|
Preparar uma ideia em{' '}
|
|
<Link className="underline" href={sectorSource.href}>
|
|
{sectorSource.name}
|
|
</Link>
|
|
. O setor será recuperado no dossier, mesmo sem oportunidade
|
|
publicada.
|
|
</p>
|
|
)}
|
|
{contentSource && (
|
|
<p>
|
|
Preparar a partir de{' '}
|
|
<Link className="underline" href={contentSource.href}>
|
|
{contentSource.title}
|
|
</Link>
|
|
.
|
|
</p>
|
|
)}
|
|
<p>
|
|
Prepare cada investimento no seu dossier. Pode trabalhar em
|
|
várias etapas em paralelo.
|
|
</p>
|
|
<ul className="grid gap-4 md:grid-cols-2">
|
|
{contexts.map((item) => (
|
|
<li key={item.id} className="rounded-xl border p-4">
|
|
<Link
|
|
className="font-semibold underline"
|
|
href={
|
|
guideSelection
|
|
? guideUrl(
|
|
`/investimentos/${item.id}/guias/${guideSelection.slug}`,
|
|
guideSelection,
|
|
)
|
|
: companyComparisonAnswers
|
|
? companyComparisonUrl(
|
|
`/investimentos/${item.id}/forma-juridica`,
|
|
companyComparisonAnswers,
|
|
)
|
|
: `/investimentos/${item.id}`
|
|
}
|
|
>
|
|
{item.title}
|
|
</Link>
|
|
<p className="text-sm">
|
|
Guardado em{' '}
|
|
{new Date(item.updated_at).toLocaleString('pt-MZ')}
|
|
</p>
|
|
{zoneSource && (
|
|
<button
|
|
type="button"
|
|
className="mt-3 rounded border p-2"
|
|
onClick={() =>
|
|
router.post(
|
|
`/investimentos/${item.id}/parques`,
|
|
{
|
|
version: item.version,
|
|
zone_id: zoneSource.zone_id,
|
|
consulted_public_version:
|
|
zoneSource.consulted_public_version,
|
|
confirm: true,
|
|
},
|
|
)
|
|
}
|
|
>
|
|
Confirmar referência neste dossier
|
|
</button>
|
|
)}
|
|
{sectorSource && (
|
|
<button
|
|
type="button"
|
|
className="mt-3 rounded border p-2"
|
|
onClick={() =>
|
|
router.post(
|
|
`/investimentos/${item.id}/sectores`,
|
|
{
|
|
version: item.version,
|
|
sector_slug: sectorSource.slug,
|
|
},
|
|
)
|
|
}
|
|
>
|
|
Continuar neste dossier com o setor
|
|
</button>
|
|
)}
|
|
{contentSource && (
|
|
<button
|
|
type="button"
|
|
className="mt-3 rounded border p-2"
|
|
onClick={() =>
|
|
router.post(
|
|
`/investimentos/${item.id}/conteudos`,
|
|
{
|
|
version: item.version,
|
|
resource_id: contentSource.id,
|
|
},
|
|
)
|
|
}
|
|
>
|
|
Continuar neste dossier com o artigo
|
|
</button>
|
|
)}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
{!contexts.length && (
|
|
<p>Ainda não criou um investimento neste percurso.</p>
|
|
)}
|
|
<form
|
|
className="max-w-xl space-y-4 rounded-xl border p-5"
|
|
onSubmit={(event) => {
|
|
event.preventDefault();
|
|
form.post('/investimentos');
|
|
}}
|
|
>
|
|
<h2 className="text-lg font-semibold">
|
|
Preparar um investimento
|
|
</h2>
|
|
<label className="grid gap-1">
|
|
Título
|
|
<input
|
|
required
|
|
maxLength={200}
|
|
className="rounded border p-2"
|
|
value={form.data.title}
|
|
onChange={(event) =>
|
|
form.setData('title', event.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
<label className="flex gap-2">
|
|
<input
|
|
type="checkbox"
|
|
checked={form.data.reuse_consent}
|
|
onChange={(event) =>
|
|
form.setData('reuse_consent', event.target.checked)
|
|
}
|
|
/>
|
|
Autorizo reutilizar o meu perfil neste dossier privado.
|
|
</label>
|
|
{Object.values(form.errors).map((error, index) => (
|
|
<p key={index} role="alert">
|
|
{error}
|
|
</p>
|
|
))}
|
|
<button
|
|
disabled={form.processing}
|
|
className="bg-primary text-primary-foreground rounded px-4 py-2"
|
|
>
|
|
Criar e guardar dossier
|
|
</button>
|
|
</form>
|
|
<nav className="flex flex-wrap gap-4" aria-label="Ferramentas">
|
|
<Link className="underline" href="/simulador-fiscal">
|
|
Simulador
|
|
</Link>
|
|
<Link className="underline" href="/balcao-virtual/painel">
|
|
Balcão
|
|
</Link>
|
|
<Link className="underline" href="/investidor">
|
|
Oportunidades guardadas
|
|
</Link>
|
|
<Link className="underline" href="/dashboard">
|
|
Painel
|
|
</Link>
|
|
</nav>
|
|
</main>
|
|
);
|
|
}
|