Co-Authored-By: Claude Fable 5.2 <[email protected]>
106 lines
5.1 KiB
TypeScript
106 lines
5.1 KiB
TypeScript
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' },
|
||
// @starter:if demo
|
||
// A File field (forms: { attachments: true }): sent with the notification to the studio, never stored on the site.
|
||
{
|
||
allowedTypes: ['pdf', 'jpg', 'png'],
|
||
blockType: 'file',
|
||
help: tx('Rzuty, zdjęcia lub mapa: PDF, JPG lub PNG, razem do 10 MB.', 'Floor plans, photos or a map: PDF, JPG or PNG, up to 10 MB together.'),
|
||
label: tx('Załączniki (opcjonalnie)', 'Attachments (optional)'),
|
||
maxFiles: 3,
|
||
maxSizeMB: 10,
|
||
name: 'attachment',
|
||
},
|
||
// @starter:endif
|
||
{ 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',
|
||
})
|
||
}
|