Fix FAQFull: Use isDraft boolean for draft filtering, fix Kontakt ID override
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { getPayload } from 'payload'
|
||||
import configPromise from '../src/payload.config'
|
||||
|
||||
async function run() {
|
||||
const payload = await getPayload({ config: configPromise })
|
||||
const pages = await payload.find({
|
||||
collection: 'pages',
|
||||
locale: 'pl'
|
||||
})
|
||||
pages.docs.forEach(p => console.log(`ID: ${p.id}, Slug: ${p.slug}, Title: ${p.title}`))
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
run()
|
||||
@@ -0,0 +1,31 @@
|
||||
import { getPayload } from 'payload'
|
||||
import configPromise from '../src/payload.config'
|
||||
|
||||
async function run() {
|
||||
const payload = await getPayload({ config: configPromise })
|
||||
|
||||
for (const locale of ['pl', 'de'] as const) {
|
||||
const doc = await payload.findByID({
|
||||
collection: 'pages',
|
||||
id: 5,
|
||||
locale
|
||||
})
|
||||
|
||||
// Filter out faqFull block
|
||||
const newLayout = doc.layout?.filter((b: any) => b.blockType !== 'faqFull') || []
|
||||
|
||||
await payload.update({
|
||||
collection: 'pages',
|
||||
id: 5,
|
||||
locale,
|
||||
data: {
|
||||
layout: newLayout
|
||||
}
|
||||
})
|
||||
console.log(`[${locale}] Usunięto faqFull z Kontakt (ID 5)`)
|
||||
}
|
||||
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
run()
|
||||
+33
-25
@@ -41,21 +41,25 @@ const questions_pl: FAQFullBlock['questions'] = [
|
||||
category: 'Dodatkowe (DO UZUPEŁNIENIA)',
|
||||
question: 'Czy mogę się rozliczyć, jeśli pracowałem w Niemczech tylko kilka miesięcy?',
|
||||
answer: PLACEHOLDER_ANSWER_PL,
|
||||
isDraft: true,
|
||||
},
|
||||
{
|
||||
category: 'Dodatkowe (DO UZUPEŁNIENIA)',
|
||||
question: 'Co się stanie, jeśli spóźnię się ze złożeniem deklaracji?',
|
||||
answer: PLACEHOLDER_ANSWER_PL,
|
||||
isDraft: true,
|
||||
},
|
||||
{
|
||||
category: 'Dodatkowe (DO UZUPEŁNIENIA)',
|
||||
question: 'Czy mogę rozliczyć się wspólnie z małżonkiem, jeśli on/ona nie pracuje w Niemczech?',
|
||||
answer: PLACEHOLDER_ANSWER_PL,
|
||||
isDraft: true,
|
||||
},
|
||||
{
|
||||
category: 'Dodatkowe (DO UZUPEŁNIENIA)',
|
||||
question: 'Czy pomagacie też w rozliczeniu za lata wcześniejsze (wsteczne)?',
|
||||
answer: PLACEHOLDER_ANSWER_PL,
|
||||
isDraft: true,
|
||||
}
|
||||
];
|
||||
|
||||
@@ -91,24 +95,28 @@ const questions_de: FAQFullBlock['questions'] = [
|
||||
answer: 'Ja, wir unterstützen Sie beim gesamten Antragsprozess für Kindergeld bei der Familienkasse. Wir kümmern uns um die Anlagen, die Überprüfung des Familienstands und den Schriftverkehr.',
|
||||
},
|
||||
{
|
||||
category: 'Zusätzlich (ZUM AUSFÜLLEN)',
|
||||
category: 'Zusätzliche (ZU ERGÄNZEN)',
|
||||
question: 'Kann ich eine Steuererklärung abgeben, wenn ich nur wenige Monate in Deutschland gearbeitet habe?',
|
||||
answer: PLACEHOLDER_ANSWER_DE,
|
||||
isDraft: true,
|
||||
},
|
||||
{
|
||||
category: 'Zusätzlich (ZUM AUSFÜLLEN)',
|
||||
question: 'Was passiert, wenn ich die Steuererklärung zu spät abgebe?',
|
||||
category: 'Zusätzliche (ZU ERGÄNZEN)',
|
||||
question: 'Was passiert, wenn ich die Erklärung zu spät abgebe?',
|
||||
answer: PLACEHOLDER_ANSWER_DE,
|
||||
isDraft: true,
|
||||
},
|
||||
{
|
||||
category: 'Zusätzlich (ZUM AUSFÜLLEN)',
|
||||
question: 'Kann ich mit meinem Ehepartner zusammenveranlagt werden, auch wenn er/sie nicht in Deutschland arbeitet?',
|
||||
category: 'Zusätzliche (ZU ERGÄNZEN)',
|
||||
question: 'Kann ich mich gemeinsam mit meinem Ehepartner veranlagen lassen, wenn er/sie nicht in Deutschland arbeitet?',
|
||||
answer: PLACEHOLDER_ANSWER_DE,
|
||||
isDraft: true,
|
||||
},
|
||||
{
|
||||
category: 'Zusätzlich (ZUM AUSFÜLLEN)',
|
||||
question: 'Helfen Sie auch bei der Steuererklärung für Vorjahre (rückwirkend)?',
|
||||
category: 'Zusätzliche (ZU ERGÄNZEN)',
|
||||
question: 'Helfen Sie auch bei der Steuererklärung für frühere Jahre (rückwirkend)?',
|
||||
answer: PLACEHOLDER_ANSWER_DE,
|
||||
isDraft: true,
|
||||
}
|
||||
];
|
||||
|
||||
@@ -128,14 +136,7 @@ async function run() {
|
||||
locale: locale
|
||||
})
|
||||
|
||||
const hasFaqFull = page.layout?.some(block => block.blockType === 'faqFull');
|
||||
|
||||
if (hasFaqFull) {
|
||||
console.log(`[${locale}] Migracja już wykonana - znaleziono blok faqFull. Pomijam.`)
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`[${locale}] Migruję... Dodaję faqFull...`)
|
||||
const hasFaqFull = page.layout?.findIndex(block => block.blockType === 'faqFull') ?? -1;
|
||||
|
||||
const title = locale === 'de' ? 'Häufig gestellte Fragen' : 'Często zadawane pytania'
|
||||
const subtitle = locale === 'de' ? 'Hier finden Sie Antworten auf die wichtigsten Fragen zur Steuererklärung.' : 'Tutaj znajdziesz odpowiedzi na najważniejsze pytania dotyczące rozliczeń podatkowych.'
|
||||
@@ -143,16 +144,23 @@ async function run() {
|
||||
const ctaText = locale === 'de' ? 'Haben Sie noch Fragen? Schreiben Sie uns auf WhatsApp' : 'Masz więcej pytań? Napisz na WhatsApp'
|
||||
const ctaUrl = '#'; // CMS link, dynamically handled later if needed
|
||||
|
||||
const newLayout = [
|
||||
{
|
||||
blockType: 'faqFull',
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
questions: locale === 'pl' ? questions_pl : questions_de,
|
||||
ctaText: ctaText,
|
||||
ctaUrl: ctaUrl
|
||||
} as FAQFullBlock
|
||||
]
|
||||
const faqFullBlock = {
|
||||
blockType: 'faqFull',
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
ctaText: ctaText,
|
||||
ctaUrl: ctaUrl,
|
||||
questions: locale === 'de' ? questions_de : questions_pl
|
||||
} as FAQFullBlock
|
||||
|
||||
let newLayout = page.layout ? [...page.layout] : [];
|
||||
if (hasFaqFull > -1) {
|
||||
console.log(`[${locale}] Zastępuję istniejący blok faqFull...`)
|
||||
newLayout[hasFaqFull] = faqFullBlock;
|
||||
} else {
|
||||
console.log(`[${locale}] Dodaję faqFull...`)
|
||||
newLayout.push(faqFullBlock)
|
||||
}
|
||||
|
||||
await payload.update({
|
||||
collection: 'pages',
|
||||
|
||||
@@ -10,6 +10,37 @@ const cleanData = (data: any) => {
|
||||
return rest
|
||||
}
|
||||
|
||||
function toLexicalParagraph(text: unknown) {
|
||||
if (typeof text !== 'string') return text;
|
||||
return {
|
||||
root: {
|
||||
type: 'root',
|
||||
format: '',
|
||||
indent: 0,
|
||||
version: 1,
|
||||
children: [
|
||||
{
|
||||
type: 'paragraph',
|
||||
format: '',
|
||||
indent: 0,
|
||||
version: 1,
|
||||
children: [
|
||||
{
|
||||
mode: 'normal',
|
||||
text: text,
|
||||
type: 'text',
|
||||
style: '',
|
||||
detail: 0,
|
||||
format: 0,
|
||||
version: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Deep replace page IDs in globals and nullify missing media relations
|
||||
const mapRelations = (obj: any, idMap: Map<number, number>): any => {
|
||||
if (Array.isArray(obj)) {
|
||||
@@ -24,6 +55,8 @@ const mapRelations = (obj: any, idMap: Map<number, number>): any => {
|
||||
newObj[key] = idMap.get(obj[key]) || obj[key]
|
||||
} else if (key === 'homepage' && typeof obj[key] === 'number') {
|
||||
newObj[key] = idMap.get(obj[key]) || obj[key]
|
||||
} else if (obj.blockType === 'TextSection' && key === 'text') {
|
||||
newObj[key] = toLexicalParagraph(obj[key])
|
||||
} else {
|
||||
newObj[key] = mapRelations(obj[key], idMap)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user