Improve error handling and logging in data loading for organization settings dialog
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'dart:developer' as developer;
|
||||||
import '../blocs/organization/organization_state.dart';
|
import '../blocs/organization/organization_state.dart';
|
||||||
import '../blocs/permission/permission_state.dart';
|
import '../blocs/permission/permission_state.dart';
|
||||||
import '../models/organization.dart';
|
import '../models/organization.dart';
|
||||||
@@ -46,30 +47,63 @@ class _OrganizationSettingsDialogState
|
|||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
|
|
||||||
try {
|
String? error;
|
||||||
final results = await Future.wait([
|
List<Member> members = [];
|
||||||
widget.orgApi.getMembers(widget.organization.id),
|
List<Invitation> invitations = [];
|
||||||
widget.orgApi.getInvitations(widget.organization.id),
|
List<JoinRequest> joinRequests = [];
|
||||||
widget.orgApi.getJoinRequests(widget.organization.id),
|
String? inviteLink;
|
||||||
widget.orgApi.getInviteLink(widget.organization.id),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!mounted) return;
|
try {
|
||||||
setState(() {
|
members = await widget.orgApi.getMembers(widget.organization.id);
|
||||||
_members = results[0] as List<Member>;
|
|
||||||
_invitations = results[1] as List<Invitation>;
|
|
||||||
_joinRequests = results[2] as List<JoinRequest>;
|
|
||||||
_inviteLink = results[3] as String?;
|
|
||||||
_isLoading = false;
|
|
||||||
_error = null;
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!mounted) return;
|
developer.log(
|
||||||
setState(() {
|
'Error loading members: $e',
|
||||||
_error = e.toString();
|
name: 'OrganizationSettingsDialog',
|
||||||
_isLoading = false;
|
);
|
||||||
});
|
error ??= 'Failed to load members: $e';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
invitations = await widget.orgApi.getInvitations(widget.organization.id);
|
||||||
|
} catch (e) {
|
||||||
|
developer.log(
|
||||||
|
'Error loading invitations: $e',
|
||||||
|
name: 'OrganizationSettingsDialog',
|
||||||
|
);
|
||||||
|
error ??= 'Failed to load invitations: $e';
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
joinRequests = await widget.orgApi.getJoinRequests(
|
||||||
|
widget.organization.id,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
developer.log(
|
||||||
|
'Error loading join requests: $e',
|
||||||
|
name: 'OrganizationSettingsDialog',
|
||||||
|
);
|
||||||
|
error ??= 'Failed to load join requests: $e';
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
inviteLink = await widget.orgApi.getInviteLink(widget.organization.id);
|
||||||
|
} catch (e) {
|
||||||
|
developer.log(
|
||||||
|
'Error loading invite link: $e',
|
||||||
|
name: 'OrganizationSettingsDialog',
|
||||||
|
);
|
||||||
|
error ??= 'Failed to load invite link: $e';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_members = members;
|
||||||
|
_invitations = invitations;
|
||||||
|
_joinRequests = joinRequests;
|
||||||
|
_inviteLink = inviteLink;
|
||||||
|
_isLoading = false;
|
||||||
|
_error = error;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateMemberRole(String userId, String newRole) async {
|
Future<void> _updateMemberRole(String userId, String newRole) async {
|
||||||
|
|||||||
Reference in New Issue
Block a user