Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,87 @@
|
||||
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 { TenantWithDetails, getTenant } from "~/utils/db/tenants.db.server";
|
||||
import { appPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { getTenantIdFromUrl } from "~/utils/services/.server/urlService";
|
||||
import { loadRequiredWebConfig } from "@toolctrl/config";
|
||||
import { absoluteAppRootPath } from "~/utils/app/CrossHostUrls";
|
||||
import { TenantUserStatus } from "~/application/enums/tenants/TenantUserStatus";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { requireUserId } from "~/utils/session.server";
|
||||
|
||||
type LoaderData = {
|
||||
metatags: MetaTagsDto;
|
||||
currentTenant: Pick<TenantWithDetails, "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 tenantId = await getTenantIdFromUrl(params);
|
||||
const currentTenant = await getTenant(tenantId);
|
||||
if (!currentTenant) {
|
||||
throw redirect(absoluteAppRootPath(loadRequiredWebConfig().routing));
|
||||
}
|
||||
const tenantMember = await db.tenantUser.findFirst({
|
||||
where: { tenantId, userId, status: TenantUserStatus.ACTIVE },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!tenantMember) {
|
||||
throw redirect(absoluteAppRootPath(loadRequiredWebConfig().routing));
|
||||
}
|
||||
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 pb-12 pt-16">
|
||||
<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 uppercase tracking-wide">{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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user