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,78 @@
|
||||
import { LoaderFunction } from "react-router";
|
||||
import { useLoaderData, useSearchParams } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import AnalyticsOverview from "~/components/analytics/AnalyticsOverview";
|
||||
import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
||||
import { defaultAnalyticsPeriod, getAnalyticsOverview, isAnalyticsPeriod, type AnalyticsOverview as AnalyticsOverviewDto } from "@toolctrl/db/analytics.server";
|
||||
import PeriodHelper, { defaultPeriodFilter, PeriodFilters } from "~/utils/helpers/PeriodHelper";
|
||||
import InputSelector from "~/components/ui/input/InputSelector";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import Tabs from "~/components/ui/tabs/Tabs";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
|
||||
type LoaderData = {
|
||||
overview: AnalyticsOverviewDto;
|
||||
};
|
||||
export const loader: LoaderFunction = async ({ request }) => {
|
||||
await verifyUserHasPermission(request, "admin.analytics.view");
|
||||
const { locale } = await getTranslations(request);
|
||||
const period = PeriodHelper.getPeriodFromRequest({ request });
|
||||
const data: LoaderData = {
|
||||
overview: await getAnalyticsOverview({
|
||||
withUsers: true,
|
||||
period: isAnalyticsPeriod(period) ? period : defaultAnalyticsPeriod,
|
||||
portalId: undefined,
|
||||
locale,
|
||||
}),
|
||||
};
|
||||
return Response.json(data);
|
||||
};
|
||||
|
||||
export default function AdminAnalyticsOverviewRoute() {
|
||||
const { t } = useTranslation();
|
||||
const { overview } = useLoaderData<LoaderData>();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
return (
|
||||
<>
|
||||
<EditPageLayout>
|
||||
<div className="flex justify-between gap-2">
|
||||
<Tabs
|
||||
breakpoint="lg"
|
||||
tabs={[
|
||||
{ name: t("analytics.overview"), routePath: adminPath("analytics/overview", { mode: "host-aware" }) },
|
||||
{ name: t("analytics.uniqueVisitors"), routePath: adminPath("analytics/visitors", { mode: "host-aware" }) },
|
||||
{ name: t("analytics.pageViews"), routePath: adminPath("analytics/page-views", { mode: "host-aware" }) },
|
||||
{ name: t("analytics.events"), routePath: adminPath("analytics/events", { mode: "host-aware" }) },
|
||||
{ name: t("analytics.settings"), routePath: adminPath("analytics/settings", { mode: "host-aware" }) },
|
||||
]}
|
||||
className="grow"
|
||||
/>
|
||||
|
||||
<InputSelector
|
||||
className="w-44"
|
||||
withSearch={false}
|
||||
name="period"
|
||||
value={searchParams.get("period")?.toString() ?? defaultPeriodFilter}
|
||||
options={PeriodFilters.map((f) => {
|
||||
return {
|
||||
value: f.value,
|
||||
name: t(f.name),
|
||||
};
|
||||
})}
|
||||
setValue={(value) => {
|
||||
if (value && value !== defaultPeriodFilter) {
|
||||
searchParams.set("period", value?.toString() ?? "");
|
||||
} else {
|
||||
searchParams.delete("period");
|
||||
}
|
||||
setSearchParams(searchParams);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<AnalyticsOverview overview={overview} withUsers={true} rootUrl={adminPath("analytics", { mode: "host-aware" })} />
|
||||
</EditPageLayout>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user