|
@@ -523,13 +523,27 @@ export function SpoolFormModal({
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // Fetch assignment for this spool (to show Unassign button)
|
|
|
|
|
|
|
+ // Fetch assignment for this spool (to show Unassign button). In Spoolman mode
|
|
|
|
|
+ // the slot assignment lives in the spoolman_slot_assignments table keyed by
|
|
|
|
|
+ // spoolman_spool_id, not in the legacy spool_assignments table — #1336 was the
|
|
|
|
|
+ // resulting "Unassign button is always disabled" report.
|
|
|
const { data: assignments } = useQuery({
|
|
const { data: assignments } = useQuery({
|
|
|
queryKey: ['spool-assignments'],
|
|
queryKey: ['spool-assignments'],
|
|
|
queryFn: () => api.getAssignments(),
|
|
queryFn: () => api.getAssignments(),
|
|
|
- enabled: isOpen && isEditing,
|
|
|
|
|
|
|
+ enabled: isOpen && isEditing && !spoolmanMode,
|
|
|
});
|
|
});
|
|
|
- const spoolAssignment = spool ? assignments?.find(a => a.spool_id === spool.id) : undefined;
|
|
|
|
|
|
|
+ const { data: spoolmanSlotAssignments } = useQuery({
|
|
|
|
|
+ queryKey: ['spoolman-slot-assignments-all'],
|
|
|
|
|
+ queryFn: () => api.getSpoolmanSlotAssignments(),
|
|
|
|
|
+ enabled: isOpen && isEditing && spoolmanMode,
|
|
|
|
|
+ });
|
|
|
|
|
+ const spoolAssignment = (() => {
|
|
|
|
|
+ if (!spool) return undefined;
|
|
|
|
|
+ if (spoolmanMode) {
|
|
|
|
|
+ return spoolmanSlotAssignments?.find(a => a.spoolman_spool_id === spool.id);
|
|
|
|
|
+ }
|
|
|
|
|
+ return assignments?.find(a => a.spool_id === spool.id);
|
|
|
|
|
+ })();
|
|
|
|
|
|
|
|
// Read inventory + settings caches (already populated by InventoryPage) to
|
|
// Read inventory + settings caches (already populated by InventoryPage) to
|
|
|
// drive the category autocomplete and low-stock-threshold placeholder. #729
|
|
// drive the category autocomplete and low-stock-threshold placeholder. #729
|
|
@@ -554,12 +568,22 @@ export function SpoolFormModal({
|
|
|
const globalLowStockThreshold = settingsForForm?.low_stock_threshold ?? 20;
|
|
const globalLowStockThreshold = settingsForForm?.low_stock_threshold ?? 20;
|
|
|
|
|
|
|
|
const unassignMutation = useMutation({
|
|
const unassignMutation = useMutation({
|
|
|
- mutationFn: () => {
|
|
|
|
|
|
|
+ mutationFn: async () => {
|
|
|
if (!spoolAssignment) throw new Error('No assignment');
|
|
if (!spoolAssignment) throw new Error('No assignment');
|
|
|
- return api.unassignSpool(spoolAssignment.printer_id, spoolAssignment.ams_id, spoolAssignment.tray_id);
|
|
|
|
|
|
|
+ if (spoolmanMode) {
|
|
|
|
|
+ if (!spool) throw new Error('No spool');
|
|
|
|
|
+ await api.unassignSpoolmanSlot(spool.id);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ await api.unassignSpool(spoolAssignment.printer_id, spoolAssignment.ams_id, spoolAssignment.tray_id);
|
|
|
},
|
|
},
|
|
|
onSuccess: async () => {
|
|
onSuccess: async () => {
|
|
|
- await queryClient.invalidateQueries({ queryKey: ['spool-assignments'] });
|
|
|
|
|
|
|
+ if (spoolmanMode) {
|
|
|
|
|
+ await queryClient.invalidateQueries({ queryKey: ['spoolman-slot-assignments-all'] });
|
|
|
|
|
+ await queryClient.invalidateQueries({ queryKey: ['spoolman-slot-assignments'] });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ await queryClient.invalidateQueries({ queryKey: ['spool-assignments'] });
|
|
|
|
|
+ }
|
|
|
showToast(t('inventory.unassignSuccess', 'Spool unassigned'), 'success');
|
|
showToast(t('inventory.unassignSuccess', 'Spool unassigned'), 'success');
|
|
|
onClose();
|
|
onClose();
|
|
|
},
|
|
},
|