fix(config): per-provider form state to avoid field cross-talk
All checks were successful
Beta Release / beta (push) Successful in 38s
All checks were successful
Beta Release / beta (push) Successful in 38s
- providerForm is now keyed by provider name - Each provider (minimax/glm/claude) has isolated form data - Validation and save target the specific provider being edited 💘 Generated with Crush Assisted-by: MiniMax-M2.7 via Crush <crush@charm.land>
This commit is contained in:
@@ -6,7 +6,6 @@ import { getLayoutList } from '../i18n/keyboards'
|
|||||||
const PANELS = [
|
const PANELS = [
|
||||||
{ id: 'profile', icon: User },
|
{ id: 'profile', icon: User },
|
||||||
{ id: 'providers', icon: Brain },
|
{ id: 'providers', icon: Brain },
|
||||||
{ id: 'terminal', icon: Monitor },
|
|
||||||
{ id: 'updates', icon: RefreshCw },
|
{ id: 'updates', icon: RefreshCw },
|
||||||
{ id: 'locale', icon: Globe },
|
{ id: 'locale', icon: Globe },
|
||||||
{ id: 'skills', icon: Wrench },
|
{ id: 'skills', icon: Wrench },
|
||||||
@@ -26,7 +25,7 @@ export default function Config({ api }) {
|
|||||||
const [editProfile, setEditProfile] = useState(false)
|
const [editProfile, setEditProfile] = useState(false)
|
||||||
const [editProvider, setEditProvider] = useState(null)
|
const [editProvider, setEditProvider] = useState(null)
|
||||||
const [profileForm, setProfileForm] = useState({})
|
const [profileForm, setProfileForm] = useState({})
|
||||||
const [providerForm, setProviderForm] = useState({})
|
const [providerForm, setProviderForm] = useState({}) // keyed by provider name
|
||||||
const [toast, setToast] = useState(null)
|
const [toast, setToast] = useState(null)
|
||||||
|
|
||||||
|
|
||||||
@@ -108,9 +107,11 @@ export default function Config({ api }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSaveProvider = async () => {
|
const handleSaveProvider = async (name) => {
|
||||||
|
const form = providerForm[name]
|
||||||
|
if (!form) return
|
||||||
try {
|
try {
|
||||||
await api.saveProvider(providerForm)
|
await api.saveProvider({ name, ...form })
|
||||||
setEditProvider(null)
|
setEditProvider(null)
|
||||||
loadData()
|
loadData()
|
||||||
showToast(t('config.saved'))
|
showToast(t('config.saved'))
|
||||||
@@ -120,12 +121,15 @@ export default function Config({ api }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const openProviderEdit = (p) => {
|
const openProviderEdit = (p) => {
|
||||||
setProviderForm({
|
setProviderForm(prev => ({
|
||||||
name: p.name,
|
...prev,
|
||||||
api_key: p.apiKey || '',
|
[p.name]: {
|
||||||
model: p.model || '',
|
name: p.name,
|
||||||
base_url: p.baseURL || '',
|
api_key: p.apiKey || '',
|
||||||
})
|
model: p.model || '',
|
||||||
|
base_url: p.baseURL || '',
|
||||||
|
},
|
||||||
|
}))
|
||||||
setEditProvider(p.name)
|
setEditProvider(p.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,23 +307,26 @@ function PanelProviders({ providers, editProvider, providerForm, setProviderForm
|
|||||||
className="config-form-input"
|
className="config-form-input"
|
||||||
type="password"
|
type="password"
|
||||||
placeholder={t('config.tokenPlaceholder')}
|
placeholder={t('config.tokenPlaceholder')}
|
||||||
value={isEditing ? providerForm.api_key : ''}
|
value={isEditing ? (providerForm[p.name]?.api_key || '') : ''}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
if (!isEditing) openProviderEdit(p)
|
if (!isEditing) openProviderEdit(p)
|
||||||
setProviderForm(f => ({ ...f, api_key: e.target.value }))
|
setProviderForm(prev => ({
|
||||||
|
...prev,
|
||||||
|
[p.name]: { ...(prev[p.name] || {}), api_key: e.target.value },
|
||||||
|
}))
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="provider-setup-token-actions">
|
<div className="provider-setup-token-actions">
|
||||||
<button
|
<button
|
||||||
className="sm primary"
|
className="sm primary"
|
||||||
disabled={validating === p.name || !providerForm.api_key}
|
disabled={validating === p.name || !providerForm[p.name]?.api_key}
|
||||||
onClick={() => handleValidate(p.name, providerForm.api_key, providerForm.model, providerForm.base_url)}
|
onClick={() => handleValidate(p.name, providerForm[p.name]?.api_key, providerForm[p.name]?.model, providerForm[p.name]?.base_url)}
|
||||||
>
|
>
|
||||||
{validating === p.name ? t('config.validating') : t('config.validateKey')}
|
{validating === p.name ? t('config.validating') : t('config.validateKey')}
|
||||||
</button>
|
</button>
|
||||||
{isValidationTarget && validationStatus?.valid && (
|
{isValidationTarget && validationStatus?.valid && (
|
||||||
<button className="sm" onClick={handleSaveProvider}>{t('config.save')}</button>
|
<button className="sm" onClick={() => handleSaveProvider(p.name)}>{t('config.save')}</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user