refactor(receipt-import): streamline category tree loading and enhance error handling
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -17,7 +17,7 @@ class EditDialog extends StatefulWidget {
|
||||
final ItemEdit current;
|
||||
final List<ProductOption> products;
|
||||
final List<AdminCategoryNode> categoryTree;
|
||||
final Future<ProductOption?> Function(String name, int categoryId)? onCreate;
|
||||
final Future<ProductOption?> Function(String name, int? categoryId)? onCreate;
|
||||
final ImportProductEntryMode? initialEntryMode;
|
||||
|
||||
const EditDialog({
|
||||
@@ -212,10 +212,6 @@ class _EditDialogState extends State<EditDialog> {
|
||||
showGlobalErrorDialog(context, 'Ange ett produktnamn först.');
|
||||
return;
|
||||
}
|
||||
if (_newCategoryId == null) {
|
||||
showGlobalErrorDialog(context, 'Välj kategori innan du skapar produkten.');
|
||||
return;
|
||||
}
|
||||
if (widget.onCreate == null) {
|
||||
showGlobalErrorDialog(context, 'Produktskapande är inte tillgängligt i den här vyn.');
|
||||
return;
|
||||
@@ -223,7 +219,7 @@ class _EditDialogState extends State<EditDialog> {
|
||||
|
||||
setState(() => _isCreatingProduct = true);
|
||||
try {
|
||||
final newProduct = await widget.onCreate!(trimmedName, _newCategoryId!);
|
||||
final newProduct = await widget.onCreate!(trimmedName, _newCategoryId);
|
||||
if (newProduct == null || !mounted) {
|
||||
if (mounted) {
|
||||
showGlobalErrorDialog(context, 'Kunde inte skapa produkten. Försök igen.');
|
||||
|
||||
Reference in New Issue
Block a user