47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
import { LoaderFunctionArgs, MetaFunction, redirect, useLoaderData } from "react-router";
|
|
import PagePlanRequired from "~/components/pages/PagePlanRequired";
|
|
import { getTranslations } from "~/locale/i18next.server";
|
|
import { appPath } from "~/utils/app/CanonicalUrlUtils";
|
|
import { getTenant } from "~/utils/db/tenants.db.server";
|
|
import { getTenantIdFromUrl } from "~/utils/services/.server/urlService";
|
|
import { loadRequiredWebConfig } from "@toolctrl/config";
|
|
import { absoluteAppRootPath } from "~/utils/app/CrossHostUrls";
|
|
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
|
|
|
export function planRequiredSubscriptionSettingsPath(tenantSlug: string) {
|
|
return appPath({ tenantSlug, path: "settings/subscription", mode: "host-aware" });
|
|
}
|
|
|
|
type LoaderData = {
|
|
title: string;
|
|
tenantSlug: string;
|
|
subscriptionPath: string;
|
|
};
|
|
|
|
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title ?? "Plan required" }];
|
|
|
|
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
|
const { t } = await getTranslations(request);
|
|
const tenantId = await getTenantIdFromUrl(params);
|
|
const tenant = await getTenant(tenantId);
|
|
|
|
if (!tenant) {
|
|
throw redirect(absoluteAppRootPath(loadRequiredWebConfig().routing));
|
|
}
|
|
await verifyUserHasPermission(request, "app.settings.subscription.view", tenantId);
|
|
|
|
const data: LoaderData = {
|
|
title: `${t("shared.planRequired")} | ${process.env.APP_NAME}`,
|
|
tenantSlug: tenant.slug,
|
|
subscriptionPath: planRequiredSubscriptionSettingsPath(tenant.slug),
|
|
};
|
|
|
|
return data;
|
|
};
|
|
|
|
export default function PlanRequiredTenantRoute() {
|
|
const data = useLoaderData<LoaderData>();
|
|
|
|
return <PagePlanRequired tenantSlug={data.tenantSlug} subscriptionPath={data.subscriptionPath} />;
|
|
}
|