This commit is contained in:
phaichayon
2026-06-22 15:49:31 +07:00
parent 1b901efc51
commit 3f28fde39f
36 changed files with 2602 additions and 56 deletions

View File

@@ -38,6 +38,7 @@ function toDefaultValues(
return {
customerId: enquiry?.customerId ?? referenceData.customers[0]?.id ?? '',
contactId: enquiry?.contactId ?? undefined,
assignedToUserId: enquiry?.assignedToUserId ?? undefined,
title: enquiry?.title ?? '',
description: enquiry?.description ?? '',
requirement: enquiry?.requirement ?? '',
@@ -110,6 +111,7 @@ export function EnquiryFormSheet({
const contactsForCustomer = referenceData.contacts.filter(
(contact) => contact.customerId === selectedCustomerId
);
const selectedCustomer = referenceData.customers.find((customer) => customer.id === selectedCustomerId);
const form = useAppForm({
defaultValues,
@@ -120,6 +122,7 @@ export function EnquiryFormSheet({
const payload: EnquiryMutationPayload = {
customerId: value.customerId,
contactId: value.contactId || null,
assignedToUserId: value.assignedToUserId || null,
title: value.title,
description: value.description,
requirement: value.requirement,
@@ -177,6 +180,17 @@ export function EnquiryFormSheet({
);
}, [defaultValues, enquiry, form, open, projectPartiesQuery.data?.items]);
useEffect(() => {
if (!open || isEdit) {
return;
}
const ownerUserId =
referenceData.customers.find((customer) => customer.id === selectedCustomerId)?.ownerUserId ?? '';
form.setFieldValue('assignedToUserId', ownerUserId);
}, [form, isEdit, open, referenceData.customers, selectedCustomerId]);
const isPending = createMutation.isPending || updateMutation.isPending;
const recordLabel = workspace === 'lead' ? 'ลีด' : 'โอกาสขาย';
@@ -262,6 +276,19 @@ export function EnquiryFormSheet({
</field.FieldSet>
)}
/>
<FormSelectField
name='assignedToUserId'
label='Suggested Sales Owner'
description={
selectedCustomer?.ownerName
? `Suggested from customer owner: ${selectedCustomer.ownerName}`
: 'Optional sales owner suggestion for this lead or enquiry'
}
options={referenceData.assignableUsers.map((user) => ({
value: user.id,
label: user.name
}))}
/>
<FormTextField
name='title'