Added delete tag button to inventory's edit spool modal

This commit is contained in:
maziggy
2026-03-01 12:04:19 +01:00
parent 1cf40a5c35
commit bf66f7a536
3 changed files with 99 additions and 73 deletions
+29 -3
View File
@@ -1,7 +1,7 @@
import { useState, useEffect, useMemo } from 'react';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useTranslation } from 'react-i18next';
import { X, Loader2, Save, Beaker, Palette, Zap } from 'lucide-react';
import { X, Loader2, Save, Beaker, Palette, Zap, Tag } from 'lucide-react';
import { api } from '../api/client';
import type { InventorySpool, SlicerSetting, SpoolCatalogEntry, LocalPreset } from '../api/client';
import { Button } from './Button';
@@ -360,6 +360,19 @@ export function SpoolFormModal({ isOpen, onClose, spool, printersWithCalibration
},
});
const deleteTagMutation = useMutation({
mutationFn: () =>
api.updateSpool(spool!.id, { tag_uid: null } as Parameters<typeof api.updateSpool>[1]),
onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: ['inventory-spools'] });
showToast(t('inventory.tagDeleted', 'Tag removed'), 'success');
onClose();
},
onError: (error: Error) => {
showToast(error.message, 'error');
},
});
// Save K-profiles for selected calibrations
const saveKProfiles = async (spoolId: number) => {
if (selectedProfiles.size === 0) {
@@ -464,7 +477,7 @@ export function SpoolFormModal({ isOpen, onClose, spool, printersWithCalibration
}
};
const isPending = createMutation.isPending || bulkCreateMutation.isPending || updateMutation.isPending;
const isPending = createMutation.isPending || bulkCreateMutation.isPending || updateMutation.isPending || deleteTagMutation.isPending;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center">
@@ -621,7 +634,19 @@ export function SpoolFormModal({ isOpen, onClose, spool, printersWithCalibration
</div>
{/* Footer */}
<div className="flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0">
<div className="flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0">
{isEditing && (
<Button
variant="secondary"
onClick={() => deleteTagMutation.mutate()}
disabled={isPending || !spool?.tag_uid}
className="mr-auto"
>
<Tag className="w-4 h-4" />
{t('inventory.deleteTag', 'Delete Tag')}
</Button>
)}
<div className="flex gap-2 ml-auto">
<Button variant="secondary" onClick={onClose}>
{t('common.cancel')}
</Button>
@@ -641,6 +666,7 @@ export function SpoolFormModal({ isOpen, onClose, spool, printersWithCalibration
</>
)}
</Button>
</div>
</div>
</div>
</div>
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -23,7 +23,7 @@
<!-- Splash screens for iOS -->
<link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
<script type="module" crossorigin src="/assets/index-Sz3ts5Wy.js"></script>
<script type="module" crossorigin src="/assets/index-C5QNmsOn.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-Dgxdt1Fd.css">
</head>
<body>