-
Notifications
You must be signed in to change notification settings - Fork 2.7k
refactor: updated elevenLabs API module and remove button UX
#6781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ export const DictationSettings = () => { | |
| ); | ||
| const [apiKey, setApiKey] = useState(''); | ||
| const [isEditingKey, setIsEditingKey] = useState(false); | ||
| const [keyValidationError, setKeyValidationError] = useState(''); | ||
| const { read, upsert, remove } = useConfig(); | ||
|
|
||
| useEffect(() => { | ||
|
|
@@ -59,49 +58,33 @@ export const DictationSettings = () => { | |
| if (!providerConfig || providerConfig.uses_provider_config) return; | ||
|
|
||
| const trimmedKey = apiKey.trim(); | ||
| if (!trimmedKey) { | ||
| setKeyValidationError('API key is required'); | ||
| return; | ||
| } | ||
| if (!trimmedKey) return; | ||
|
|
||
| try { | ||
| const keyName = providerConfig.config_key!; | ||
| await upsert(keyName, trimmedKey, true); | ||
| setApiKey(''); | ||
| setKeyValidationError(''); | ||
| setIsEditingKey(false); | ||
| const keyName = providerConfig.config_key!; | ||
| await upsert(keyName, trimmedKey, true); | ||
| setApiKey(''); | ||
| setIsEditingKey(false); | ||
|
|
||
| const audioConfig = await getDictationConfig(); | ||
| setProviderStatuses(audioConfig.data || {}); | ||
| } catch (error) { | ||
| console.error('Error saving API key:', error); | ||
| setKeyValidationError('Failed to save API key'); | ||
| } | ||
| const audioConfig = await getDictationConfig(); | ||
| setProviderStatuses(audioConfig.data || {}); | ||
|
Comment on lines
+63
to
+69
|
||
| }; | ||
|
|
||
| const handleRemoveKey = async () => { | ||
| if (!provider) return; | ||
| const providerConfig = providerStatuses[provider]; | ||
| if (!providerConfig || providerConfig.uses_provider_config) return; | ||
|
|
||
| try { | ||
| const keyName = providerConfig.config_key!; | ||
| await remove(keyName, true); | ||
| setApiKey(''); | ||
| setKeyValidationError(''); | ||
| setIsEditingKey(false); | ||
| const keyName = providerConfig.config_key!; | ||
| await remove(keyName, true); | ||
| setApiKey(''); | ||
| setIsEditingKey(false); | ||
|
|
||
| const audioConfig = await getDictationConfig(); | ||
| setProviderStatuses(audioConfig.data || {}); | ||
| } catch (error) { | ||
| console.error('Error removing API key:', error); | ||
| setKeyValidationError('Failed to remove API key'); | ||
| } | ||
| const audioConfig = await getDictationConfig(); | ||
| setProviderStatuses(audioConfig.data || {}); | ||
|
Comment on lines
+77
to
+83
|
||
| }; | ||
|
|
||
| const handleCancelEdit = () => { | ||
| setApiKey(''); | ||
| setKeyValidationError(''); | ||
| setIsEditingKey(false); | ||
| }; | ||
|
|
||
|
|
@@ -193,37 +176,33 @@ export const DictationSettings = () => { | |
| </div> | ||
|
|
||
| {!isEditingKey ? ( | ||
| <Button variant="outline" size="sm" onClick={() => setIsEditingKey(true)}> | ||
| {providerStatuses[provider]?.configured ? 'Update API Key' : 'Add API Key'} | ||
| </Button> | ||
| <div className="flex gap-2 flex-wrap"> | ||
| <Button variant="outline" size="sm" onClick={() => setIsEditingKey(true)}> | ||
| {providerStatuses[provider]?.configured ? 'Update API Key' : 'Add API Key'} | ||
| </Button> | ||
| {providerStatuses[provider]?.configured && ( | ||
| <Button variant="destructive" size="sm" onClick={handleRemoveKey}> | ||
| Remove API Key | ||
| </Button> | ||
| )} | ||
| </div> | ||
| ) : ( | ||
| <div className="space-y-2"> | ||
| <Input | ||
| type="password" | ||
| value={apiKey} | ||
| onChange={(e) => { | ||
| setApiKey(e.target.value); | ||
| if (keyValidationError) setKeyValidationError(''); | ||
| }} | ||
| onChange={(e) => setApiKey(e.target.value)} | ||
| placeholder="Enter your API key" | ||
| className="max-w-md" | ||
| autoFocus | ||
| /> | ||
| {keyValidationError && ( | ||
| <p className="text-xs text-red-600 mt-1">{keyValidationError}</p> | ||
| )} | ||
| <div className="flex gap-2"> | ||
| <Button size="sm" onClick={handleSaveKey}> | ||
| Save | ||
| </Button> | ||
| <Button variant="outline" size="sm" onClick={handleCancelEdit}> | ||
| Cancel | ||
| </Button> | ||
| {providerStatuses[provider]?.configured && ( | ||
| <Button variant="destructive" size="sm" onClick={handleRemoveKey}> | ||
| Remove | ||
| </Button> | ||
| )} | ||
| </div> | ||
| </div> | ||
| )} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clicking “Save” with an empty/whitespace API key currently just returns with no UI feedback, which makes the button appear broken; disable the Save button until a non-empty key is entered or reintroduce a small inline validation message.