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
@@ -5,9 +5,13 @@
|
||||
|
||||
import { FormDefinitionSchema, FormThemeSchema, type FormDefinition, type FormTheme } from "@hivegrid/form-widget";
|
||||
import { getSitekey, resolveCaptchaConfig } from "@hivegrid/captcha";
|
||||
import { useLoaderData } from "react-router";
|
||||
import { isRouteErrorResponse, useLoaderData, useRouteError } from "react-router";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
import { PublicFormRenderer } from "~/modules/forms/public/PublicFormRenderer";
|
||||
import { PublicFormUnavailable } from "~/modules/forms/public/PublicFormUnavailable";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { runWithRlsContext } from "@hivegrid/db/rls-context.server";
|
||||
import { resolvePublicFormSlugRlsIdentity } from "@hivegrid/db/rls-resolvers.server";
|
||||
|
||||
type LoaderResult = {
|
||||
formKey: string;
|
||||
@@ -21,39 +25,56 @@ export async function loader({ params }: { params: { tenant?: string; slug?: str
|
||||
const formSlug = params.slug;
|
||||
if (!tenantSlug || !formSlug) throw new Response(null, { status: 404 });
|
||||
|
||||
const tenant = await db.tenant.findUnique({ where: { slug: tenantSlug }, select: { id: true } });
|
||||
if (!tenant) throw new Response(null, { status: 404 });
|
||||
const identity = await resolvePublicFormSlugRlsIdentity(tenantSlug, formSlug);
|
||||
if (!identity) throw new Response(null, { status: 404 });
|
||||
|
||||
const form = await db.form.findFirst({
|
||||
where: {
|
||||
tenantId: tenant.id,
|
||||
slug: formSlug,
|
||||
isEnabled: true,
|
||||
isPublic: true,
|
||||
status: "published",
|
||||
},
|
||||
select: { key: true, definition: true, theme: true },
|
||||
return runWithRlsContext({ tenantId: identity.tenantId }, async () => {
|
||||
const form = await db.form.findFirst({
|
||||
where: {
|
||||
id: identity.resourceId,
|
||||
tenantId: identity.tenantId,
|
||||
slug: formSlug,
|
||||
isEnabled: true,
|
||||
isPublic: true,
|
||||
status: "published",
|
||||
},
|
||||
select: { key: true, definition: true, theme: true },
|
||||
});
|
||||
if (!form) throw new Response(null, { status: 404 });
|
||||
|
||||
const def = FormDefinitionSchema.safeParse(form.definition);
|
||||
if (!def.success) throw new Response(null, { status: 500 });
|
||||
const theme = FormThemeSchema.safeParse(form.theme ?? {});
|
||||
const captcha = resolveCaptchaConfig(process.env);
|
||||
|
||||
return Response.json({
|
||||
formKey: form.key,
|
||||
definition: def.data,
|
||||
theme: theme.success ? theme.data : {},
|
||||
captcha: {
|
||||
enabled: def.data.captchaEnabled === true,
|
||||
provider: captcha.provider,
|
||||
instanceUrl: captcha.instanceUrl,
|
||||
sitekey: getSitekey(captcha, "forms"),
|
||||
},
|
||||
} satisfies LoaderResult);
|
||||
});
|
||||
if (!form) throw new Response(null, { status: 404 });
|
||||
|
||||
const def = FormDefinitionSchema.safeParse(form.definition);
|
||||
if (!def.success) throw new Response(null, { status: 500 });
|
||||
const theme = FormThemeSchema.safeParse(form.theme ?? {});
|
||||
const captcha = resolveCaptchaConfig(process.env);
|
||||
|
||||
return Response.json({
|
||||
formKey: form.key,
|
||||
definition: def.data,
|
||||
theme: theme.success ? theme.data : {},
|
||||
captcha: {
|
||||
enabled: def.data.captchaEnabled === true,
|
||||
provider: captcha.provider,
|
||||
instanceUrl: captcha.instanceUrl,
|
||||
sitekey: getSitekey(captcha, "forms"),
|
||||
},
|
||||
} satisfies LoaderResult);
|
||||
}
|
||||
|
||||
export default function PublicSlugForm(): React.JSX.Element {
|
||||
return <PublicFormRenderer {...(useLoaderData() as LoaderResult)} />;
|
||||
return <PublicFormRenderer {...(useLoaderData() as LoaderResult)} layout="standalone" />;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the friendly V02 "form not available" page for 404s thrown by the
|
||||
* loader (unknown tenant/slug, unpublished or disabled form). The document
|
||||
* response keeps the thrown 404 status; other errors fall back to the
|
||||
* generic error page.
|
||||
*/
|
||||
export function ErrorBoundary(): React.JSX.Element {
|
||||
const error = useRouteError();
|
||||
if (isRouteErrorResponse(error) && error.status === 404) {
|
||||
return <PublicFormUnavailable variant="standalone" />;
|
||||
}
|
||||
return <ServerError />;
|
||||
}
|
||||
Reference in new issue
Block a user