Refactor organization creation logic for improved readability and maintainability
This commit is contained in:
@@ -112,15 +112,15 @@ class OrganizationBloc extends Bloc<OrganizationEvent, OrganizationState> {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Get existing organizations list
|
||||
List<Organization> existingOrgs = [];
|
||||
Organization? selectedOrg;
|
||||
|
||||
|
||||
if (state is OrganizationLoaded) {
|
||||
existingOrgs = (state as OrganizationLoaded).organizations;
|
||||
selectedOrg = (state as OrganizationLoaded).selectedOrg;
|
||||
|
||||
|
||||
// Check for duplicate name (client-side validation)
|
||||
if (existingOrgs.any((org) => org.name == name)) {
|
||||
emit(
|
||||
@@ -134,7 +134,7 @@ class OrganizationBloc extends Bloc<OrganizationEvent, OrganizationState> {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set loading state
|
||||
emit(
|
||||
OrganizationLoaded(
|
||||
@@ -143,13 +143,11 @@ class OrganizationBloc extends Bloc<OrganizationEvent, OrganizationState> {
|
||||
isLoading: true,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
try {
|
||||
final newOrg = await orgApi.createOrganization(name);
|
||||
final updatedOrgs = [...existingOrgs, newOrg];
|
||||
emit(
|
||||
OrganizationLoaded(organizations: updatedOrgs, selectedOrg: newOrg),
|
||||
);
|
||||
emit(OrganizationLoaded(organizations: updatedOrgs, selectedOrg: newOrg));
|
||||
// Reset blocs and load permissions for new org
|
||||
permissionBloc.add(PermissionsReset());
|
||||
fileBrowserBloc.add(ResetFileBrowser());
|
||||
|
||||
Reference in New Issue
Block a user