feat: consolidar desenvolvimentos do portal InvestMoz

This commit is contained in:
2026-11-03 23:32:32 +02:00
parent 1da273f1f3
commit 36c8cadb49
345 changed files with 110714 additions and 2799 deletions
+85 -31
View File
@@ -1,9 +1,12 @@
import { Link, useForm } from '@inertiajs/react';
import { Link } from '@inertiajs/react';
import { useCrmRecordEdit } from '@/lib/crm-record-edit';
import CrmEditComparison from '@/components/crm-edit-comparison';
import { Management, Field, control, button } from '../management/shared';
import { leadStates } from './types';
type Contact = {
id: string;
version_no: number;
full_name: string;
email: string | null;
phone: string | null;
@@ -15,44 +18,61 @@ function ContactForm({
contact: Contact;
investorId: string;
}) {
const form = useForm({
full_name: contact.full_name,
email: contact.email ?? '',
phone: contact.phone ?? '',
const edit = useCrmRecordEdit({
id: contact.id,
kind: 'contact',
version: contact.version_no,
values: {
full_name: contact.full_name,
email: contact.email ?? '',
phone: contact.phone ?? '',
},
});
const form = edit.form;
return (
<form
className="space-y-3 rounded border p-4"
onSubmit={(e) => {
e.preventDefault();
form.patch(
edit.submit(
`/management/crm/investors/${investorId}/contacts/${contact.id}`,
);
}}
>
<Field label="Nome do contacto" error={form.errors.full_name}>
<Field label="Nome do contacto" error={edit.error('full_name')}>
<input
className={control}
value={form.data.full_name}
onChange={(e) => form.setData('full_name', e.target.value)}
value={edit.values.full_name}
onChange={(e) => edit.change('full_name', e.target.value)}
/>
</Field>
<Field label="Email" error={form.errors.email}>
<Field label="Email" error={edit.error('email')}>
<input
className={control}
type="email"
value={form.data.email}
onChange={(e) => form.setData('email', e.target.value)}
value={edit.values.email}
onChange={(e) => edit.change('email', e.target.value)}
/>
</Field>
<Field label="Telefone" error={form.errors.phone}>
<Field label="Telefone" error={edit.error('phone')}>
<input
className={control}
value={form.data.phone}
onChange={(e) => form.setData('phone', e.target.value)}
value={edit.values.phone}
onChange={(e) => edit.change('phone', e.target.value)}
/>
</Field>
<button className={button} disabled={form.processing}>
<CrmEditComparison
editor={edit}
labels={{
full_name: 'Nome do contacto',
email: 'Email',
phone: 'Telefone',
}}
/>
<button
className={button}
disabled={form.processing || edit.blocked}
>
Guardar contacto
</button>
</form>
@@ -65,6 +85,7 @@ export default function InvestorDetail({
}: {
investor: {
id: string;
version_no: number;
legal_name: string;
investor_type: string;
status: string;
@@ -72,38 +93,44 @@ export default function InvestorDetail({
contacts: Contact[];
leads: { id: string; title: string; status: string }[];
}) {
const form = useForm({
legal_name: investor.legal_name,
investor_type: investor.investor_type,
status: investor.status,
const edit = useCrmRecordEdit({
id: investor.id,
kind: 'investor',
version: investor.version_no,
values: {
legal_name: investor.legal_name,
investor_type: investor.investor_type,
status: investor.status,
},
});
const form = edit.form;
return (
<Management title={investor.legal_name}>
<form
className="max-w-xl space-y-4"
onSubmit={(e) => {
e.preventDefault();
form.patch(`/management/crm/investors/${investor.id}`);
edit.submit(`/management/crm/investors/${investor.id}`);
}}
>
<Field label="Nome legal" error={form.errors.legal_name}>
<Field label="Nome legal" error={edit.error('legal_name')}>
<input
className={control}
value={form.data.legal_name}
value={edit.values.legal_name}
onChange={(e) =>
form.setData('legal_name', e.target.value)
edit.change('legal_name', e.target.value)
}
/>
</Field>
<Field
label="Tipo de investidor"
error={form.errors.investor_type}
error={edit.error('investor_type')}
>
<select
className={control}
value={form.data.investor_type}
value={edit.values.investor_type}
onChange={(e) =>
form.setData('investor_type', e.target.value)
edit.change('investor_type', e.target.value)
}
>
{Object.entries({
@@ -118,11 +145,11 @@ export default function InvestorDetail({
))}
</select>
</Field>
<Field label="Estado" error={form.errors.status}>
<Field label="Estado" error={edit.error('status')}>
<select
className={control}
value={form.data.status}
onChange={(e) => form.setData('status', e.target.value)}
value={edit.values.status}
onChange={(e) => edit.change('status', e.target.value)}
>
{Object.entries({
prospect: 'Potencial investidor',
@@ -135,7 +162,34 @@ export default function InvestorDetail({
))}
</select>
</Field>
<button className={button} disabled={form.processing}>
<CrmEditComparison
editor={edit}
labels={{
legal_name: 'Nome legal',
investor_type: 'Tipo de investidor',
status: 'Estado',
}}
display={(key, value) =>
key === 'investor_type'
? ({
domestic: 'Nacional',
foreign: 'Estrangeiro',
institutional: 'Institucional',
individual: 'Individual',
}[value] ?? value)
: key === 'status'
? ({
prospect: 'Potencial investidor',
active: 'Activo',
inactive: 'Inactivo',
}[value] ?? value)
: value
}
/>
<button
className={button}
disabled={form.processing || edit.blocked}
>
Guardar investidor
</button>
</form>