fix(work-orders): preserve draft technician staging on save [SH-193]

This commit is contained in:
Arthur Bassi 2026-08-10 13:50:20 -03:00
parent 814bbf14ea
commit f01a79d0b5
2 changed files with 8 additions and 4 deletions

View file

@ -35,12 +35,12 @@ export function useVendorDialogSave({
setSaveError,
}: UseVendorDialogSaveArgs) {
const resolveSaveVendor = () =>
allVendors.find((vendor) => String(vendor.id) === selectedKey) ??
allVendors.find(
(vendor) =>
vendor.contactName === tech &&
vendor.companyName === (resolvedCompany || anchorCompanyName),
) ??
allVendors.find((vendor) => String(vendor.id) === selectedKey) ??
selectedVendor;
const handleSave = async () => {
@ -50,7 +50,10 @@ export function useVendorDialogSave({
if (saveVendor != null && isDraftVendorId(saveVendor.id) && pendingPayload) {
try {
const created = await createVendor.mutateAsync(pendingPayload);
const created = await createVendor.mutateAsync({
...pendingPayload,
phone: phone.trim() || pendingPayload.phone,
});
saveVendor = vendorToDropdownItem(created);
} catch (error) {
const message = error instanceof Error ? error.message : "Failed to create technician";

View file

@ -60,13 +60,14 @@ export function VendorDialog({
useEffect(() => {
if (open) {
setT(tech);
setPhone(techPhone || phoneForOption(tech, technicianOptions));
setPhone(techPhone || phoneForOption(tech, buildTechnicianOptions(vendors, tech, company)));
setNotes("");
setAddedVendors([]);
setPendingCreates({});
setSaveError(null);
}
}, [open, tech, techPhone, technicianOptions]);
// Intentionally omit technicianOptions: rebuilding options after Add must not clear staged drafts.
}, [open, tech, techPhone, vendors, company]);
const selected =
technicianOptions.find((o) => o.name === t && (!company || o.company === company)) ??