Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/utils/data/useAppData.ts
T

29 lines
1.3 KiB
TypeScript

import { useMatches } from "react-router";
import type { SeatType } from "@hivegrid/db/prisma-browser";
import type { SubscriptionBannerVM } from "@hivegrid/view-models";
import { TenantUserType } from "~/application/enums/tenants/TenantUserType";
import { TenantSimple } from "../db/tenants.db.server";
import { TenantSubscriptionWithDetails } from "../db/tenantSubscriptions.db.server";
import { AppOrAdminData } from "./useAppOrAdminData";
export type AppLoaderData = AppOrAdminData & {
currentTenant: TenantSimple;
mySubscription: TenantSubscriptionWithDetails | null;
/**
* Root-route decision for the focused first-purchase gate. A persisted
* signup selection keeps a new tenant locked even where subscriptions are
* not globally required (for example staging demo environments).
*/
subscriptionActivationRequired?: boolean;
billingBanner: SubscriptionBannerVM;
currentRole: TenantUserType;
/** Effective seat type of the current user in this tenant (office vs field, Fundament C). */
effectiveSeatType: SeatType;
};
export function useAppData(): AppLoaderData {
const paths: string[] = ["routes/app.$tenant", "routes/app"];
const appData = (useMatches().find((f) => paths.includes(f.id.toLowerCase()))?.data ?? {}) as AppLoaderData;
return appData;
}