Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+57
@@ -0,0 +1,57 @@
|
||||
import { runWithRlsContext } from "@hivegrid/db/rls-context.server";
|
||||
import { toFirstStepsChecklistVM, toWelcomeSetupVM, type WelcomeSetupVM } from "@hivegrid/view-models";
|
||||
import { LoaderFunctionArgs, useLoaderData, useNavigate, useRevalidator } from "react-router";
|
||||
|
||||
import { WelcomeSetupPage } from "~/components/screens/onboarding/WelcomeSetupPage";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import UrlUtils from "~/utils/app/UrlUtils";
|
||||
import { getTenant } from "~/utils/db/tenants.db.server";
|
||||
import { getUser } from "~/utils/db/users.db.server";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { getTenantIdFromUrl } from "~/utils/services/.server/urlService";
|
||||
import { getFirstStepsChecklist } from "~/utils/services/.server/akP20OnboardingService";
|
||||
import { getUserInfo } from "~/utils/session.server";
|
||||
|
||||
type LoaderData = { title: string; vm: WelcomeSetupVM; homeHref: string };
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const [{ t }, tenantId, userInfo] = await Promise.all([getTranslations(request), getTenantIdFromUrl(params), getUserInfo(request)]);
|
||||
await verifyUserHasPermission(request, "app.onboarding.checklist.update", tenantId);
|
||||
const [user, tenant, checklist] = await runWithRlsContext({ tenantId, userId: userInfo.userId }, () =>
|
||||
Promise.all([getUser(userInfo.userId), getTenant(tenantId), getFirstStepsChecklist({ tenantId, userId: userInfo.userId })])
|
||||
);
|
||||
if (!user || !tenant) throw new Response(null, { status: 404 });
|
||||
|
||||
const checklistVm = toFirstStepsChecklistVM({
|
||||
...checklist,
|
||||
items: checklist.items.map((item) => ({ ...item, href: UrlUtils.currentTenantUrl(params, item.href) })),
|
||||
});
|
||||
return {
|
||||
title: `${t("onboarding.welcome.metaTitle")} | ${process.env.APP_NAME}`,
|
||||
homeHref: UrlUtils.currentTenantUrl(params, "dashboard"),
|
||||
vm: toWelcomeSetupVM({
|
||||
firstName: user.firstName,
|
||||
workspaceName: tenant.name,
|
||||
dashboardHref: UrlUtils.currentTenantUrl(params, "dashboard"),
|
||||
checklist: checklistVm,
|
||||
}),
|
||||
} satisfies LoaderData;
|
||||
};
|
||||
|
||||
export default function WelcomeSetupRoute() {
|
||||
const data = useLoaderData<LoaderData>();
|
||||
const navigate = useNavigate();
|
||||
const revalidator = useRevalidator();
|
||||
|
||||
return (
|
||||
<WelcomeSetupPage
|
||||
vm={data.vm}
|
||||
homeHref={data.homeHref}
|
||||
actions={{
|
||||
onOpen: (href) => navigate(href),
|
||||
onDashboard: (href) => navigate(href),
|
||||
onRetry: () => revalidator.revalidate(),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user