Skip to content

Commit 8f8c2e3

Browse files
committed
feat: add service for fetching options for users and api tokens
1 parent 5b441aa commit 8f8c2e3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Pages/GlobalConfigurations/Authorization/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
export * from './constants'
1818
export type { UserListFilterParams, UserRoleGroup, UserGroupDTO, UserGroupType } from './types'
1919
export * from './shared'
20+
export * from './service'
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { get } from '@Common/index'
2+
import { SelectPickerCustomOptionType } from '@Shared/Components'
3+
import { stringComparatorBySortOrder } from '@Shared/Helpers'
4+
import { DefaultUserKey } from '@Shared/types'
5+
import { GroupBase } from 'react-select'
6+
7+
export const getUserAndApiTokenOptions = async (): Promise<GroupBase<SelectPickerCustomOptionType<string>>[]> => {
8+
const [{ result: userResponse }, { result: apiTokenResponse }] = await Promise.all([
9+
get('user/v2'),
10+
get('api-token'),
11+
])
12+
13+
return [
14+
{
15+
label: 'Users',
16+
options: (userResponse?.users ?? [])
17+
.sort((a, b) => stringComparatorBySortOrder(a.email_id, b.email_id))
18+
.filter(({ email_id: emailId }) => emailId !== DefaultUserKey.system)
19+
.map(({ email_id: emailId }) => ({
20+
label: emailId,
21+
value: emailId,
22+
})),
23+
},
24+
{
25+
label: 'API Tokens',
26+
options: (apiTokenResponse ?? [])
27+
.sort((a, b) => stringComparatorBySortOrder(a.userIdentifier, b.userIdentifier))
28+
.map(({ userIdentifier }) => ({
29+
label: userIdentifier,
30+
value: userIdentifier,
31+
})),
32+
},
33+
]
34+
}

0 commit comments

Comments
 (0)