From 113a7657e4a517b8b25514151380a6297e4dfbeb Mon Sep 17 00:00:00 2001 From: Sam Richard Date: Tue, 13 Jun 2023 14:04:32 -0400 Subject: [PATCH] Add subscription form Slightly better handling from previous form, and no longer redirects to a new page as that felt excessive. --- astro/src/pages/[lang]/subscribe.astro | 171 +++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 astro/src/pages/[lang]/subscribe.astro diff --git a/astro/src/pages/[lang]/subscribe.astro b/astro/src/pages/[lang]/subscribe.astro new file mode 100644 index 00000000..05e22f29 --- /dev/null +++ b/astro/src/pages/[lang]/subscribe.astro @@ -0,0 +1,171 @@ +--- +import countries from 'i18n-iso-countries'; +import { getMicrocopy, getLanguages } from '$$microcopy'; +import Wrapper from '$layouts/wrapper.astro'; +import Input from '$components/Input.svelte'; +import { renderMarkdown } from '$lib/markdown'; + +/** + * Builds paths for content files + * @return {object[]} Paths + */ +export function getStaticPaths() { + const languages = getLanguages(); + return languages.map((l) => ({ + params: { + lang: l.code, + }, + props: { + microcopy: getMicrocopy(l.code), + }, + })); +} + +const { microcopy } = Astro.props; +const { locale, newsletter } = microcopy; +const fields = newsletter.fields.map((f) => { + const field = { + type: f.type, + required: f.required, + label: f.label, + name: f.name, + }; + + const text = {}; + + if (f.required) { + text.required = newsletter.content.required; + } + if (f.error) { + text.error = f.error; + } + + if (Object.keys(text).length) { + field.text = text; + } + + if (f.options) { + field.options = f.options; + } + + if (f.value) { + field.value = f.value; + } + + if (f.type === 'country') { + field.options = Object.entries(countries.getNames(locale.code)).map( + ([code, name]) => ({ value: code, text: name }), + ); + field.type = 'select'; + } + + return field; +}); + +const generic = ['submit', 'button', 'radio']; +const full = ['EmailAddress']; +const { content: disclaimer } = await renderMarkdown( + newsletter.content.disclaimer, +); +--- + + +
+
+
+ + + +