ignore folder
This commit is contained in:
31
store/tenantStore.ts
Normal file
31
store/tenantStore.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { create } from "zustand";
|
||||
|
||||
type TenantState = {
|
||||
tenantId: string;
|
||||
availableTenants: string[];
|
||||
};
|
||||
|
||||
type TenantAction = {
|
||||
setTenantId: (tenantId: string) => void;
|
||||
hydrate: () => void;
|
||||
};
|
||||
|
||||
const STORAGE_KEY = "utms-ng-tenant";
|
||||
const fallbackTenants = ["acme", "global", "demo"];
|
||||
|
||||
export const useTenantStore = create<TenantState & TenantAction>((set, get) => ({
|
||||
tenantId: process.env.NEXT_PUBLIC_DEFAULT_TENANT || "acme",
|
||||
availableTenants: Array.from(
|
||||
new Set([process.env.NEXT_PUBLIC_DEFAULT_TENANT || "acme", ...fallbackTenants])
|
||||
),
|
||||
setTenantId: (tenantId) => {
|
||||
set({ tenantId });
|
||||
if (typeof window !== "undefined") localStorage.setItem(STORAGE_KEY, tenantId);
|
||||
},
|
||||
hydrate: () => {
|
||||
if (typeof window === "undefined") return;
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (raw) set({ tenantId: raw });
|
||||
else set({ tenantId: get().tenantId });
|
||||
}
|
||||
}));
|
||||
Reference in New Issue
Block a user