import { useCrmTaskCreation } from '@/lib/crm-task-creation'; import type { TaskCreationContext } from '@/lib/crm-task-creation'; import type { Lead, Owner } from '@/pages/crm/types'; import { Field, button, control } from '@/pages/management/shared'; import { useState } from 'react'; export default function CrmTaskCreation({ lead, owners, context, }: { lead: Lead; owners: Owner[]; context: TaskCreationContext; }) { const edit = useCrmTaskCreation(lead, context); const { form } = edit; const [showPreparation, setShowPreparation] = useState(false); const preparation = edit.preparation; const labels = { title: 'Tarefa', due_at: 'Prazo', assignee_user_id: 'Responsável pela tarefa', }; function display(field: keyof typeof labels, value: string) { if (!value) return 'Por preencher'; if (field === 'assignee_user_id') return ( owners.find((owner) => String(owner.id) === value)?.name ?? 'Responsável anterior indisponível' ); if (field === 'due_at') { const date = new Date(value); return Number.isNaN(date.getTime()) ? 'Prazo por confirmar' : new Intl.DateTimeFormat('pt-MZ', { dateStyle: 'medium', timeStyle: 'short', timeZone: 'Africa/Maputo', }).format(date) + ' (Maputo)'; } return value; } const missing = form.data.assignee_user_id && !owners.some( (owner) => String(owner.id) === form.data.assignee_user_id, ); const sentDate = edit.sent ? new Date(edit.sent.due_at) : null; const sentDeadline = sentDate && !Number.isNaN(sentDate.getTime()) ? new Intl.DateTimeFormat('pt-MZ', { dateStyle: 'medium', timeStyle: 'short', timeZone: 'Africa/Maputo', }).format(sentDate) + ' (Maputo)' : 'Prazo por confirmar'; return (
); }