@@ -10,19 +10,25 @@ const OrganizationRedirect: FC = () => {
10
10
organizationPermissionsByOrganizationId : organizationPermissions ,
11
11
} = useOrganizationSettings ( ) ;
12
12
13
+ const sortedOrganizations = [ ...organizations ] . sort (
14
+ ( a , b ) => ( b . is_default ? 1 : 0 ) - ( a . is_default ? 1 : 0 ) ,
15
+ ) ;
16
+
13
17
// Redirect /organizations => /organizations/some-organization-name
14
18
// If they can edit the default org, we should redirect to the default.
15
19
// If they cannot edit the default, we should redirect to the first org that
16
20
// they can edit.
17
- const editableOrg = [ ... organizations ]
18
- . sort ( ( a , b ) => ( b . is_default ? 1 : 0 ) - ( a . is_default ? 1 : 0 ) )
19
- . find ( ( org ) => canEditOrganization ( organizationPermissions [ org . id ] ) ) ;
21
+ const editableOrg = sortedOrganizations . find ( ( org ) =>
22
+ canEditOrganization ( organizationPermissions [ org . id ] ) ,
23
+ ) ;
20
24
if ( editableOrg ) {
21
25
return < Navigate to = { `/organizations/${ editableOrg . name } ` } replace /> ;
22
26
}
23
27
// If they cannot edit any org, just redirect to an org they can read.
24
- if ( organizations . length > 0 ) {
25
- return < Navigate to = { `/organizations/${ organizations [ 0 ] . name } ` } replace /> ;
28
+ if ( sortedOrganizations . length > 0 ) {
29
+ return (
30
+ < Navigate to = { `/organizations/${ sortedOrganizations [ 0 ] . name } ` } replace />
31
+ ) ;
26
32
}
27
33
return < EmptyState message = "No organizations found" /> ;
28
34
} ;
0 commit comments