feat(seed): add GroupRequest and BirthdayBooking forms + assign to page globals

This commit is contained in:
Vadym Samoilenko 2026-05-18 12:08:34 +01:00
parent 42cb554de4
commit 3ea4d95cc7

View file

@ -678,5 +678,243 @@ export async function POST(req: NextRequest) {
results.push('Tariffs already exist')
}
// === FORMS ===
const managerEmail = process.env['MANAGER_EMAILS']?.split(',')[0]?.trim() ?? ''
const { totalDocs: formCount } = await payload.find({
collection: 'forms',
limit: 1,
overrideAccess: true,
})
if (formCount === 0) {
const emailBlock = (subject: string) =>
managerEmail
? [
{
emailTo: managerEmail,
subject,
emailFrom: 'noreply@shumiland.com.ua',
replyTo: '{{email}}',
message: {
root: {
type: 'root',
format: '',
indent: 0,
version: 1,
direction: 'ltr',
children: [
{
type: 'paragraph',
format: '',
indent: 0,
version: 1,
direction: 'ltr',
children: [
{
type: 'text',
detail: 0,
format: 0,
mode: 'normal',
style: '',
text: `Нова заявка: ${subject}`,
version: 1,
},
],
},
],
},
},
},
]
: []
const successMessage = (text: string) => ({
root: {
type: 'root',
format: '',
indent: 0,
version: 1,
direction: 'ltr',
children: [
{
type: 'paragraph',
format: '',
indent: 0,
version: 1,
direction: 'ltr',
children: [
{ type: 'text', detail: 0, format: 0, mode: 'normal', style: '', text, version: 1 },
],
},
],
},
})
const groupForm = await payload.create({
collection: 'forms',
data: {
title: 'Заявка на групове відвідування',
submitButtonLabel: 'Надіслати заявку',
confirmationType: 'message',
confirmationMessage: successMessage(
'Заявку отримано! Менеджер зателефонує вам протягом 30 хвилин для уточнення деталей.'
),
emails: emailBlock('Групове відвідування'),
fields: [
{
blockType: 'text',
name: 'name',
label: "Ваше ім'я",
required: true,
placeholder: 'Іван Іванов',
width: 50,
},
{
blockType: 'text',
name: 'phone',
label: 'Телефон',
required: true,
placeholder: '+38 (0__) ___-__-__',
width: 50,
},
{
blockType: 'email',
name: 'email',
label: 'Email',
placeholder: 'your@email.com',
width: 50,
},
{
blockType: 'number',
name: 'groupSize',
label: 'Кількість учасників',
required: true,
placeholder: '30',
width: 50,
},
{ blockType: 'date', name: 'preferredDate', label: 'Бажана дата', width: 50 },
{
blockType: 'select',
name: 'groupType',
label: 'Тип групи',
width: 50,
options: [
{ label: 'Шкільна екскурсія', value: 'school' },
{ label: 'Дитячий садок', value: 'kindergarten' },
{ label: 'Корпоратив', value: 'corporate' },
{ label: 'Інше', value: 'other' },
],
},
{
blockType: 'textarea',
name: 'message',
label: 'Повідомлення',
placeholder: 'Додаткові побажання або запитання...',
width: 100,
},
],
} as never,
overrideAccess: true,
})
results.push('Created GroupRequest form')
const birthdayForm = await payload.create({
collection: 'forms',
data: {
title: 'Замовлення дня народження',
submitButtonLabel: 'Замовити святкування',
confirmationType: 'message',
confirmationMessage: successMessage(
"Заявку отримано! Менеджер зв'яжеться з вами протягом 30 хвилин для уточнення деталей свята."
),
emails: emailBlock('День народження'),
fields: [
{
blockType: 'text',
name: 'name',
label: "Ваше ім'я",
required: true,
placeholder: 'Іван Іванов',
width: 50,
},
{
blockType: 'text',
name: 'phone',
label: 'Телефон',
required: true,
placeholder: '+38 (0__) ___-__-__',
width: 50,
},
{
blockType: 'email',
name: 'email',
label: 'Email',
placeholder: 'your@email.com',
width: 50,
},
{
blockType: 'number',
name: 'childAge',
label: 'Вік іменинника',
placeholder: '7',
width: 50,
},
{
blockType: 'select',
name: 'packageSlug',
label: 'Пакет',
width: 50,
options: [
{ label: 'Стандарт — 4 500 ₴', value: 'standard' },
{ label: 'Преміум — 8 900 ₴', value: 'premium' },
{ label: 'VIP — 15 000 ₴', value: 'vip' },
],
},
{
blockType: 'number',
name: 'guestCount',
label: 'Кількість гостей',
placeholder: '15',
width: 50,
},
{
blockType: 'date',
name: 'preferredDate',
label: 'Бажана дата',
required: true,
width: 100,
},
{
blockType: 'textarea',
name: 'wishes',
label: 'Побажання',
placeholder: 'Тема свята, улюблені герої, особливі побажання...',
width: 100,
},
],
} as never,
overrideAccess: true,
})
results.push('Created BirthdayBooking form')
// Assign forms to page globals
await payload.updateGlobal({
slug: 'group-visits-page',
data: { form: groupForm.id } as never,
overrideAccess: true,
})
results.push('Assigned GroupRequest form to group-visits-page')
await payload.updateGlobal({
slug: 'birthday-page',
data: { form: birthdayForm.id } as never,
overrideAccess: true,
})
results.push('Assigned BirthdayBooking form to birthday-page')
} else {
results.push('Forms already exist')
}
return NextResponse.json({ ok: true, results })
}