@@ -2,14 +2,15 @@ import { Form, Formik } from "formik";
2
2
import { PopupSpec } from "@/components/admin/connectors/Popup" ;
3
3
import {
4
4
BooleanFormField ,
5
+ SelectorFormField ,
5
6
TextFormField ,
6
7
} from "@/components/admin/connectors/Field" ;
7
8
import { createApiKey , updateApiKey } from "./lib" ;
8
9
import { Modal } from "@/components/Modal" ;
9
10
import { Button } from "@/components/ui/button" ;
10
11
import { Separator } from "@/components/ui/separator" ;
11
12
import Text from "@/components/ui/text" ;
12
- import { UserRole } from "@/lib/types" ;
13
+ import { USER_ROLE_LABELS , UserRole } from "@/lib/types" ;
13
14
import { APIKey } from "./types" ;
14
15
15
16
interface DanswerApiKeyFormProps {
@@ -39,20 +40,15 @@ export const DanswerApiKeyForm = ({
39
40
< Formik
40
41
initialValues = { {
41
42
name : apiKey ?. api_key_name || "" ,
42
- is_admin : apiKey ?. api_key_role === "admin" ,
43
+ role : apiKey ?. api_key_role || UserRole . BASIC . toString ( ) ,
43
44
} }
44
45
onSubmit = { async ( values , formikHelpers ) => {
45
46
formikHelpers . setSubmitting ( true ) ;
46
47
47
- // Map the boolean to a UserRole string
48
- const role : UserRole = values . is_admin
49
- ? UserRole . ADMIN
50
- : UserRole . BASIC ;
51
-
52
48
// Prepare the payload with the UserRole
53
49
const payload = {
54
50
...values ,
55
- role, // Assign the role directly as a UserRole type
51
+ role : values . role as UserRole , // Assign the role directly as a UserRole type
56
52
} ;
57
53
58
54
let response ;
@@ -98,13 +94,28 @@ export const DanswerApiKeyForm = ({
98
94
autoCompleteDisabled = { true }
99
95
/>
100
96
101
- < BooleanFormField
102
- small
103
- removeIndent
104
- alignTop
105
- name = "is_admin"
106
- label = "Is Admin?"
107
- subtext = "If set, this API key will have access to admin level server API's."
97
+ < SelectorFormField
98
+ // defaultValue is managed by Formik
99
+ label = "Role:"
100
+ subtext = "Select the role for this API key.
101
+ Limited has access to simple public API's.
102
+ Basic has access to regular user API's.
103
+ Admin has access to admin level APIs."
104
+ name = "role"
105
+ options = { [
106
+ {
107
+ name : USER_ROLE_LABELS [ UserRole . LIMITED ] ,
108
+ value : UserRole . LIMITED . toString ( ) ,
109
+ } ,
110
+ {
111
+ name : USER_ROLE_LABELS [ UserRole . BASIC ] ,
112
+ value : UserRole . BASIC . toString ( ) ,
113
+ } ,
114
+ {
115
+ name : USER_ROLE_LABELS [ UserRole . ADMIN ] ,
116
+ value : UserRole . ADMIN . toString ( ) ,
117
+ } ,
118
+ ] }
108
119
/>
109
120
110
121
< Button
0 commit comments