@@ -0,0 +1,172 @@
|
||||
import { Link, useForm } from '@inertiajs/react';
|
||||
import { Management, Field, control, button } from '../management/shared';
|
||||
import { leadStates } from './types';
|
||||
|
||||
type Contact = {
|
||||
id: string;
|
||||
full_name: string;
|
||||
email: string | null;
|
||||
phone: string | null;
|
||||
};
|
||||
function ContactForm({
|
||||
contact,
|
||||
investorId,
|
||||
}: {
|
||||
contact: Contact;
|
||||
investorId: string;
|
||||
}) {
|
||||
const form = useForm({
|
||||
full_name: contact.full_name,
|
||||
email: contact.email ?? '',
|
||||
phone: contact.phone ?? '',
|
||||
});
|
||||
return (
|
||||
<form
|
||||
className="space-y-3 rounded border p-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.patch(
|
||||
`/management/crm/investors/${investorId}/contacts/${contact.id}`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<Field label="Nome do contacto" error={form.errors.full_name}>
|
||||
<input
|
||||
className={control}
|
||||
value={form.data.full_name}
|
||||
onChange={(e) => form.setData('full_name', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Email" error={form.errors.email}>
|
||||
<input
|
||||
className={control}
|
||||
type="email"
|
||||
value={form.data.email}
|
||||
onChange={(e) => form.setData('email', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Telefone" error={form.errors.phone}>
|
||||
<input
|
||||
className={control}
|
||||
value={form.data.phone}
|
||||
onChange={(e) => form.setData('phone', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<button className={button} disabled={form.processing}>
|
||||
Guardar contacto
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
export default function InvestorDetail({
|
||||
investor,
|
||||
contacts,
|
||||
leads,
|
||||
}: {
|
||||
investor: {
|
||||
id: string;
|
||||
legal_name: string;
|
||||
investor_type: string;
|
||||
status: string;
|
||||
};
|
||||
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,
|
||||
});
|
||||
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}`);
|
||||
}}
|
||||
>
|
||||
<Field label="Nome legal" error={form.errors.legal_name}>
|
||||
<input
|
||||
className={control}
|
||||
value={form.data.legal_name}
|
||||
onChange={(e) =>
|
||||
form.setData('legal_name', e.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
<Field
|
||||
label="Tipo de investidor"
|
||||
error={form.errors.investor_type}
|
||||
>
|
||||
<select
|
||||
className={control}
|
||||
value={form.data.investor_type}
|
||||
onChange={(e) =>
|
||||
form.setData('investor_type', e.target.value)
|
||||
}
|
||||
>
|
||||
{Object.entries({
|
||||
domestic: 'Nacional',
|
||||
foreign: 'Estrangeiro',
|
||||
institutional: 'Institucional',
|
||||
individual: 'Individual',
|
||||
}).map(([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Estado" error={form.errors.status}>
|
||||
<select
|
||||
className={control}
|
||||
value={form.data.status}
|
||||
onChange={(e) => form.setData('status', e.target.value)}
|
||||
>
|
||||
{Object.entries({
|
||||
prospect: 'Potencial investidor',
|
||||
active: 'Activo',
|
||||
inactive: 'Inactivo',
|
||||
}).map(([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<button className={button} disabled={form.processing}>
|
||||
Guardar investidor
|
||||
</button>
|
||||
</form>
|
||||
<section className="max-w-xl space-y-4">
|
||||
<h2 className="text-lg font-semibold">Contactos</h2>
|
||||
<p>
|
||||
Um contacto pode representar vários investidores. Alterações
|
||||
ao contacto são partilhadas entre essas relações.
|
||||
</p>
|
||||
{contacts.map((contact) => (
|
||||
<ContactForm
|
||||
key={contact.id}
|
||||
contact={contact}
|
||||
investorId={investor.id}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
<section className="space-y-3">
|
||||
<h2 className="text-lg font-semibold">Leads associados</h2>
|
||||
{leads.map((lead) => (
|
||||
<p key={lead.id}>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/management/crm/leads/${lead.id}`}
|
||||
>
|
||||
{lead.title}
|
||||
</Link>{' '}
|
||||
· {leadStates[lead.status]}
|
||||
</p>
|
||||
))}
|
||||
</section>
|
||||
</Management>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user