Files
ipal-kit/reference/src/seed/forms.ts
T
Radosław SmolińskiandClaude Opus 5.5 8adac41f92 Reference site: Example Studio on ipal-kit (reference/), index for agents, CI job
reference/ is one complete client site on the plugin (made-up company, pl/en,
MongoDB, every library block and template, token standard light/dark, forms,
consent, SEO/GEO, enforced CSP, 2FA, base + demo seeds, Coolify runbook,
smoke tests). It uses the plugin as file:.. (injected) and is not shipped.

- docs/agent/reference-site/INDEX.md (generated by scripts/reference-index.mjs,
  kept current by test/referenceIndex.test.ts)
- AGENT.md section and pointers in ipal-site, ipal-setup, ipal-reference,
  ipal-upgrade, ipal-block; release steps in PROGRAMISTA §8.1b
- CI: reference (fast) on every push, reference-full on main; doctor steps
  wired, commented until ipal-doctor ships

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 15:17:11 +01:00

94 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Seeder } from '@intecion/ipal-kit/seed'
import { richMessage, tx } from './lib'
type Localized = Record<string, string>
const rich = (v: Localized) => Object.fromEntries(Object.entries(v).map(([l, text]) => [l, richMessage(text)]))
const consent = {
blockType: 'checkbox',
label: tx('Zgadzam się na przetwarzanie moich danych w celu odpowiedzi na wiadomość.', 'I agree to the processing of my data to answer this message.'),
name: 'consent', // the name MUST stay `consent`; never pre-ticked
required: true,
width: 100,
}
/** The two e-mails every form sends: a notification to the company and a confirmation to the sender (ipal-form). */
function emails(notifyTo: string, subject: Localized, confirmationSubject: Localized) {
return [
{ emailTo: notifyTo, message: rich(tx('Nowe zgłoszenie z formularza:\n\n{{*:table}}', 'New form submission:\n\n{{*:table}}')), replyTo: '{{email}}', subject },
{
emailTo: '{{email}}',
message: rich(
tx(
'Dzień dobry {{name}},\n\ndziękujemy za wiadomość. Odpowiemy w ciągu jednego dnia roboczego.\n\nTwoje zgłoszenie:\n{{*:table}}',
'Hello {{name}},\n\nthank you for your message. We will reply within one working day.\n\nYour submission:\n{{*:table}}',
),
),
replyTo: notifyTo,
subject: confirmationSubject,
},
]
}
/**
* The site's forms, matched by title. `notifyTo` comes from the Company global (or SEED_NOTIFY_EMAIL),
* never from this file.
*/
export async function seedForms(seed: Seeder, notifyTo: string) {
await seed.upsertBy('forms', { title: 'Contact form' }, {
confirmationMessage: rich(tx('Dziękujemy! Odpowiemy w ciągu jednego dnia roboczego.', 'Thank you! We will reply within one working day.')),
confirmationType: 'message',
emails: emails(notifyTo, tx('Nowa wiadomość ze strony od {{name}}', 'New website message from {{name}}'), tx('Otrzymaliśmy Twoją wiadomość', 'We received your message')),
fields: [
{ blockType: 'text', label: tx('Imię i nazwisko', 'Full name'), name: 'name', required: true, width: 50 },
{ blockType: 'email', label: tx('E-mail', 'E-mail'), name: 'email', required: true, width: 50 },
{ blockType: 'text', label: tx('Telefon', 'Phone'), name: 'phone', width: 50 },
{ blockType: 'textarea', label: tx('Wiadomość', 'Message'), name: 'message', required: true, width: 100 },
consent,
],
submitButtonLabel: tx('Wyślij', 'Send'),
title: 'Contact form',
})
// Step-by-step quote form: steps, choice lists, a date, a message block.
await seed.upsertBy('forms', { title: 'Quote form' }, {
confirmationMessage: rich(tx('Dziękujemy! Wycenę prześlemy w ciągu trzech dni roboczych.', 'Thank you! We will send the quote within three working days.')),
confirmationType: 'message',
emails: emails(notifyTo, tx('Zapytanie o wycenę od {{name}}', 'Quote request from {{name}}'), tx('Otrzymaliśmy Twoje zapytanie', 'We received your request')),
fields: [
{ blockType: 'step', title: tx('Kontakt', 'Contact') },
{ blockType: 'text', label: tx('Imię i nazwisko', 'Full name'), name: 'name', required: true, width: 50 },
{ blockType: 'email', label: tx('E-mail', 'E-mail'), name: 'email', required: true, width: 50 },
{ blockType: 'step', description: tx('Zaznacz, czego potrzebujesz.', 'Tick what you need.'), title: tx('Projekt', 'Project') },
{
blockType: 'checkboxGroup',
label: tx('Zakres', 'Scope'),
name: 'scope',
options: [
{ label: tx('Projekt budynku', 'Building design'), value: 'building' },
{ label: tx('Projekt wnętrza', 'Interior design'), value: 'interior' },
{ label: tx('Nadzór autorski', 'Site supervision'), value: 'supervision' },
],
required: true,
},
{
blockType: 'radio',
label: tx('Powierzchnia', 'Floor area'),
name: 'area',
options: [
{ label: tx('do 150 m²', 'up to 150 m²'), value: 's' },
{ label: tx('150–500 m²', '150–500 m²'), value: 'm' },
{ label: tx('powyżej 500 m²', 'over 500 m²'), value: 'l' },
],
required: true,
},
{ blockType: 'date', label: tx('Planowany start', 'Planned start'), name: 'start' },
{ blockType: 'message', message: rich(tx('Dane przetwarzamy wyłącznie w celu przygotowania wyceny.', 'We use your data only to prepare the quote.')) },
consent,
],
submitButtonLabel: tx('Wyślij zapytanie', 'Send request'),
title: 'Quote form',
})
}