Show UI drift marker for env draft vs Vercel config

This commit is contained in:
CJACK.
2026-03-21 17:08:43 +08:00
parent 1e7e0b2ae3
commit 43a6e6712f
12 changed files with 131 additions and 15 deletions

View File

@@ -1,5 +1,7 @@
import { useCallback, useEffect, useState } from 'react'
const ENV_DRAFT_KEY = 'ds2api_env_config_draft_v1'
export function useAdminConfig({ token, showMessage, t }) {
const [config, setConfig] = useState({ keys: [], accounts: [] })
@@ -11,6 +13,21 @@ export function useAdminConfig({ token, showMessage, t }) {
})
if (res.ok) {
const data = await res.json()
if (data?.env_backed) {
const rawDraft = localStorage.getItem(ENV_DRAFT_KEY)
if (rawDraft) {
try {
const draft = JSON.parse(rawDraft)
setConfig({ ...draft, env_backed: true })
return
} catch (_e) {
localStorage.removeItem(ENV_DRAFT_KEY)
}
}
localStorage.setItem(ENV_DRAFT_KEY, JSON.stringify(data))
} else {
localStorage.removeItem(ENV_DRAFT_KEY)
}
setConfig(data)
}
} catch (e) {
@@ -21,6 +38,17 @@ export function useAdminConfig({ token, showMessage, t }) {
useEffect(() => {
if (token) {
const rawDraft = localStorage.getItem(ENV_DRAFT_KEY)
if (rawDraft) {
try {
const draft = JSON.parse(rawDraft)
if (draft?.env_backed) {
setConfig(draft)
}
} catch (_e) {
localStorage.removeItem(ENV_DRAFT_KEY)
}
}
fetchConfig()
}
}, [fetchConfig, token])