feat: Improve bulk category update functionality with validation and clearer logic
Test Suite / test (24.15.0) (push) Has been cancelled

This commit is contained in:
Nils-Johan Gynther
2026-05-11 10:22:17 +02:00
parent afbc5b91b2
commit 06056c6182
2 changed files with 20 additions and 8 deletions
@@ -104,14 +104,21 @@ class _AdminProductsPanelState extends ConsumerState<AdminProductsPanel> {
Future<void> _applyBulkCategory() async {
if (_selectedIds.isEmpty || _isApplying) return;
if (_bulkCategoryValue == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Välj en kategori innan du uppdaterar valda produkter.')),
);
return;
}
final categoryId =
_bulkCategoryValue == '__remove__' ? null : int.parse(_bulkCategoryValue!);
setState(() => _isApplying = true);
try {
await ref.read(adminRepositoryProvider).bulkSetCategory(
_selectedIds.toList(),
categoryId: _bulkCategoryValue == null ||
_bulkCategoryValue == '__remove__'
? null
: int.parse(_bulkCategoryValue!),
categoryId: categoryId,
);
if (!mounted) return;
setState(() {
@@ -651,7 +658,9 @@ class _AdminProductsPanelState extends ConsumerState<AdminProductsPanel> {
),
if (!_showDeletedOnly)
FilledButton(
onPressed: _selectedIds.isEmpty || _isApplying
onPressed: _selectedIds.isEmpty ||
_isApplying ||
_bulkCategoryValue == null
? null
: _applyBulkCategory,
child: _isApplying