diff --git a/src/components/ContactForm.tsx b/src/components/ContactForm.tsx new file mode 100644 index 0000000..e7f9ca5 --- /dev/null +++ b/src/components/ContactForm.tsx @@ -0,0 +1,141 @@ +import { useSubmission } from "@solidjs/router"; +import { For, Show } from "solid-js"; +import { PixelArrowRight, PixelCheck } from "./icons/pixel"; +import { submitContact } from "~/lib/contact"; +import { mailto, site } from "~/config"; +import { t } from "~/i18n"; + +/** + * The demo request form. + * + * It is a real `
` posting to a server action, so it works before the + * client bundle arrives and keeps working if it never does. The submission + * signal only adds what progressive enhancement cannot: a pending label and + * the field-level error the server decided on. + */ +export default function ContactForm() { + const submission = useSubmission(submitContact); + + const f = t.contact.fields; + const errorCode = () => { + const result = submission.result; + return result && !result.ok ? result.code : null; + }; + const errorFor = (field: string) => { + const code = errorCode(); + if (!code) return null; + const result = submission.result; + if (result && !result.ok && result.field !== field) return null; + return t.contact.errors[code as keyof typeof t.contact.errors] ?? t.contact.errors.unknown; + }; + + return ( +
+ + + +

{t.contact.successTitle}

+

{t.contact.successBody}

+ + {site.email} + +
+ } + > + +

{t.contact.formTitle}

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ {f.interest} +
+ + {option => ( + + )} + +
+
+ +