remove localstorage dependency for wizard

This commit is contained in:
Mayur Shinde
2026-06-10 13:26:10 +05:30
parent 081bf10558
commit a139516d7f
4 changed files with 67 additions and 80 deletions
+11 -12
View File
@@ -179,13 +179,15 @@ export const DISCLAIMER_TEMPLATE =
export const TENANT_CONFIG_VERSION = 'tenant-config-v1';
export const DISCLAIMER_VERSION = 'disclaimer-v1';
// Admin-editable overrides persist here (spec §14). The wizard merges them over
// the defaults so pricing/branding/feature flags are tenant-controlled, not code.
const CONFIG_STORAGE_KEY = 'lup_estimate_wizard_config_v1';
// Admin-editable overrides (spec §14). Held in memory only — like the rest of the
// CRM demo store, nothing is written to localStorage, so this resets on a full page
// reload. The wizard merges these over the defaults so pricing/branding/feature
// flags are tenant-controlled, not code. Module-scoped so the value survives route
// changes within a session (admin → wizard → leads) without persistence.
let configOverrides = {};
// Same-tab change signal. The public wizard snapshots config at mount, so when the
// admin publishes in the SAME tab/SPA there's no `storage` event to react to — we
// dispatch this so an open wizard can refresh without a hard reload.
// Same-tab change signal so an open wizard refreshes when the admin publishes,
// without a hard reload (the in-memory store has no `storage` event to lean on).
export const CONFIG_CHANGE_EVENT = 'lup-estimate-wizard-config-changed';
function notifyConfigChanged() {
@@ -212,19 +214,16 @@ function defaults() {
}
export function loadConfigOverrides() {
try {
const raw = localStorage.getItem(CONFIG_STORAGE_KEY);
return raw ? JSON.parse(raw) : {};
} catch { return {}; }
return configOverrides;
}
export function saveConfigOverrides(overrides) {
try { localStorage.setItem(CONFIG_STORAGE_KEY, JSON.stringify(overrides || {})); } catch { /* quota */ }
configOverrides = overrides || {};
notifyConfigChanged();
}
export function resetConfigOverrides() {
try { localStorage.removeItem(CONFIG_STORAGE_KEY); } catch { /* ignore */ }
configOverrides = {};
notifyConfigChanged();
}