@@ -14,7 +14,6 @@ export const DictationSettings = () => {
1414 ) ;
1515 const [ apiKey , setApiKey ] = useState ( '' ) ;
1616 const [ isEditingKey , setIsEditingKey ] = useState ( false ) ;
17- const [ keyValidationError , setKeyValidationError ] = useState ( '' ) ;
1817 const { read, upsert, remove } = useConfig ( ) ;
1918
2019 useEffect ( ( ) => {
@@ -58,49 +57,33 @@ export const DictationSettings = () => {
5857 if ( ! providerConfig || providerConfig . uses_provider_config ) return ;
5958
6059 const trimmedKey = apiKey . trim ( ) ;
61- if ( ! trimmedKey ) {
62- setKeyValidationError ( 'API key is required' ) ;
63- return ;
64- }
60+ if ( ! trimmedKey ) return ;
6561
66- try {
67- const keyName = providerConfig . config_key ! ;
68- await upsert ( keyName , trimmedKey , true ) ;
69- setApiKey ( '' ) ;
70- setKeyValidationError ( '' ) ;
71- setIsEditingKey ( false ) ;
62+ const keyName = providerConfig . config_key ! ;
63+ await upsert ( keyName , trimmedKey , true ) ;
64+ setApiKey ( '' ) ;
65+ setIsEditingKey ( false ) ;
7266
73- const audioConfig = await getDictationConfig ( ) ;
74- setProviderStatuses ( audioConfig . data || { } ) ;
75- } catch ( error ) {
76- console . error ( 'Error saving API key:' , error ) ;
77- setKeyValidationError ( 'Failed to save API key' ) ;
78- }
67+ const audioConfig = await getDictationConfig ( ) ;
68+ setProviderStatuses ( audioConfig . data || { } ) ;
7969 } ;
8070
8171 const handleRemoveKey = async ( ) => {
8272 if ( ! provider ) return ;
8373 const providerConfig = providerStatuses [ provider ] ;
8474 if ( ! providerConfig || providerConfig . uses_provider_config ) return ;
8575
86- try {
87- const keyName = providerConfig . config_key ! ;
88- await remove ( keyName , true ) ;
89- setApiKey ( '' ) ;
90- setKeyValidationError ( '' ) ;
91- setIsEditingKey ( false ) ;
76+ const keyName = providerConfig . config_key ! ;
77+ await remove ( keyName , true ) ;
78+ setApiKey ( '' ) ;
79+ setIsEditingKey ( false ) ;
9280
93- const audioConfig = await getDictationConfig ( ) ;
94- setProviderStatuses ( audioConfig . data || { } ) ;
95- } catch ( error ) {
96- console . error ( 'Error removing API key:' , error ) ;
97- setKeyValidationError ( 'Failed to remove API key' ) ;
98- }
81+ const audioConfig = await getDictationConfig ( ) ;
82+ setProviderStatuses ( audioConfig . data || { } ) ;
9983 } ;
10084
10185 const handleCancelEdit = ( ) => {
10286 setApiKey ( '' ) ;
103- setKeyValidationError ( '' ) ;
10487 setIsEditingKey ( false ) ;
10588 } ;
10689
@@ -192,37 +175,33 @@ export const DictationSettings = () => {
192175 </ div >
193176
194177 { ! isEditingKey ? (
195- < Button variant = "outline" size = "sm" onClick = { ( ) => setIsEditingKey ( true ) } >
196- { providerStatuses [ provider ] ?. configured ? 'Update API Key' : 'Add API Key' }
197- </ Button >
178+ < div className = "flex gap-2 flex-wrap" >
179+ < Button variant = "outline" size = "sm" onClick = { ( ) => setIsEditingKey ( true ) } >
180+ { providerStatuses [ provider ] ?. configured ? 'Update API Key' : 'Add API Key' }
181+ </ Button >
182+ { providerStatuses [ provider ] ?. configured && (
183+ < Button variant = "destructive" size = "sm" onClick = { handleRemoveKey } >
184+ Remove API Key
185+ </ Button >
186+ ) }
187+ </ div >
198188 ) : (
199189 < div className = "space-y-2" >
200190 < Input
201191 type = "password"
202192 value = { apiKey }
203- onChange = { ( e ) => {
204- setApiKey ( e . target . value ) ;
205- if ( keyValidationError ) setKeyValidationError ( '' ) ;
206- } }
193+ onChange = { ( e ) => setApiKey ( e . target . value ) }
207194 placeholder = "Enter your API key"
208195 className = "max-w-md"
209196 autoFocus
210197 />
211- { keyValidationError && (
212- < p className = "text-xs text-red-600 mt-1" > { keyValidationError } </ p >
213- ) }
214198 < div className = "flex gap-2" >
215199 < Button size = "sm" onClick = { handleSaveKey } >
216200 Save
217201 </ Button >
218202 < Button variant = "outline" size = "sm" onClick = { handleCancelEdit } >
219203 Cancel
220204 </ Button >
221- { providerStatuses [ provider ] ?. configured && (
222- < Button variant = "destructive" size = "sm" onClick = { handleRemoveKey } >
223- Remove
224- </ Button >
225- ) }
226205 </ div >
227206 </ div >
228207 ) }
0 commit comments