11import { addDays } from 'date-fns' ;
22import { useState } from 'react' ;
33
4- import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState' ;
54import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons' ;
65import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer' ;
76import { SettingsSkeletonLoader } from '@/settings/components/SettingsSkeletonLoader' ;
@@ -12,7 +11,7 @@ import { Select } from '@/ui/input/components/Select';
1211import { SettingsTextInput } from '@/ui/input/components/SettingsTextInput' ;
1312import { SubMenuTopBarContainer } from '@/ui/layout/page/components/SubMenuTopBarContainer' ;
1413import { useLingui } from '@lingui/react/macro' ;
15- import { useRecoilCallback , useRecoilValue } from 'recoil' ;
14+ import { useRecoilCallback } from 'recoil' ;
1615import { Key } from 'ts-key-enum' ;
1716import { SettingsPath } from 'twenty-shared/types' ;
1817import { getSettingsPath , isDefined } from 'twenty-shared/utils' ;
@@ -29,21 +28,16 @@ export const SettingsDevelopersApiKeysNew = () => {
2928 const { t } = useLingui ( ) ;
3029 const [ generateOneApiKeyToken ] = useGenerateApiKeyTokenMutation ( ) ;
3130 const navigateSettings = useNavigateSettings ( ) ;
32- const currentWorkspace = useRecoilValue ( currentWorkspaceState ) ;
3331 const { data : rolesData , loading : rolesLoading } = useGetRolesQuery ( {
3432 onCompleted : ( data ) => {
3533 if ( isDefined ( data ?. getRoles ) ) {
36- const defaultRole = data . getRoles . find (
37- ( role ) => role . id === currentWorkspace ?. defaultRole ?. id ,
34+ const apiKeyAssignableRoles = data . getRoles . filter (
35+ ( role ) => role . canBeAssignedToApiKeys ,
3836 ) ;
39- if (
40- isDefined ( defaultRole ) &&
41- defaultRole . canBeAssignedToApiKeys &&
42- ! formValues . roleId
43- ) {
37+ if ( ! formValues . roleId && apiKeyAssignableRoles . length > 0 ) {
4438 setFormValues ( ( prev ) => ( {
4539 ...prev ,
46- roleId : defaultRole . id ,
40+ roleId : apiKeyAssignableRoles [ 0 ] . id ,
4741 } ) ) ;
4842 }
4943 }
0 commit comments