85 lines
3.3 KiB
TypeScript
85 lines
3.3 KiB
TypeScript
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<TenantSessionIdentity, "name" | "slug" | "deactivatedReason">;
|
|
};
|
|
|
|
export function activeTenantDashboardPath(tenantSlug: string) {
|
|
return appPath({ tenantSlug, path: "dashboard", mode: "host-aware" });
|
|
}
|
|
export const meta: MetaFunction<typeof loader> = ({ 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<LoaderData>();
|
|
return (
|
|
<>
|
|
<div className="">
|
|
<div className="flex min-h-full flex-col pt-16 pb-12">
|
|
<main className="mx-auto flex w-full max-w-7xl grow flex-col justify-center px-4 sm:px-6 lg:px-8">
|
|
<div className="flex shrink-0 justify-center">
|
|
<Logo />
|
|
</div>
|
|
<div className="py-16">
|
|
<div className="text-center">
|
|
<p className="text-muted-foreground text-sm font-semibold tracking-wide uppercase">{data.currentTenant.name}</p>
|
|
<h1 className="mt-2 text-2xl font-extrabold tracking-tight sm:text-5xl">{t("shared.deactivated")}</h1>
|
|
<p className="text-muted-foreground mt-2 text-lg">{data.currentTenant.deactivatedReason}</p>
|
|
<div className="mt-4 flex">
|
|
<Link to="." className="text-primary hover:text-primary/90 w-full text-center text-sm font-medium hover:underline">
|
|
{t("shared.reload")}
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|