mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
fix(work-orders): preserve draft technician staging on save [SH-193]
This commit is contained in:
parent
814bbf14ea
commit
f01a79d0b5
2 changed files with 8 additions and 4 deletions
|
|
@ -35,12 +35,12 @@ export function useVendorDialogSave({
|
||||||
setSaveError,
|
setSaveError,
|
||||||
}: UseVendorDialogSaveArgs) {
|
}: UseVendorDialogSaveArgs) {
|
||||||
const resolveSaveVendor = () =>
|
const resolveSaveVendor = () =>
|
||||||
|
allVendors.find((vendor) => String(vendor.id) === selectedKey) ??
|
||||||
allVendors.find(
|
allVendors.find(
|
||||||
(vendor) =>
|
(vendor) =>
|
||||||
vendor.contactName === tech &&
|
vendor.contactName === tech &&
|
||||||
vendor.companyName === (resolvedCompany || anchorCompanyName),
|
vendor.companyName === (resolvedCompany || anchorCompanyName),
|
||||||
) ??
|
) ??
|
||||||
allVendors.find((vendor) => String(vendor.id) === selectedKey) ??
|
|
||||||
selectedVendor;
|
selectedVendor;
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
|
|
@ -50,7 +50,10 @@ export function useVendorDialogSave({
|
||||||
|
|
||||||
if (saveVendor != null && isDraftVendorId(saveVendor.id) && pendingPayload) {
|
if (saveVendor != null && isDraftVendorId(saveVendor.id) && pendingPayload) {
|
||||||
try {
|
try {
|
||||||
const created = await createVendor.mutateAsync(pendingPayload);
|
const created = await createVendor.mutateAsync({
|
||||||
|
...pendingPayload,
|
||||||
|
phone: phone.trim() || pendingPayload.phone,
|
||||||
|
});
|
||||||
saveVendor = vendorToDropdownItem(created);
|
saveVendor = vendorToDropdownItem(created);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : "Failed to create technician";
|
const message = error instanceof Error ? error.message : "Failed to create technician";
|
||||||
|
|
|
||||||
|
|
@ -60,13 +60,14 @@ export function VendorDialog({
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open) {
|
if (open) {
|
||||||
setT(tech);
|
setT(tech);
|
||||||
setPhone(techPhone || phoneForOption(tech, technicianOptions));
|
setPhone(techPhone || phoneForOption(tech, buildTechnicianOptions(vendors, tech, company)));
|
||||||
setNotes("");
|
setNotes("");
|
||||||
setAddedVendors([]);
|
setAddedVendors([]);
|
||||||
setPendingCreates({});
|
setPendingCreates({});
|
||||||
setSaveError(null);
|
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 =
|
const selected =
|
||||||
technicianOptions.find((o) => o.name === t && (!company || o.company === company)) ??
|
technicianOptions.find((o) => o.name === t && (!company || o.company === company)) ??
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue