th-tenant.ts 770 Bytes
import type { ThAppBoundLocationDto } from '#/api/th';

import { defineStore } from 'pinia';

export interface ThTenantContext {
  tenantId: string;
  tenantName: string;
  locations: ThAppBoundLocationDto[];
}

export const useThTenantStore = defineStore('th-tenant', {
  actions: {
    setTenantContext(ctx: Partial<ThTenantContext>) {
      if (ctx.tenantId != null) {
        this.tenantId = ctx.tenantId;
      }
      if (ctx.tenantName != null) {
        this.tenantName = ctx.tenantName;
      }
      if (ctx.locations != null) {
        this.locations = ctx.locations;
      }
    },
  },
  persist: {
    pick: ['tenantId', 'tenantName', 'locations'],
  },
  state: (): ThTenantContext => ({
    tenantId: '',
    tenantName: '',
    locations: [],
  }),
});