Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
@@ -0,0 +1,59 @@
|
||||
// AK-P16c public form URL `/f/:tenant/:slug`.
|
||||
//
|
||||
// This route reuses the sandbox-style embedded renderer but resolves the form
|
||||
// via tenant slug + public form slug instead of the opaque embed key.
|
||||
|
||||
import { FormDefinitionSchema, FormThemeSchema, type FormDefinition, type FormTheme } from "@hivegrid/form-widget";
|
||||
import { getSitekey, resolveCaptchaConfig } from "@hivegrid/captcha";
|
||||
import { useLoaderData } from "react-router";
|
||||
import { PublicFormRenderer } from "~/modules/forms/public/PublicFormRenderer";
|
||||
import { db } from "~/utils/db.server";
|
||||
|
||||
type LoaderResult = {
|
||||
formKey: string;
|
||||
definition: FormDefinition;
|
||||
theme: FormTheme;
|
||||
captcha: { enabled: boolean; provider: "mcaptcha" | "cap"; instanceUrl: string | undefined; sitekey: string | undefined };
|
||||
};
|
||||
|
||||
export async function loader({ params }: { params: { tenant?: string; slug?: string } }): Promise<Response> {
|
||||
const tenantSlug = params.tenant;
|
||||
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 form = await db.form.findFirst({
|
||||
where: {
|
||||
tenantId: tenant.id,
|
||||
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);
|
||||
}
|
||||
|
||||
export default function PublicSlugForm(): React.JSX.Element {
|
||||
return <PublicFormRenderer {...(useLoaderData() as LoaderResult)} />;
|
||||
}
|
||||
Reference in new issue
Block a user