feat: consolidar desenvolvimentos do portal InvestMoz
This commit is contained in:
+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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user