From 06d7d798a456940a959c0c2a60d6bd549f40a230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Miler?= Date: Fri, 28 Aug 2026 10:23:50 +0200 Subject: [PATCH] fix: missing alert translations --- src/app/(app)/shared/utils/appConfig.ts | 34 ++++++++----- .../utilities/getChangedLocalizedPaths.ts | 48 +++++++++++++++++++ 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/src/app/(app)/shared/utils/appConfig.ts b/src/app/(app)/shared/utils/appConfig.ts index 156097c2..8fce2a67 100644 --- a/src/app/(app)/shared/utils/appConfig.ts +++ b/src/app/(app)/shared/utils/appConfig.ts @@ -303,11 +303,7 @@ async function getAppConfigBase( // Fetch English resource directory for fallback if not English locale let englishResourceDirectory: ResourceDirectory | null = null; - if ( - locale !== 'en' && - (resourceDirectory.resource?.useCustomLayout || - !resourceDirectory.search.cardLayout) - ) { + if (locale !== 'en') { englishResourceDirectory = await findResourceDirectoryByHost(host, 'en'); } @@ -617,13 +613,27 @@ async function getAppConfigBase( }), ), }, - alerts: activeAlerts.map((alert) => ({ - text: alert.text, - buttonText: alert.buttonText ?? undefined, - target: alert.openInNewTab ? '_blank' : undefined, - url: alert.url ?? undefined, - variant: alert.variant ?? undefined, - })), + alerts: activeAlerts + .map((alert, index) => { + const englishAlerts = englishResourceDirectory?.common?.alert ?? []; + const fallbackAlert = + findFallbackById(alert, englishAlerts) ?? englishAlerts[index]; + const text = alert.text || fallbackAlert?.text; + + if (!text?.trim()) { + return null; + } + + return { + text, + buttonText: + (alert.buttonText || fallbackAlert?.buttonText) ?? undefined, + target: alert.openInNewTab ? ('_blank' as const) : undefined, + url: alert.url ?? undefined, + variant: alert.variant ?? undefined, + }; + }) + .filter((alert): alert is NonNullable => alert !== null), heroUrl, highlights: resourceDirectory.highlights ? { diff --git a/src/payload/utilities/getChangedLocalizedPaths.ts b/src/payload/utilities/getChangedLocalizedPaths.ts index 45755fe7..f0d7f24b 100644 --- a/src/payload/utilities/getChangedLocalizedPaths.ts +++ b/src/payload/utilities/getChangedLocalizedPaths.ts @@ -247,6 +247,54 @@ function deepLocalizedDiff( } }); + // ALERTS (from common tab) + + const beforeAlerts: NonNullable< + NonNullable['alert'] + > = get(before, 'common.alert', []); + const afterAlerts: NonNullable< + NonNullable['alert'] + > = get(after, 'common.alert', []); + + const beforeAlertsMap = new Map(beforeAlerts.map((a) => [a.id, a])); + const afterAlertsMap = new Map(afterAlerts.map((a) => [a.id, a])); + + afterAlerts.forEach((afterAlert, index) => { + const beforeAlert = beforeAlertsMap.get(afterAlert.id); + + (['text', 'buttonText'] as const).forEach((field) => { + if (!beforeAlert) { + if (afterAlert[field]) { + changes.push({ + path: `common.alert.${index}.${field}`, + before: undefined, + after: afterAlert[field], + }); + } + } else if (beforeAlert[field] !== afterAlert[field]) { + changes.push({ + path: `common.alert.${index}.${field}`, + before: beforeAlert[field], + after: afterAlert[field], + }); + } + }); + }); + + beforeAlerts.forEach((beforeAlert, index) => { + if (!afterAlertsMap.has(beforeAlert.id)) { + (['text', 'buttonText'] as const).forEach((field) => { + if (beforeAlert[field]) { + changes.push({ + path: `common.alert.${index}.${field}`, + before: beforeAlert[field], + after: undefined, + }); + } + }); + } + }); + // SEARCH FACETS const beforeFacets: NonNullable = get(