Explorar o código

calendar: fix stale res fields after selection change during async save

ZiB hai 4 meses
pai
achega
e04bc75ce4
Modificáronse 1 ficheiros con 8 adicións e 5 borrados
  1. 8 5
      room_cal/vue/calendar.html

+ 8 - 5
room_cal/vue/calendar.html

@@ -1809,26 +1809,29 @@ createApp({
       editRef.value  = null;
       editRef.value  = null;
       const original = selection.value?.[field] ?? '';
       const original = selection.value?.[field] ?? '';
       if (newVal === null || newVal === original) return;
       if (newVal === null || newVal === original) return;
+      const targetUid      = selection.value.uid;
+      const targetCheckin  = selection.value.checkin_date;
       stateRef.value = 'saving';
       stateRef.value = 'saving';
       try {
       try {
-        const res = await fetch(`/reservation/${selection.value.uid}`, {
+        const res = await fetch(`/reservation/${targetUid}`, {
           method: 'PATCH',
           method: 'PATCH',
           headers: { 'Content-Type': 'application/json' },
           headers: { 'Content-Type': 'application/json' },
-          body: JSON.stringify({ checkin_date: selection.value.checkin_date, [field]: newVal }),
+          body: JSON.stringify({ checkin_date: targetCheckin, [field]: newVal }),
         });
         });
         if (!res.ok) throw new Error(await res.text());
         if (!res.ok) throw new Error(await res.text());
         const updated = await res.json();
         const updated = await res.json();
+        if (selection.value?.uid !== targetUid) return;
         selection.value.wifi_key  = updated.wifi_key  ?? selection.value.wifi_key;
         selection.value.wifi_key  = updated.wifi_key  ?? selection.value.wifi_key;
         selection.value.wifi_ssid = updated.wifi_ssid ?? selection.value.wifi_ssid;
         selection.value.wifi_ssid = updated.wifi_ssid ?? selection.value.wifi_ssid;
         selection.value.door_code = updated.door_code ?? selection.value.door_code;
         selection.value.door_code = updated.door_code ?? selection.value.door_code;
-        const cd = selection.value.checkin_date;
-        if (reservations.value[cd]) {
-          Object.assign(reservations.value[cd], {
+        if (reservations.value[targetCheckin]) {
+          Object.assign(reservations.value[targetCheckin], {
             wifi_key: updated.wifi_key, wifi_ssid: updated.wifi_ssid, door_code: updated.door_code,
             wifi_key: updated.wifi_key, wifi_ssid: updated.wifi_ssid, door_code: updated.door_code,
           });
           });
         }
         }
         stateRef.value = null;
         stateRef.value = null;
       } catch {
       } catch {
+        if (selection.value?.uid !== targetUid) return;
         setError(stateRef);
         setError(stateRef);
       }
       }
     }
     }