106 lines
3.9 KiB
TypeScript
106 lines
3.9 KiB
TypeScript
import { Head, Link, useForm } from '@inertiajs/react';
|
|
import { useState } from 'react';
|
|
|
|
export type InvestmentContext = {
|
|
id: string;
|
|
title: string;
|
|
version: number;
|
|
updated_at: string;
|
|
};
|
|
|
|
export default function InvestmentContexts({
|
|
contexts,
|
|
}: {
|
|
contexts: InvestmentContext[];
|
|
}) {
|
|
const [key] = useState(() => globalThis.crypto.randomUUID());
|
|
const form = useForm({ title: '', client_key: key, reuse_consent: false });
|
|
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>
|
|
<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={`/investimentos/${item.id}`}
|
|
>
|
|
{item.title}
|
|
</Link>
|
|
<p className="text-sm">
|
|
Guardado em{' '}
|
|
{new Date(item.updated_at).toLocaleString('pt-MZ')}
|
|
</p>
|
|
</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>
|
|
);
|
|
}
|