import { LoaderFunctionArgs, MetaFunction, redirect } from "react-router"; import { Link, useLoaderData } from "react-router"; import { useTranslation } from "react-i18next"; import { MetaTagsDto } from "~/application/dtos/seo/MetaTagsDto"; import Logo from "~/components/brand/Logo"; import { getTranslations } from "~/locale/i18next.server"; import { getTenantSessionIdentityForUser, type TenantSessionIdentity } from "~/utils/db/tenants.db.server"; import { appPath } from "~/utils/app/CanonicalUrlUtils"; import { loadRequiredWebConfig } from "@hivegrid/config"; import { absoluteAppRootPath } from "~/utils/app/CrossHostUrls"; import { requireUserId } from "~/utils/session.server"; import { runWithRlsContext } from "@hivegrid/db/rls-context.server"; type LoaderData = { metatags: MetaTagsDto; currentTenant: Pick; }; export function activeTenantDashboardPath(tenantSlug: string) { return appPath({ tenantSlug, path: "dashboard", mode: "host-aware" }); } export const meta: MetaFunction = ({ data }) => data?.metatags || []; export const loader = async ({ request, params }: LoaderFunctionArgs) => { const { t } = await getTranslations(request); const requestUrl = new URL(request.url); const userId = await requireUserId(request, `${requestUrl.pathname}${requestUrl.search}`); const currentTenant = await getTenantSessionIdentityForUser({ userId, tenant: params.tenant, allowInactiveTenant: true, }); if (!currentTenant) { throw redirect(absoluteAppRootPath(loadRequiredWebConfig().routing)); } return runWithRlsContext({ tenantId: currentTenant.id, userId }, async () => { if (!currentTenant.deactivatedReason) { throw redirect(activeTenantDashboardPath(currentTenant.slug)); } const data: LoaderData = { metatags: [ { title: `${t("shared.deactivated")} | ${process.env.APP_NAME}`, }, ], currentTenant: { name: currentTenant.name, slug: currentTenant.slug, deactivatedReason: currentTenant.deactivatedReason, }, }; return data; }); }; export default function TenantDeactivatedRoute() { const { t } = useTranslation(); const data = useLoaderData(); return ( <>

{data.currentTenant.name}

{t("shared.deactivated")}

{data.currentTenant.deactivatedReason}

{t("shared.reload")}
); }