fix: official preset add button — write settings.json first, handle errors

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
程序员阿江(Relakkes) 2026-04-07 12:12:22 +08:00
parent d3d3e0ce2a
commit 1b190524e5

View File

@ -255,13 +255,7 @@ function ProviderFormModal({ open, onClose, mode, provider }: ProviderFormProps)
if (!canSubmit) return
setIsSubmitting(true)
try {
if (isOfficial) {
await useProviderStore.getState().activateOfficial()
await fetchSettings()
onClose()
return
}
// Write the edited settings.json directly
// Write the edited settings.json first (for all presets including official)
if (settingsJson.trim()) {
try {
const parsed = JSON.parse(settingsJson)
@ -272,6 +266,17 @@ function ProviderFormModal({ open, onClose, mode, provider }: ProviderFormProps)
}
}
if (isOfficial) {
try {
await useProviderStore.getState().activateOfficial()
await fetchSettings()
} catch (err) {
console.error('Failed to activate official:', err)
}
onClose()
return
}
if (mode === 'create') {
await createProvider({
presetId: selectedPreset.id,