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,42 @@
|
||||
import { useEffect } from "react";
|
||||
import { Outlet, useLocation, useNavigate, redirect, MetaFunction, LoaderFunctionArgs } from "react-router";
|
||||
import UrlUtils from "~/utils/app/UrlUtils";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
|
||||
export function isAdminAnalyticsRootPath(pathname: string) {
|
||||
return UrlUtils.stripTrailingSlash(pathname) === adminPath("analytics", { mode: "host-aware" });
|
||||
}
|
||||
|
||||
export function adminAnalyticsRedirectTarget() {
|
||||
return adminPath("analytics/overview", { mode: "host-aware" });
|
||||
}
|
||||
|
||||
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
await verifyUserHasPermission(request, "admin.analytics.view");
|
||||
const { t } = await getTranslations(request);
|
||||
if (isAdminAnalyticsRootPath(new URL(request.url).pathname)) {
|
||||
throw redirect(adminAnalyticsRedirectTarget());
|
||||
}
|
||||
|
||||
return {
|
||||
title: `${t("analytics.title")} | ${process.env.APP_NAME}`,
|
||||
};
|
||||
};
|
||||
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
export default function AdminAnalticsRoute() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
if (isAdminAnalyticsRootPath(location.pathname)) {
|
||||
navigate(adminAnalyticsRedirectTarget());
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [location.pathname]);
|
||||
|
||||
return <Outlet />;
|
||||
}
|
||||
Reference in new issue
Block a user