fix: DB values override env vars in campaign settings, Settings page resets on campaign switch
All checks were successful
Build and Push / build (push) Successful in 12m16s
All checks were successful
Build and Push / build (push) Successful in 12m16s
This commit is contained in:
@@ -85,13 +85,13 @@ CAMPAIGN_ENV_OVERRIDES = {
|
||||
|
||||
|
||||
def merge_campaign_settings_with_env(raw: dict) -> dict:
|
||||
"""Priority: env var > DB value > CAMPAIGN_SETTINGS default."""
|
||||
"""Priority: DB value > env var > CAMPAIGN_SETTINGS default."""
|
||||
merged = {**CAMPAIGN_SETTINGS}
|
||||
for key, val in raw.items():
|
||||
if val and val.strip():
|
||||
merged[key] = val.strip()
|
||||
for key, env_name in CAMPAIGN_ENV_OVERRIDES.items():
|
||||
val = os.environ.get(env_name)
|
||||
if val is not None:
|
||||
merged[key] = val
|
||||
for key, val in raw.items():
|
||||
if val and val.strip():
|
||||
merged[key] = val.strip()
|
||||
return merged
|
||||
|
||||
@@ -6,15 +6,18 @@ export default function Settings() {
|
||||
const { currentCampaign } = useCampaign();
|
||||
const [settings, setSettings] = useState<any>(null);
|
||||
const [saved, setSaved] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const campaignId = currentCampaign?.id;
|
||||
|
||||
useEffect(() => {
|
||||
if (!campaignId) return;
|
||||
api.getCampaignSettings(campaignId).then(setSettings);
|
||||
setSettings(null);
|
||||
setLoading(true);
|
||||
api.getCampaignSettings(campaignId).then(s => { setSettings(s); setLoading(false); });
|
||||
}, [campaignId]);
|
||||
|
||||
if (!settings || !campaignId) return null;
|
||||
if (!settings || !campaignId) return loading ? <div className="max-w-4xl mx-auto py-16 px-4"><p className="text-ink/40">Loading...</p></div> : null;
|
||||
|
||||
const set = (k: string, v: any) => setSettings({ ...settings, [k]: v });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user