Form seed template: fields, confirmation, company notification and sender confirmation in every language
The ipal-form skill now requires seeding each form (scripts/seed-form-*.ts):
idempotent, reads the notification inbox from the panel and stops without
one, adds both e-mails ({{email}} is safe since submitForm accepts exactly one
address). Verified on the dev sandbox in pl + en. Dev sandbox enables forms.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -71,6 +71,8 @@ export interface Config {
|
||||
pages: Page;
|
||||
posts: Post;
|
||||
media: Media;
|
||||
forms: Form;
|
||||
'form-submissions': FormSubmission;
|
||||
'payload-kv': PayloadKv;
|
||||
'payload-locked-documents': PayloadLockedDocument;
|
||||
'payload-preferences': PayloadPreference;
|
||||
@@ -82,6 +84,8 @@ export interface Config {
|
||||
pages: PagesSelect<false> | PagesSelect<true>;
|
||||
posts: PostsSelect<false> | PostsSelect<true>;
|
||||
media: MediaSelect<false> | MediaSelect<true>;
|
||||
forms: FormsSelect<false> | FormsSelect<true>;
|
||||
'form-submissions': FormSubmissionsSelect<false> | FormSubmissionsSelect<true>;
|
||||
'payload-kv': PayloadKvSelect<false> | PayloadKvSelect<true>;
|
||||
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
|
||||
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
|
||||
@@ -223,6 +227,188 @@ export interface Post {
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "forms".
|
||||
*/
|
||||
export interface Form {
|
||||
id: number;
|
||||
title: string;
|
||||
fields?:
|
||||
| (
|
||||
| {
|
||||
name: string;
|
||||
label?: string | null;
|
||||
width?: number | null;
|
||||
required?: boolean | null;
|
||||
defaultValue?: boolean | null;
|
||||
id?: string | null;
|
||||
blockName?: string | null;
|
||||
blockType: 'checkbox';
|
||||
}
|
||||
| {
|
||||
name: string;
|
||||
label?: string | null;
|
||||
width?: number | null;
|
||||
required?: boolean | null;
|
||||
id?: string | null;
|
||||
blockName?: string | null;
|
||||
blockType: 'country';
|
||||
}
|
||||
| {
|
||||
name: string;
|
||||
label?: string | null;
|
||||
width?: number | null;
|
||||
required?: boolean | null;
|
||||
id?: string | null;
|
||||
blockName?: string | null;
|
||||
blockType: 'email';
|
||||
}
|
||||
| {
|
||||
message?: {
|
||||
root: {
|
||||
type: string;
|
||||
children: {
|
||||
type: any;
|
||||
version: number;
|
||||
[k: string]: unknown;
|
||||
}[];
|
||||
direction: ('ltr' | 'rtl') | null;
|
||||
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
|
||||
indent: number;
|
||||
version: number;
|
||||
};
|
||||
[k: string]: unknown;
|
||||
} | null;
|
||||
id?: string | null;
|
||||
blockName?: string | null;
|
||||
blockType: 'message';
|
||||
}
|
||||
| {
|
||||
name: string;
|
||||
label?: string | null;
|
||||
width?: number | null;
|
||||
defaultValue?: number | null;
|
||||
required?: boolean | null;
|
||||
id?: string | null;
|
||||
blockName?: string | null;
|
||||
blockType: 'number';
|
||||
}
|
||||
| {
|
||||
name: string;
|
||||
label?: string | null;
|
||||
width?: number | null;
|
||||
defaultValue?: string | null;
|
||||
placeholder?: string | null;
|
||||
options?:
|
||||
| {
|
||||
label: string;
|
||||
value: string;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
required?: boolean | null;
|
||||
id?: string | null;
|
||||
blockName?: string | null;
|
||||
blockType: 'select';
|
||||
}
|
||||
| {
|
||||
name: string;
|
||||
label?: string | null;
|
||||
width?: number | null;
|
||||
required?: boolean | null;
|
||||
id?: string | null;
|
||||
blockName?: string | null;
|
||||
blockType: 'state';
|
||||
}
|
||||
| {
|
||||
name: string;
|
||||
label?: string | null;
|
||||
width?: number | null;
|
||||
defaultValue?: string | null;
|
||||
required?: boolean | null;
|
||||
id?: string | null;
|
||||
blockName?: string | null;
|
||||
blockType: 'text';
|
||||
}
|
||||
| {
|
||||
name: string;
|
||||
label?: string | null;
|
||||
width?: number | null;
|
||||
defaultValue?: string | null;
|
||||
required?: boolean | null;
|
||||
id?: string | null;
|
||||
blockName?: string | null;
|
||||
blockType: 'textarea';
|
||||
}
|
||||
)[]
|
||||
| null;
|
||||
submitButtonLabel?: string | null;
|
||||
confirmationType?: ('message' | 'redirect') | null;
|
||||
confirmationMessage?: {
|
||||
root: {
|
||||
type: string;
|
||||
children: {
|
||||
type: any;
|
||||
version: number;
|
||||
[k: string]: unknown;
|
||||
}[];
|
||||
direction: ('ltr' | 'rtl') | null;
|
||||
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
|
||||
indent: number;
|
||||
version: number;
|
||||
};
|
||||
[k: string]: unknown;
|
||||
} | null;
|
||||
redirect?: {
|
||||
url: string;
|
||||
};
|
||||
emails?:
|
||||
| {
|
||||
emailTo?: string | null;
|
||||
cc?: string | null;
|
||||
bcc?: string | null;
|
||||
replyTo?: string | null;
|
||||
emailFrom?: string | null;
|
||||
subject: string;
|
||||
message?: {
|
||||
root: {
|
||||
type: string;
|
||||
children: {
|
||||
type: any;
|
||||
version: number;
|
||||
[k: string]: unknown;
|
||||
}[];
|
||||
direction: ('ltr' | 'rtl') | null;
|
||||
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
|
||||
indent: number;
|
||||
version: number;
|
||||
};
|
||||
[k: string]: unknown;
|
||||
} | null;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "form-submissions".
|
||||
*/
|
||||
export interface FormSubmission {
|
||||
id: number;
|
||||
form: number | Form;
|
||||
submissionData?:
|
||||
| {
|
||||
field: string;
|
||||
value: string;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "payload-kv".
|
||||
@@ -262,6 +448,14 @@ export interface PayloadLockedDocument {
|
||||
| ({
|
||||
relationTo: 'media';
|
||||
value: number | Media;
|
||||
} | null)
|
||||
| ({
|
||||
relationTo: 'forms';
|
||||
value: number | Form;
|
||||
} | null)
|
||||
| ({
|
||||
relationTo: 'form-submissions';
|
||||
value: number | FormSubmission;
|
||||
} | null);
|
||||
globalSlug?: string | null;
|
||||
user: {
|
||||
@@ -380,6 +574,155 @@ export interface MediaSelect<T extends boolean = true> {
|
||||
focalX?: T;
|
||||
focalY?: T;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "forms_select".
|
||||
*/
|
||||
export interface FormsSelect<T extends boolean = true> {
|
||||
title?: T;
|
||||
fields?:
|
||||
| T
|
||||
| {
|
||||
checkbox?:
|
||||
| T
|
||||
| {
|
||||
name?: T;
|
||||
label?: T;
|
||||
width?: T;
|
||||
required?: T;
|
||||
defaultValue?: T;
|
||||
id?: T;
|
||||
blockName?: T;
|
||||
};
|
||||
country?:
|
||||
| T
|
||||
| {
|
||||
name?: T;
|
||||
label?: T;
|
||||
width?: T;
|
||||
required?: T;
|
||||
id?: T;
|
||||
blockName?: T;
|
||||
};
|
||||
email?:
|
||||
| T
|
||||
| {
|
||||
name?: T;
|
||||
label?: T;
|
||||
width?: T;
|
||||
required?: T;
|
||||
id?: T;
|
||||
blockName?: T;
|
||||
};
|
||||
message?:
|
||||
| T
|
||||
| {
|
||||
message?: T;
|
||||
id?: T;
|
||||
blockName?: T;
|
||||
};
|
||||
number?:
|
||||
| T
|
||||
| {
|
||||
name?: T;
|
||||
label?: T;
|
||||
width?: T;
|
||||
defaultValue?: T;
|
||||
required?: T;
|
||||
id?: T;
|
||||
blockName?: T;
|
||||
};
|
||||
select?:
|
||||
| T
|
||||
| {
|
||||
name?: T;
|
||||
label?: T;
|
||||
width?: T;
|
||||
defaultValue?: T;
|
||||
placeholder?: T;
|
||||
options?:
|
||||
| T
|
||||
| {
|
||||
label?: T;
|
||||
value?: T;
|
||||
id?: T;
|
||||
};
|
||||
required?: T;
|
||||
id?: T;
|
||||
blockName?: T;
|
||||
};
|
||||
state?:
|
||||
| T
|
||||
| {
|
||||
name?: T;
|
||||
label?: T;
|
||||
width?: T;
|
||||
required?: T;
|
||||
id?: T;
|
||||
blockName?: T;
|
||||
};
|
||||
text?:
|
||||
| T
|
||||
| {
|
||||
name?: T;
|
||||
label?: T;
|
||||
width?: T;
|
||||
defaultValue?: T;
|
||||
required?: T;
|
||||
id?: T;
|
||||
blockName?: T;
|
||||
};
|
||||
textarea?:
|
||||
| T
|
||||
| {
|
||||
name?: T;
|
||||
label?: T;
|
||||
width?: T;
|
||||
defaultValue?: T;
|
||||
required?: T;
|
||||
id?: T;
|
||||
blockName?: T;
|
||||
};
|
||||
};
|
||||
submitButtonLabel?: T;
|
||||
confirmationType?: T;
|
||||
confirmationMessage?: T;
|
||||
redirect?:
|
||||
| T
|
||||
| {
|
||||
url?: T;
|
||||
};
|
||||
emails?:
|
||||
| T
|
||||
| {
|
||||
emailTo?: T;
|
||||
cc?: T;
|
||||
bcc?: T;
|
||||
replyTo?: T;
|
||||
emailFrom?: T;
|
||||
subject?: T;
|
||||
message?: T;
|
||||
id?: T;
|
||||
};
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "form-submissions_select".
|
||||
*/
|
||||
export interface FormSubmissionsSelect<T extends boolean = true> {
|
||||
form?: T;
|
||||
submissionData?:
|
||||
| T
|
||||
| {
|
||||
field?: T;
|
||||
value?: T;
|
||||
id?: T;
|
||||
};
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
}
|
||||
/**
|
||||
* This interface was referenced by `Config`'s JSON-Schema
|
||||
* via the `definition` "payload-kv_select".
|
||||
@@ -450,6 +793,15 @@ export interface SiteSetting {
|
||||
* Fallback Open Graph image when a page has none.
|
||||
*/
|
||||
defaultShareImage?: (number | null) | Media;
|
||||
/**
|
||||
* Official profiles of this business (Google Business Profile, LinkedIn, Facebook, Wikipedia…). Tells search engines and AI which entity the site belongs to.
|
||||
*/
|
||||
sameAs?:
|
||||
| {
|
||||
url: string;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
/**
|
||||
* Square icon, PNG or SVG, min. 48×48px (Google requires this to show it in search). Rendered via buildIconsMetadata.
|
||||
*/
|
||||
@@ -539,6 +891,10 @@ export interface SiteIntegration {
|
||||
since?: string | null;
|
||||
checkedAt?: string | null;
|
||||
};
|
||||
/**
|
||||
* Key that proves this site owns its URLs to IndexNow (Bing, ChatGPT Search). Generated automatically — change only to rotate it.
|
||||
*/
|
||||
indexNowKey?: string | null;
|
||||
updatedAt?: string | null;
|
||||
createdAt?: string | null;
|
||||
}
|
||||
@@ -548,6 +904,10 @@ export interface SiteIntegration {
|
||||
*/
|
||||
export interface CookieSetting {
|
||||
id: number;
|
||||
/**
|
||||
* Raise by 1 when you add a tool or change the cookie policy — every visitor is asked for consent again.
|
||||
*/
|
||||
policyVersion: number;
|
||||
/**
|
||||
* Main consent message shown in the banner.
|
||||
*/
|
||||
@@ -581,6 +941,25 @@ export interface CookieSetting {
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
/**
|
||||
* Cookies the site uses — shown on the cookie policy page (<CookieTable>). Fill it from a scan: ipal-consent-check → cookie-scan.
|
||||
*/
|
||||
cookies?:
|
||||
| {
|
||||
name: string;
|
||||
/**
|
||||
* e.g. Google, this site
|
||||
*/
|
||||
provider?: string | null;
|
||||
category: 'necessary' | 'functional' | 'analytics' | 'marketing';
|
||||
purpose?: string | null;
|
||||
/**
|
||||
* e.g. "2 years", "session"
|
||||
*/
|
||||
duration?: string | null;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
updatedAt?: string | null;
|
||||
createdAt?: string | null;
|
||||
}
|
||||
@@ -622,6 +1001,12 @@ export interface SiteSettingsSelect<T extends boolean = true> {
|
||||
titleSeparator?: T;
|
||||
logo?: T;
|
||||
defaultShareImage?: T;
|
||||
sameAs?:
|
||||
| T
|
||||
| {
|
||||
url?: T;
|
||||
id?: T;
|
||||
};
|
||||
favicon?: T;
|
||||
defaultTheme?: T;
|
||||
allowThemeToggle?: T;
|
||||
@@ -667,6 +1052,7 @@ export interface SiteIntegrationsSelect<T extends boolean = true> {
|
||||
since?: T;
|
||||
checkedAt?: T;
|
||||
};
|
||||
indexNowKey?: T;
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
globalType?: T;
|
||||
@@ -676,6 +1062,7 @@ export interface SiteIntegrationsSelect<T extends boolean = true> {
|
||||
* via the `definition` "cookie-settings_select".
|
||||
*/
|
||||
export interface CookieSettingsSelect<T extends boolean = true> {
|
||||
policyVersion?: T;
|
||||
message?: T;
|
||||
settingsTitle?: T;
|
||||
privacyLinkLabel?: T;
|
||||
@@ -696,6 +1083,16 @@ export interface CookieSettingsSelect<T extends boolean = true> {
|
||||
description?: T;
|
||||
id?: T;
|
||||
};
|
||||
cookies?:
|
||||
| T
|
||||
| {
|
||||
name?: T;
|
||||
provider?: T;
|
||||
category?: T;
|
||||
purpose?: T;
|
||||
duration?: T;
|
||||
id?: T;
|
||||
};
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
globalType?: T;
|
||||
|
||||
@@ -63,6 +63,7 @@ export default buildConfig({
|
||||
{ code: 'en', label: 'English' },
|
||||
],
|
||||
},
|
||||
forms: {},
|
||||
seo: { collections: ['posts', 'pages'] },
|
||||
// 2FA is enforced by default; the dev sandbox opts out so it boots without an authenticator.
|
||||
twoFactor: false,
|
||||
|
||||
@@ -38,7 +38,8 @@ weryfikacji nie ma, formularz działa; jeden klucz → wyłączony + alert na da
|
||||
## 3. Kod (skopiuj z `resources/`, dostosuj tylko klasy)
|
||||
| Plik | Do projektu | Rola |
|
||||
|---|---|---|
|
||||
| `actions.ts` | `src/app/(frontend)/[locale]/actions.ts` | jedna akcja `sendForm`: honeypot → IP (`clientIp`, `IPAL_IP_HEADER`) → `submitForm` → tekst z Notifications |
|
||||
| `actions.ts` | `src/app/(frontend)/[locale]/actions.ts` | `export const sendForm = createSubmitAction({ getCachedPayload, headers })` — honeypot → IP → `submitForm` → tekst z Notifications |
|
||||
| `seed-form.template.ts` | `scripts/seed-form-<nazwa>.ts` | formularz w bazie: pola, potwierdzenie, mail do firmy + do klienta, każdy język |
|
||||
| `FormBlock.tsx` | `src/blocks/FormBlock/Component.tsx` | serwer: RichText (potwierdzenie, pola „message”), bind akcji |
|
||||
| `FormRenderer.tsx` | `src/components/forms/FormRenderer.tsx` | klient: dowolny formularz z panelu przez `useForm` |
|
||||
|
||||
@@ -65,22 +66,40 @@ Zapytanie strony: `depth` ≥ 1 (relacja `form` jako obiekt). Rejestr bloków:
|
||||
`formBlock: FormBlock`. Formularz poza blokiem (stopka, modal) = ten sam
|
||||
`FormRenderer` z formularzem pobranym po ID z globalu (relacja w Footer), nigdy kopia.
|
||||
|
||||
## 5. Panel (zrób sam albo seedem, potem opisz w raporcie)
|
||||
1. **Forms → nowy formularz**: pola z briefu, `name` po angielsku, małe litery
|
||||
## 5. Formularz w bazie — ZAWSZE seedem (`resources/seed-form.template.ts`)
|
||||
Każdy formularz z briefu powstaje skryptem, nie ręcznie: wtedy jest powtarzalny (dev → produkcja),
|
||||
ma wszystkie języki i **oba maile**, o których łatwo zapomnieć:
|
||||
- **powiadomienie do firmy**: `emailTo` = adres z panelu (global firmy), `replyTo: {{email}}`, treść `{{*:table}}`;
|
||||
- **potwierdzenie do klienta**: `emailTo: {{email}}`, `replyTo` = adres firmy, temat i treść per język.
|
||||
|
||||
```bash
|
||||
cp .agents/skills/ipal-form/resources/seed-form.template.ts scripts/seed-form-contact.ts
|
||||
# uzupełnij FORM z briefu (pola, etykiety, komunikaty, tematy maili — każdy język), NOTIFY = global/pole z adresem firmy
|
||||
pnpm payload run scripts/seed-form-contact.ts
|
||||
```
|
||||
Bez adresu powiadomień skrypt **zatrzymuje się** — zapytaj klienta, na jaką skrzynkę mają przychodzić
|
||||
zgłoszenia (pytanie z listy w ipal-site), wpisz go w panelu i uruchom ponownie. Nie wpisuj adresu w kod.
|
||||
Skrypt commitujesz — na produkcji uruchamiasz go po migracji. Zmiana formularza: popraw FORM,
|
||||
`SEED_UPDATE=1 pnpm payload run …` (nadpisuje zmiany redaktora — tylko przed oddaniem).
|
||||
|
||||
Szczegóły, które seed już spełnia, a które sprawdzasz po każdej ręcznej zmianie w panelu:
|
||||
1. **Forms → formularz**: pola z briefu, `name` po angielsku, małe litery
|
||||
(`name`, `email`, `phone`, `message`, `consent`); etykiety per język.
|
||||
2. **Zgoda RODO**: checkbox `consent`, etykieta z linkiem do polityki, **nie**
|
||||
zaznaczony domyślnie (plugin i tak wymusza server-side → `reason: 'consent'`).
|
||||
3. **Confirmation**: komunikat (per język) albo redirect na stronę „Dziękujemy”
|
||||
(wtedy ta strona `noindex`).
|
||||
4. **Emails**: powiadomienie do firmy (`emailTo` z globalu firmy/panelu, `replyTo: {{email}}`,
|
||||
treść `{{*:table}}`) + opcjonalne potwierdzenie do wysyłającego (`emailTo: {{email}}`).
|
||||
treść `{{*:table}}`) **i** potwierdzenie do wysyłającego (`emailTo: {{email}}`) — oba obowiązkowe.
|
||||
Pole e-mail musi mieć `name: 'email'` (plugin przyjmuje w nim dokładnie jeden adres).
|
||||
5. **Analytics (GTM / dataLayer)**: Event name `generate_lead` / `form_submit`, parametry `form_name`.
|
||||
6. **Site Integrations**: transport maila (SMTP/Graph) + **Send test**; klucze Turnstile.
|
||||
7. **Notifications → form.\***: teksty w każdym języku.
|
||||
|
||||
## 6. Sprawdź sam, zanim powiesz „gotowe”
|
||||
- [ ] wysyłka z pustymi wymaganymi polami → błędy przy polach, bez requestu;
|
||||
- [ ] poprawna wysyłka → potwierdzenie, rekord w **Form Submissions**, mail doszedł
|
||||
- [ ] poprawna wysyłka → potwierdzenie, rekord w **Form Submissions**, mail do firmy doszedł
|
||||
**i** potwierdzenie doszło na adres wpisany w formularzu
|
||||
(Send test w panelu działa = transport OK; brak maila mimo to → zakładka Emails formularza);
|
||||
- [ ] niezaznaczona zgoda → komunikat z Notifications (nie angielski fallback);
|
||||
- [ ] 6 szybkich wysyłek → `rate_limited`;
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* Seed of ONE form in the database — fields, confirmation, and the two e-mails
|
||||
* every site needs: a notification to the company and a confirmation to the
|
||||
* person who sent it. Copy to scripts/seed-form-<name>.ts, fill FORM from the
|
||||
* brief (every language), run:
|
||||
*
|
||||
* pnpm payload run scripts/seed-form-contact.ts # creates the form if missing
|
||||
* SEED_UPDATE=1 pnpm payload run scripts/seed-form-contact.ts # also overwrites an existing one
|
||||
*
|
||||
* Nothing about the company lives in this file. The notification address comes
|
||||
* from the panel — NOTIFY.global / NOTIFY.field below (the project's company
|
||||
* global) — or SEED_NOTIFY_EMAIL for a first run. Without an address the script
|
||||
* stops: a form whose submissions reach nobody is a bug, not a default.
|
||||
*
|
||||
* Safe to send to {{email}}: submitForm accepts exactly one address in an
|
||||
* `email` field (no extra recipients, no header injection).
|
||||
*/
|
||||
import config from '@payload-config'
|
||||
import { getPayload } from 'payload'
|
||||
|
||||
// ─── fill from the brief ────────────────────────────────────────────────────
|
||||
const FORM = {
|
||||
/** Unique, not shown to visitors — the seed finds the form by it. */
|
||||
title: 'Contact form',
|
||||
fields: [
|
||||
{ blockType: 'text', name: 'name', required: true, width: 50, label: { pl: 'Imię i nazwisko', en: 'Full name' } },
|
||||
{ blockType: 'email', name: 'email', required: true, width: 50, label: { pl: 'E-mail', en: 'E-mail' } },
|
||||
{ blockType: 'text', name: 'phone', required: false, width: 50, label: { pl: 'Telefon', en: 'Phone' } },
|
||||
{ blockType: 'textarea', name: 'message', required: true, width: 100, label: { pl: 'Wiadomość', en: 'Message' } },
|
||||
// GDPR consent — name MUST stay `consent`; never pre-ticked (the plugin enforces it server-side).
|
||||
{
|
||||
blockType: 'checkbox',
|
||||
name: 'consent',
|
||||
required: true,
|
||||
width: 100,
|
||||
label: {
|
||||
pl: 'Zgadzam się na przetwarzanie moich danych w celu odpowiedzi na wiadomość.',
|
||||
en: 'I agree to the processing of my data to answer this message.',
|
||||
},
|
||||
},
|
||||
],
|
||||
submitButtonLabel: { pl: 'Wyślij', en: 'Send' },
|
||||
confirmation: {
|
||||
pl: 'Dziękujemy! Odpowiemy najszybciej, jak to możliwe.',
|
||||
en: 'Thank you! We will get back to you as soon as possible.',
|
||||
},
|
||||
/** E-mail to the company. {{*:table}} = every field as a table. */
|
||||
notification: {
|
||||
subject: { pl: 'Nowa wiadomość ze strony od {{name}}', en: 'New website message from {{name}}' },
|
||||
message: { pl: 'Nowe zgłoszenie z formularza:\n\n{{*:table}}', en: 'New form submission:\n\n{{*:table}}' },
|
||||
},
|
||||
/** E-mail to the sender. */
|
||||
confirmationEmail: {
|
||||
subject: { pl: 'Otrzymaliśmy Twoją wiadomość', en: 'We received your message' },
|
||||
message: {
|
||||
pl: 'Dzień dobry {{name}},\n\ndziękujemy za wiadomość — odpowiemy wkrótce.\n\nTwoje zgłoszenie:\n{{*:table}}',
|
||||
en: 'Hello {{name}},\n\nthank you for your message — we will reply shortly.\n\nYour submission:\n{{*:table}}',
|
||||
},
|
||||
},
|
||||
} as const
|
||||
|
||||
/** Where the company's address lives in the panel (project global + field). */
|
||||
const NOTIFY = { global: 'company', field: 'email' }
|
||||
// ────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
type Localized = Readonly<Record<string, string>>
|
||||
|
||||
/** Plain text (with blank-line paragraphs) → Lexical rich text, as form-builder messages expect. */
|
||||
function richText(text: string) {
|
||||
return {
|
||||
root: {
|
||||
children: text.split(/\n{2,}/).map((para) => ({
|
||||
children: para.split('\n').flatMap((line, i) => [
|
||||
...(i ? [{ type: 'linebreak', version: 1 }] : []),
|
||||
{ detail: 0, format: 0, mode: 'normal', style: '', text: line, type: 'text', version: 1 },
|
||||
]),
|
||||
direction: 'ltr',
|
||||
format: '',
|
||||
indent: 0,
|
||||
type: 'paragraph',
|
||||
version: 1,
|
||||
})),
|
||||
direction: 'ltr',
|
||||
format: '',
|
||||
indent: 0,
|
||||
type: 'root',
|
||||
version: 1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const payload = await getPayload({ config })
|
||||
const locales = (payload.config.localization ? payload.config.localization.localeCodes : ['pl']) as string[]
|
||||
const defaultLocale = (payload.config.localization ? payload.config.localization.defaultLocale : locales[0]) as string
|
||||
const pick = (value: Localized, locale: string) => value[locale] ?? value[defaultLocale] ?? Object.values(value)[0]
|
||||
|
||||
// Notification address — from the panel, never from this file.
|
||||
let notifyTo = process.env.SEED_NOTIFY_EMAIL?.trim() ?? ''
|
||||
if (!notifyTo) {
|
||||
try {
|
||||
const g = (await payload.findGlobal({ slug: NOTIFY.global as never, depth: 0 })) as Record<string, unknown>
|
||||
notifyTo = typeof g[NOTIFY.field] === 'string' ? (g[NOTIFY.field] as string).trim() : ''
|
||||
} catch {
|
||||
// no such global — handled below
|
||||
}
|
||||
}
|
||||
if (!/^[^\s@,;]+@[^\s@,;]+\.[^\s@,;]+$/.test(notifyTo)) {
|
||||
console.error(
|
||||
`[seed-form] No notification address. Fill ${NOTIFY.global} → ${NOTIFY.field} in the panel ` +
|
||||
'(or run with SEED_NOTIFY_EMAIL=…). Ask the client which inbox gets the submissions — do not guess.',
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
/** Form data in one locale (localized fields resolved for it). */
|
||||
function dataFor(locale: string) {
|
||||
return {
|
||||
confirmationMessage: richText(pick(FORM.confirmation, locale)),
|
||||
confirmationType: 'message',
|
||||
emails: [
|
||||
{
|
||||
emailTo: notifyTo,
|
||||
replyTo: '{{email}}',
|
||||
message: richText(pick(FORM.notification.message, locale)),
|
||||
subject: pick(FORM.notification.subject, locale),
|
||||
},
|
||||
{
|
||||
emailTo: '{{email}}',
|
||||
replyTo: notifyTo,
|
||||
message: richText(pick(FORM.confirmationEmail.message, locale)),
|
||||
subject: pick(FORM.confirmationEmail.subject, locale),
|
||||
},
|
||||
],
|
||||
fields: FORM.fields.map(({ label, ...field }) => ({ ...field, label: pick(label, locale) })),
|
||||
submitButtonLabel: pick(FORM.submitButtonLabel, locale),
|
||||
title: FORM.title,
|
||||
}
|
||||
}
|
||||
|
||||
const existing = await payload.find({ collection: 'forms' as never, limit: 1, where: { title: { equals: FORM.title } } })
|
||||
let id = existing.docs[0]?.id as number | string | undefined
|
||||
if (id && process.env.SEED_UPDATE !== '1') {
|
||||
console.log(`[seed-form] "${FORM.title}" exists (id ${id}) — unchanged. SEED_UPDATE=1 overwrites it.`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
const created = await payload.create({ collection: 'forms' as never, data: dataFor(defaultLocale) as never, locale: defaultLocale as never })
|
||||
id = created.id
|
||||
} else {
|
||||
await payload.update({ collection: 'forms' as never, data: dataFor(defaultLocale) as never, id, locale: defaultLocale as never })
|
||||
}
|
||||
|
||||
// Other languages: same rows (ids kept), localized texts per locale.
|
||||
for (const locale of locales.filter((l) => l !== defaultLocale)) {
|
||||
const doc = (await payload.findByID({ collection: 'forms' as never, depth: 0, id, locale: locale as never })) as {
|
||||
emails?: { id?: string }[]
|
||||
fields?: { id?: string }[]
|
||||
}
|
||||
const d = dataFor(locale)
|
||||
await payload.update({
|
||||
collection: 'forms' as never,
|
||||
data: {
|
||||
...d,
|
||||
emails: d.emails.map((e, i) => ({ ...e, id: doc.emails?.[i]?.id })),
|
||||
fields: d.fields.map((f, i) => ({ ...f, id: doc.fields?.[i]?.id })),
|
||||
} as never,
|
||||
id,
|
||||
locale: locale as never,
|
||||
})
|
||||
}
|
||||
|
||||
console.log(`[seed-form] "${FORM.title}" ready (id ${id}) in ${locales.join(', ')} — notifications to ${notifyTo}, confirmation to the sender.`)
|
||||
console.log('Next: place the form in a Form block on the contact page, then Site Integrations → Send test.')
|
||||
process.exit(0)
|
||||
@@ -25,7 +25,7 @@ między fazami. Przed fazą przejdź tabelę „Przewidujesz” z AGENT.md §0a.
|
||||
1. Języki strony? (pl + en — jak w briefie)
|
||||
2. Domena produkcyjna? (placeholder w .env, canonical ustawię po wdrożeniu)
|
||||
3. Dane firmy: NIP, adres, telefon? ([DO UZUPEŁNIENIA] w panelu)
|
||||
4. Na jaki adres wysyłać zgłoszenia z formularza? ([DO UZUPEŁNIENIA] w Forms → Emails)
|
||||
4. Na jaki adres wysyłać zgłoszenia z formularza? (bez tego seed formularza się nie uruchomi — to jedyne pytanie, bez którego nie oddam formularzy)
|
||||
5. Analityka: ID GA4/GTM/pikseli? (wyłączona do czasu wpisania ID w panelu)
|
||||
6. Dane R2: bucket, endpoint, klucze, domena mediów? (R2 jest wpięty zawsze; do czasu kluczy media lokalnie w dev)
|
||||
7. Klucze Turnstile? (testowe w dev; produkcyjne wpiszesz w Site Integrations)
|
||||
@@ -57,7 +57,8 @@ Każdy blok: schemat ze słownika pól, kompozycja prymitywów, zero tekstu w JS
|
||||
(`ipal-audit --quick` po każdym bloku — błędy naprawiasz od razu).
|
||||
|
||||
## Faza 5 — Formularze → **ipal-form**
|
||||
Formularze tworzysz w panelu (albo seedem) — kod piszesz raz. **Nigdy** własny
|
||||
Każdy formularz = seed z `ipal-form/resources/seed-form.template.ts` (pola, potwierdzenie, mail do
|
||||
firmy **i** potwierdzenie do klienta, każdy język) — kod renderera i akcji piszesz raz. **Nigdy** własny
|
||||
formularz z polami w JSX, trasa `api/contact`, `nodemailer`, reCAPTCHA (AGENT.md §0b).
|
||||
|
||||
## Faza 6 — Treść w panelu, każdy język
|
||||
|
||||
Reference in New Issue
Block a user