feat: Improve bulk category update functionality with validation and clearer logic
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user