feat: consolidar desenvolvimentos do portal InvestMoz
This commit is contained in:
@@ -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>
|
||||
|
||||
+117
-90
@@ -1,16 +1,28 @@
|
||||
import { Link, useForm } from '@inertiajs/react';
|
||||
import CrmTaskCreation from '@/components/crm-task-creation';
|
||||
import type { TaskCreationContext } from '@/lib/crm-task-creation';
|
||||
import { Link } from '@inertiajs/react';
|
||||
import { useCrmRecordEdit } from '@/lib/crm-record-edit';
|
||||
import CrmEditComparison from '@/components/crm-edit-comparison';
|
||||
import { Management, Field, button, control } from '../management/shared';
|
||||
import { leadStates, taskStates } from './types';
|
||||
import type { Lead, Owner, Task } from './types';
|
||||
|
||||
function TaskRow({ task, leadId }: { task: Task; leadId: string }) {
|
||||
const form = useForm({ status: task.status });
|
||||
const edit = useCrmRecordEdit({
|
||||
id: task.id,
|
||||
kind: 'task',
|
||||
version: task.version_no,
|
||||
values: { status: task.status },
|
||||
});
|
||||
const form = edit.form;
|
||||
return (
|
||||
<form
|
||||
id={`crm-task-${task.id}`}
|
||||
className="space-y-3 rounded border p-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.patch(`/management/crm/leads/${leadId}/tasks/${task.id}`);
|
||||
if (task.can_update === false) return;
|
||||
edit.submit(`/management/crm/leads/${leadId}/tasks/${task.id}`);
|
||||
}}
|
||||
>
|
||||
<h3 className="font-semibold">{task.title}</h3>
|
||||
@@ -26,12 +38,13 @@ function TaskRow({ task, leadId }: { task: Task; leadId: string }) {
|
||||
</p>
|
||||
<Field
|
||||
label={`Estado da tarefa: ${task.title}`}
|
||||
error={form.errors.status}
|
||||
error={edit.error('status')}
|
||||
>
|
||||
<select
|
||||
className={control}
|
||||
value={form.data.status}
|
||||
onChange={(e) => form.setData('status', e.target.value)}
|
||||
disabled={task.can_update === false}
|
||||
value={edit.values.status}
|
||||
onChange={(e) => edit.change('status', e.target.value)}
|
||||
>
|
||||
{Object.entries(taskStates).map(([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
@@ -40,9 +53,26 @@ function TaskRow({ task, leadId }: { task: Task; leadId: string }) {
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<button className={button} disabled={form.processing}>
|
||||
Actualizar tarefa
|
||||
</button>
|
||||
{task.can_update !== false ? (
|
||||
<>
|
||||
<CrmEditComparison
|
||||
editor={edit}
|
||||
labels={{ status: 'Estado da tarefa' }}
|
||||
display={(_key, value) => taskStates[value] ?? value}
|
||||
/>
|
||||
<button
|
||||
className={button}
|
||||
disabled={form.processing || edit.blocked}
|
||||
>
|
||||
Actualizar tarefa
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<p>
|
||||
Dossier associado encerrado; tarefa disponível para
|
||||
consulta.
|
||||
</p>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -50,6 +80,8 @@ export default function LeadDetail({
|
||||
lead,
|
||||
contacts,
|
||||
owners,
|
||||
nextAction,
|
||||
taskCreation,
|
||||
}: {
|
||||
lead: Lead;
|
||||
contacts: {
|
||||
@@ -59,17 +91,21 @@ export default function LeadDetail({
|
||||
phone: string | null;
|
||||
}[];
|
||||
owners: Owner[];
|
||||
nextAction?: { future_tasks: number };
|
||||
taskCreation: TaskCreationContext;
|
||||
}) {
|
||||
const review = useForm({
|
||||
status: lead.status,
|
||||
owner_user_id: String(lead.owner_user_id ?? ''),
|
||||
qualification_reason: '',
|
||||
});
|
||||
const task = useForm({
|
||||
title: '',
|
||||
due_at: '',
|
||||
assignee_user_id: String(lead.owner_user_id ?? ''),
|
||||
const edit = useCrmRecordEdit({
|
||||
id: lead.id,
|
||||
kind: 'lead',
|
||||
version: lead.version_no,
|
||||
blankAfterSave: ['qualification_reason'],
|
||||
values: {
|
||||
status: lead.status,
|
||||
owner_user_id: String(lead.owner_user_id ?? ''),
|
||||
qualification_reason: '',
|
||||
},
|
||||
});
|
||||
const review = edit.form;
|
||||
return (
|
||||
<Management title={lead.title}>
|
||||
<Link className="underline" href="/management/crm/leads">
|
||||
@@ -108,23 +144,46 @@ export default function LeadDetail({
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
{nextAction && (
|
||||
<section
|
||||
aria-label="Próxima acção"
|
||||
className="space-y-2 rounded border p-4"
|
||||
>
|
||||
<p>
|
||||
{nextAction.future_tasks === 1
|
||||
? '1 tarefa disponível com prazo futuro.'
|
||||
: `${nextAction.future_tasks} tarefas disponíveis com prazo futuro.`}
|
||||
</p>
|
||||
{nextAction.future_tasks === 0 &&
|
||||
['new', 'qualified'].includes(lead.status) && (
|
||||
<p role="status">
|
||||
Registe uma próxima acção com prazo futuro antes
|
||||
de qualificar o acompanhamento ou concluir a sua
|
||||
última tarefa. Tarefas num dossier encerrado
|
||||
ficam no histórico e não contam como próxima
|
||||
acção.
|
||||
</p>
|
||||
)}
|
||||
<a className="underline" href="#new-crm-task">
|
||||
Registar próxima acção
|
||||
</a>
|
||||
</section>
|
||||
)}
|
||||
<form
|
||||
className="max-w-xl space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
review.patch(`/management/crm/leads/${lead.id}`);
|
||||
edit.submit(`/management/crm/leads/${lead.id}`);
|
||||
}}
|
||||
>
|
||||
<h2 className="text-lg font-semibold">
|
||||
Qualificação e atribuição
|
||||
</h2>
|
||||
<Field label="Estado do lead" error={review.errors.status}>
|
||||
<Field label="Estado do lead" error={edit.error('status')}>
|
||||
<select
|
||||
className={control}
|
||||
value={review.data.status}
|
||||
onChange={(e) =>
|
||||
review.setData('status', e.target.value)
|
||||
}
|
||||
value={edit.values.status}
|
||||
onChange={(e) => edit.change('status', e.target.value)}
|
||||
>
|
||||
{Object.entries(leadStates)
|
||||
.filter(([key]) => key !== 'converted')
|
||||
@@ -135,12 +194,12 @@ export default function LeadDetail({
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Responsável" error={review.errors.owner_user_id}>
|
||||
<Field label="Responsável" error={edit.error('owner_user_id')}>
|
||||
<select
|
||||
className={control}
|
||||
value={review.data.owner_user_id}
|
||||
value={edit.values.owner_user_id}
|
||||
onChange={(e) =>
|
||||
review.setData('owner_user_id', e.target.value)
|
||||
edit.change('owner_user_id', e.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione</option>
|
||||
@@ -153,16 +212,13 @@ export default function LeadDetail({
|
||||
</Field>
|
||||
<Field
|
||||
label="Fundamento da alteração"
|
||||
error={review.errors.qualification_reason}
|
||||
error={edit.error('qualification_reason')}
|
||||
>
|
||||
<textarea
|
||||
className={control}
|
||||
value={review.data.qualification_reason}
|
||||
value={edit.values.qualification_reason}
|
||||
onChange={(e) =>
|
||||
review.setData(
|
||||
'qualification_reason',
|
||||
e.target.value,
|
||||
)
|
||||
edit.change('qualification_reason', e.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
@@ -171,9 +227,30 @@ export default function LeadDetail({
|
||||
Último fundamento: {lead.qualification_reason}
|
||||
</p>
|
||||
)}
|
||||
<CrmEditComparison
|
||||
editor={edit}
|
||||
labels={{
|
||||
status: 'Estado do lead',
|
||||
owner_user_id: 'Responsável',
|
||||
qualification_reason: 'Fundamento da alteração',
|
||||
}}
|
||||
display={(key, value) =>
|
||||
key === 'status'
|
||||
? (leadStates[value] ?? value)
|
||||
: key === 'owner_user_id'
|
||||
? (owners.find(
|
||||
(owner) => String(owner.id) === value,
|
||||
)?.name ?? 'Responsável por confirmar')
|
||||
: value
|
||||
}
|
||||
/>
|
||||
<button
|
||||
className={button}
|
||||
disabled={review.processing || lead.status === 'converted'}
|
||||
disabled={
|
||||
review.processing ||
|
||||
edit.blocked ||
|
||||
lead.status === 'converted'
|
||||
}
|
||||
>
|
||||
Guardar lead
|
||||
</button>
|
||||
@@ -185,62 +262,12 @@ export default function LeadDetail({
|
||||
))}
|
||||
{!lead.tasks.length && <p>Não existem tarefas.</p>}
|
||||
</section>
|
||||
<form
|
||||
className="max-w-xl space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
task.transform((data) => ({
|
||||
...data,
|
||||
due_at: data.due_at
|
||||
? new Date(data.due_at).toISOString()
|
||||
: '',
|
||||
}));
|
||||
task.post(`/management/crm/leads/${lead.id}/tasks`, {
|
||||
onSuccess: () => task.reset('title', 'due_at'),
|
||||
});
|
||||
}}
|
||||
>
|
||||
<h2 className="text-lg font-semibold">
|
||||
Registar próxima acção
|
||||
</h2>
|
||||
<Field label="Tarefa" error={task.errors.title}>
|
||||
<input
|
||||
className={control}
|
||||
value={task.data.title}
|
||||
onChange={(e) => task.setData('title', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Prazo (hora local)" error={task.errors.due_at}>
|
||||
<input
|
||||
type="datetime-local"
|
||||
className={control}
|
||||
value={task.data.due_at}
|
||||
onChange={(e) => task.setData('due_at', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field
|
||||
label="Responsável pela tarefa"
|
||||
error={task.errors.assignee_user_id}
|
||||
>
|
||||
<select
|
||||
className={control}
|
||||
value={task.data.assignee_user_id}
|
||||
onChange={(e) =>
|
||||
task.setData('assignee_user_id', e.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione</option>
|
||||
{owners.map((owner) => (
|
||||
<option key={owner.id} value={owner.id}>
|
||||
{owner.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<button className={button} disabled={task.processing}>
|
||||
Criar tarefa
|
||||
</button>
|
||||
</form>
|
||||
<CrmTaskCreation
|
||||
key={`${lead.id}:${taskCreation.actor_id}`}
|
||||
lead={lead}
|
||||
owners={owners}
|
||||
context={taskCreation}
|
||||
/>
|
||||
</Management>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
export type Owner = { id: number; name: string };
|
||||
export type Task = {
|
||||
version_no: number;
|
||||
can_update?: boolean;
|
||||
id: string;
|
||||
title: string;
|
||||
status: string;
|
||||
@@ -7,6 +9,7 @@ export type Task = {
|
||||
assignee_user_id: number | null;
|
||||
};
|
||||
export type Lead = {
|
||||
version_no: number;
|
||||
id: string;
|
||||
title: string;
|
||||
status: string;
|
||||
|
||||
Reference in New Issue
Block a user