From 1a9c51a1fd6222730b1c5c7a4974a189e46a2f62 Mon Sep 17 00:00:00 2001 From: rasm-its Date: Mon, 12 Oct 2026 22:31:40 +0200 Subject: [PATCH] Add fix for branding --- dist/modules/branding/adminGraphics.d.ts | 21 ++++++--- dist/modules/branding/adminGraphics.js | 46 +++++++++++++------ dist/modules/branding/adminGraphics.js.map | 2 +- src/modules/branding/adminGraphics.tsx | 51 +++++++++++++++------- 4 files changed, 83 insertions(+), 37 deletions(-) diff --git a/dist/modules/branding/adminGraphics.d.ts b/dist/modules/branding/adminGraphics.d.ts index a3a5bb7..5c97924 100644 --- a/dist/modules/branding/adminGraphics.d.ts +++ b/dist/modules/branding/adminGraphics.d.ts @@ -1,3 +1,4 @@ +import type { Payload } from 'payload'; /** * White-label admin branding: the Payload admin panel's logo (login + nav) and * icon, pulled from the project's SiteSettings so each client sees THEIR brand, @@ -5,13 +6,13 @@ * automatically by `ipalKit({ whiteLabel: true })` (it injects * admin.components.graphics.Logo/Icon pointing here). * - * Server Components — they read the SiteSettings global at render. Data access - * uses the project's `@payload-config` alias (universal in Payload 3 Next apps), - * loaded via a variable specifier so the PLUGIN's own typecheck doesn't try to - * resolve it (same pattern as the optional 2FA import). Everything is wrapped in - * try/catch: on the login screen before the DB is ready, or a build with no DB, - * the component falls back to the site name text, then to null (Payload's own - * default) — never throws, never blocks the panel. + * Server Components — they read the SiteSettings global at render, using the + * `payload` instance Payload itself passes to admin server components. NO + * `import('@payload-config')`: a variable-specifier import isn't traced by the + * Next bundler ("Cannot find module '@payload-config'") — same bug class as the + * old 2FA import. Everything is wrapped in try/catch: no payload prop, DB not + * ready, etc. → site name text, then null (Payload's own default) — never + * throws, never blocks the panel. * * A0: no client brand in code. The logo/name come from the panel; if nothing is * set, nothing is forced. @@ -19,8 +20,14 @@ type BrandingProps = { /** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */ imageField?: string; + /** Injected by Payload — current admin locale (object or code). */ + locale?: { + code?: string; + } | string; /** Field holding the site name. Default 'siteName'. */ nameField?: string; + /** Injected by Payload into admin server components. */ + payload?: Payload; /** SiteSettings global slug. Default 'site-settings'. */ settingsSlug?: string; }; diff --git a/dist/modules/branding/adminGraphics.js b/dist/modules/branding/adminGraphics.js index f85ac5c..2b4149a 100644 --- a/dist/modules/branding/adminGraphics.js +++ b/dist/modules/branding/adminGraphics.js @@ -1,25 +1,45 @@ import { jsx as _jsx } from "react/jsx-runtime"; -import { getPayload } from 'payload'; -async function loadBranding(settingsSlug, nameField, imageField) { +/** A localized text field may arrive as a string or a { locale: value } map. */ function pickText(value, locale) { + if (typeof value === 'string') { + return value; + } + if (value && typeof value === 'object') { + const map = value; + const preferred = locale ? map[locale] : undefined; + if (typeof preferred === 'string') { + return preferred; + } + const first = Object.values(map).find((v)=>typeof v === 'string'); + return first ?? null; + } + return null; +} +async function loadBranding(props, settingsSlug, nameField, imageField) { + const { payload } = props; + if (!payload) { + return { + name: null, + url: null + }; + } try { - // Consumer alias — resolved in the project's build, hidden from plugin tsc. - const spec = '@payload-config'; - const mod = await import(spec); - const payload = await getPayload({ - config: mod.default - }); + const locale = typeof props.locale === 'string' ? props.locale : props.locale?.code; const settings = await payload.findGlobal({ slug: settingsSlug, - depth: 1 + depth: 1, + ...locale ? { + locale: locale + } : {} }); - const name = typeof settings[nameField] === 'string' ? settings[nameField] : null; + const name = pickText(settings[nameField], locale); const image = settings[imageField]; const url = image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null; return { name, url }; - } catch { + } catch (error) { + console.warn('[ipal] admin branding: falling back to Payload default:', error); return { name: null, url: null @@ -32,7 +52,7 @@ async function loadBranding(settingsSlug, nameField, imageField) { * falls back to `siteName` text. Sized generously for the login screen. */ export async function AdminLogo(props = {}) { const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props; - const { name, url } = await loadBranding(settingsSlug, nameField, imageField); + const { name, url } = await loadBranding(props, settingsSlug, nameField, imageField); if (url) { return /*#__PURE__*/ _jsx("img", { alt: name ?? '', @@ -59,7 +79,7 @@ async function loadBranding(settingsSlug, nameField, imageField) { } /** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */ export async function AdminIcon(props = {}) { const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props; - const { name, url } = await loadBranding(settingsSlug, nameField, imageField); + const { name, url } = await loadBranding(props, settingsSlug, nameField, imageField); if (url) { return /*#__PURE__*/ _jsx("img", { alt: name ?? '', diff --git a/dist/modules/branding/adminGraphics.js.map b/dist/modules/branding/adminGraphics.js.map index 837341e..ae32ac1 100644 --- a/dist/modules/branding/adminGraphics.js.map +++ b/dist/modules/branding/adminGraphics.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/modules/branding/adminGraphics.tsx"],"sourcesContent":["import { getPayload } from 'payload'\n\n/**\n * White-label admin branding: the Payload admin panel's logo (login + nav) and\n * icon, pulled from the project's SiteSettings so each client sees THEIR brand,\n * set by the editor in the panel — not hardcoded per project. Wired\n * automatically by `ipalKit({ whiteLabel: true })` (it injects\n * admin.components.graphics.Logo/Icon pointing here).\n *\n * Server Components — they read the SiteSettings global at render. Data access\n * uses the project's `@payload-config` alias (universal in Payload 3 Next apps),\n * loaded via a variable specifier so the PLUGIN's own typecheck doesn't try to\n * resolve it (same pattern as the optional 2FA import). Everything is wrapped in\n * try/catch: on the login screen before the DB is ready, or a build with no DB,\n * the component falls back to the site name text, then to null (Payload's own\n * default) — never throws, never blocks the panel.\n *\n * A0: no client brand in code. The logo/name come from the panel; if nothing is\n * set, nothing is forced.\n */\n\ntype BrandingProps = {\n /** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */\n imageField?: string\n /** Field holding the site name. Default 'siteName'. */\n nameField?: string\n /** SiteSettings global slug. Default 'site-settings'. */\n settingsSlug?: string\n}\n\ntype MediaLike = { url?: null | string } | null | undefined\n\nasync function loadBranding(\n settingsSlug: string,\n nameField: string,\n imageField: string,\n): Promise<{ name: null | string; url: null | string }> {\n try {\n // Consumer alias — resolved in the project's build, hidden from plugin tsc.\n const spec = '@payload-config'\n const mod = (await import(spec)) as { default: unknown }\n const payload = await getPayload({ config: mod.default as never })\n const settings = (await payload.findGlobal({\n slug: settingsSlug as never,\n depth: 1,\n })) as Record\n\n const name = typeof settings[nameField] === 'string' ? (settings[nameField]) : null\n const image = settings[imageField] as MediaLike\n const url =\n image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null\n return { name, url }\n } catch {\n return { name: null, url: null }\n }\n}\n\n/**\n * Admin panel logo — this is the LARGE logo on the login / unauthorized screens\n * (Payload uses `graphics.Icon` for the small nav glyph). SiteSettings `logo`,\n * falls back to `siteName` text. Sized generously for the login screen.\n */\nexport async function AdminLogo(props: BrandingProps = {}) {\n const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props\n const { name, url } = await loadBranding(settingsSlug, nameField, imageField)\n if (url) {\n return (\n \n )\n }\n if (name) {return
{name}
}\n return null // nothing configured → Payload's default\n}\n\n/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */\nexport async function AdminIcon(props: BrandingProps = {}) {\n const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props\n const { name, url } = await loadBranding(settingsSlug, nameField, imageField)\n if (url) {\n return (\n \n )\n }\n if (name) {return
{name.slice(0, 2).toUpperCase()}
}\n return null\n}\n\n/**\n * Discreet vendor credit: \"Technology supported by Intecion.com\". This is the\n * PLUGIN VENDOR's credit (Intecion ships ipal-kit, the framework), not client\n * data — a sensible default here is fine and A0-safe. The client's own brand\n * still owns the logo/name; this is a small line stating who supports the tech.\n * Text/URL overridable; turn it off with `whiteLabel: { credit: false }`.\n *\n * Wired by ipalKit into admin.components.afterNavLinks (nav) AND afterLogin\n * (login screen footer). `variant` adjusts placement:\n * - 'nav' → left-aligned line under the nav links\n * - 'login' → centered line below the login form\n */\nexport function IntecionCredit(\n props: { text?: string; url?: string; variant?: 'login' | 'nav' } = {},\n) {\n const {\n text = 'Technology supported by Intecion.com',\n url = 'https://intecion.com',\n variant = 'nav',\n } = props\n const style =\n variant === 'login'\n ? {\n color: 'inherit' as const,\n display: 'block',\n fontSize: '0.75rem',\n marginTop: '2rem',\n opacity: 0.6,\n padding: '0.5rem',\n textAlign: 'center' as const,\n textDecoration: 'none',\n }\n : {\n color: 'inherit' as const,\n display: 'block',\n fontSize: '0.75rem',\n opacity: 0.6,\n padding: '0.75rem 1rem',\n textDecoration: 'none',\n }\n return (\n \n {text}\n \n )\n}\n"],"names":["getPayload","loadBranding","settingsSlug","nameField","imageField","spec","mod","payload","config","default","settings","findGlobal","slug","depth","name","image","url","AdminLogo","props","img","alt","src","style","height","maxHeight","maxWidth","width","div","fontSize","fontWeight","AdminIcon","slice","toUpperCase","IntecionCredit","text","variant","color","display","marginTop","opacity","padding","textAlign","textDecoration","a","href","rel","target"],"mappings":";AAAA,SAASA,UAAU,QAAQ,UAAS;AAgCpC,eAAeC,aACbC,YAAoB,EACpBC,SAAiB,EACjBC,UAAkB;IAElB,IAAI;QACF,4EAA4E;QAC5E,MAAMC,OAAO;QACb,MAAMC,MAAO,MAAM,MAAM,CAACD;QAC1B,MAAME,UAAU,MAAMP,WAAW;YAAEQ,QAAQF,IAAIG,OAAO;QAAU;QAChE,MAAMC,WAAY,MAAMH,QAAQI,UAAU,CAAC;YACzCC,MAAMV;YACNW,OAAO;QACT;QAEA,MAAMC,OAAO,OAAOJ,QAAQ,CAACP,UAAU,KAAK,WAAYO,QAAQ,CAACP,UAAU,GAAI;QAC/E,MAAMY,QAAQL,QAAQ,CAACN,WAAW;QAClC,MAAMY,MACJD,SAAS,OAAOA,UAAU,YAAY,OAAOA,MAAMC,GAAG,KAAK,WAAWD,MAAMC,GAAG,GAAG;QACpF,OAAO;YAAEF;YAAME;QAAI;IACrB,EAAE,OAAM;QACN,OAAO;YAAEF,MAAM;YAAME,KAAK;QAAK;IACjC;AACF;AAEA;;;;CAIC,GACD,OAAO,eAAeC,UAAUC,QAAuB,CAAC,CAA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QACTC,SAAS;QACTC,WAAW;QACXC,gBAAgB;IAClB,IACA;QACEN,OAAO;QACPC,SAAS;QACTT,UAAU;QACVW,SAAS;QACTC,SAAS;QACTE,gBAAgB;IAClB;IACN,qBACE,KAACC;QAAEC,MAAM5B;QAAK6B,KAAI;QAAsBvB,OAAOA;QAAOwB,QAAO;kBAC1DZ;;AAGP"} \ No newline at end of file +{"version":3,"sources":["../../../src/modules/branding/adminGraphics.tsx"],"sourcesContent":["import type { Payload } from 'payload'\n\n/**\n * White-label admin branding: the Payload admin panel's logo (login + nav) and\n * icon, pulled from the project's SiteSettings so each client sees THEIR brand,\n * set by the editor in the panel — not hardcoded per project. Wired\n * automatically by `ipalKit({ whiteLabel: true })` (it injects\n * admin.components.graphics.Logo/Icon pointing here).\n *\n * Server Components — they read the SiteSettings global at render, using the\n * `payload` instance Payload itself passes to admin server components. NO\n * `import('@payload-config')`: a variable-specifier import isn't traced by the\n * Next bundler (\"Cannot find module '@payload-config'\") — same bug class as the\n * old 2FA import. Everything is wrapped in try/catch: no payload prop, DB not\n * ready, etc. → site name text, then null (Payload's own default) — never\n * throws, never blocks the panel.\n *\n * A0: no client brand in code. The logo/name come from the panel; if nothing is\n * set, nothing is forced.\n */\n\ntype BrandingProps = {\n /** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */\n imageField?: string\n /** Injected by Payload — current admin locale (object or code). */\n locale?: { code?: string } | string\n /** Field holding the site name. Default 'siteName'. */\n nameField?: string\n /** Injected by Payload into admin server components. */\n payload?: Payload\n /** SiteSettings global slug. Default 'site-settings'. */\n settingsSlug?: string\n}\n\ntype MediaLike = { url?: null | string } | null | undefined\n\n/** A localized text field may arrive as a string or a { locale: value } map. */\nfunction pickText(value: unknown, locale: string | undefined): null | string {\n if (typeof value === 'string') {return value}\n if (value && typeof value === 'object') {\n const map = value as Record\n const preferred = locale ? map[locale] : undefined\n if (typeof preferred === 'string') {return preferred}\n const first = Object.values(map).find((v): v is string => typeof v === 'string')\n return first ?? null\n }\n return null\n}\n\nasync function loadBranding(\n props: BrandingProps,\n settingsSlug: string,\n nameField: string,\n imageField: string,\n): Promise<{ name: null | string; url: null | string }> {\n const { payload } = props\n if (!payload) {return { name: null, url: null }}\n try {\n const locale = typeof props.locale === 'string' ? props.locale : props.locale?.code\n const settings = (await payload.findGlobal({\n slug: settingsSlug as never,\n depth: 1,\n ...(locale ? { locale: locale as never } : {}),\n })) as Record\n\n const name = pickText(settings[nameField], locale)\n const image = settings[imageField] as MediaLike\n const url =\n image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null\n return { name, url }\n } catch (error) {\n console.warn('[ipal] admin branding: falling back to Payload default:', error)\n return { name: null, url: null }\n }\n}\n\n/**\n * Admin panel logo — this is the LARGE logo on the login / unauthorized screens\n * (Payload uses `graphics.Icon` for the small nav glyph). SiteSettings `logo`,\n * falls back to `siteName` text. Sized generously for the login screen.\n */\nexport async function AdminLogo(props: BrandingProps = {}) {\n const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props\n const { name, url } = await loadBranding(props, settingsSlug, nameField, imageField)\n if (url) {\n return (\n \n )\n }\n if (name) {return
{name}
}\n return null // nothing configured → Payload's default\n}\n\n/** Admin panel icon (small nav glyph). SiteSettings `favicon`, falls back to initials. */\nexport async function AdminIcon(props: BrandingProps = {}) {\n const { imageField = 'favicon', nameField = 'siteName', settingsSlug = 'site-settings' } = props\n const { name, url } = await loadBranding(props, settingsSlug, nameField, imageField)\n if (url) {\n return (\n \n )\n }\n if (name) {return
{name.slice(0, 2).toUpperCase()}
}\n return null\n}\n\n/**\n * Discreet vendor credit: \"Technology supported by Intecion.com\". This is the\n * PLUGIN VENDOR's credit (Intecion ships ipal-kit, the framework), not client\n * data — a sensible default here is fine and A0-safe. The client's own brand\n * still owns the logo/name; this is a small line stating who supports the tech.\n * Text/URL overridable; turn it off with `whiteLabel: { credit: false }`.\n *\n * Wired by ipalKit into admin.components.afterNavLinks (nav) AND afterLogin\n * (login screen footer). `variant` adjusts placement:\n * - 'nav' → left-aligned line under the nav links\n * - 'login' → centered line below the login form\n */\nexport function IntecionCredit(\n props: { text?: string; url?: string; variant?: 'login' | 'nav' } = {},\n) {\n const {\n text = 'Technology supported by Intecion.com',\n url = 'https://intecion.com',\n variant = 'nav',\n } = props\n const style =\n variant === 'login'\n ? {\n color: 'inherit' as const,\n display: 'block',\n fontSize: '0.75rem',\n marginTop: '2rem',\n opacity: 0.6,\n padding: '0.5rem',\n textAlign: 'center' as const,\n textDecoration: 'none',\n }\n : {\n color: 'inherit' as const,\n display: 'block',\n fontSize: '0.75rem',\n opacity: 0.6,\n padding: '0.75rem 1rem',\n textDecoration: 'none',\n }\n return (\n \n {text}\n \n )\n}\n"],"names":["pickText","value","locale","map","preferred","undefined","first","Object","values","find","v","loadBranding","props","settingsSlug","nameField","imageField","payload","name","url","code","settings","findGlobal","slug","depth","image","error","console","warn","AdminLogo","img","alt","src","style","height","maxHeight","maxWidth","width","div","fontSize","fontWeight","AdminIcon","slice","toUpperCase","IntecionCredit","text","variant","color","display","marginTop","opacity","padding","textAlign","textDecoration","a","href","rel","target"],"mappings":";AAoCA,8EAA8E,GAC9E,SAASA,SAASC,KAAc,EAAEC,MAA0B;IAC1D,IAAI,OAAOD,UAAU,UAAU;QAAC,OAAOA;IAAK;IAC5C,IAAIA,SAAS,OAAOA,UAAU,UAAU;QACtC,MAAME,MAAMF;QACZ,MAAMG,YAAYF,SAASC,GAAG,CAACD,OAAO,GAAGG;QACzC,IAAI,OAAOD,cAAc,UAAU;YAAC,OAAOA;QAAS;QACpD,MAAME,QAAQC,OAAOC,MAAM,CAACL,KAAKM,IAAI,CAAC,CAACC,IAAmB,OAAOA,MAAM;QACvE,OAAOJ,SAAS;IAClB;IACA,OAAO;AACT;AAEA,eAAeK,aACbC,KAAoB,EACpBC,YAAoB,EACpBC,SAAiB,EACjBC,UAAkB;IAElB,MAAM,EAAEC,OAAO,EAAE,GAAGJ;IACpB,IAAI,CAACI,SAAS;QAAC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,EAAEG,aAAa,SAAS,EAAED,YAAY,UAAU,EAAED,eAAe,eAAe,EAAE,GAAGD;IAC3F,MAAM,EAAEK,IAAI,EAAEC,GAAG,EAAE,GAAG,MAAMP,aAAaC,OAAOC,cAAcC,WAAWC;IACzE,IAAIG,KAAK;QACP,qBACE,KAACW;YACCC,KAAKb,QAAQ;YACbc,KAAKb;YACLc,OAAO;gBAAEC,QAAQ;gBAAQC,WAAW;gBAAIC,UAAU;gBAAIC,OAAO;YAAO;;IAG1E;IACA,IAAInB,MAAM;QAAC,qBAAO,KAACoB;YAAIL,OAAO;gBAAEO,YAAY;YAAI;sBAAItB,KAAKwB,KAAK,CAAC,GAAG,GAAGC,WAAW;;IAAS;IACzF,OAAO;AACT;AAEA;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,eACd/B,QAAoE,CAAC,CAAC;IAEtE,MAAM,EACJgC,OAAO,sCAAsC,EAC7C1B,MAAM,sBAAsB,EAC5B2B,UAAU,KAAK,EAChB,GAAGjC;IACJ,MAAMoB,QACJa,YAAY,UACR;QACEC,OAAO;QACPC,SAAS;QACTT,UAAU;QACVU,WAAW;QACXC,SAAS;QACTC,SAAS;QACTC,WAAW;QACXC,gBAAgB;IAClB,IACA;QACEN,OAAO;QACPC,SAAS;QACTT,UAAU;QACVW,SAAS;QACTC,SAAS;QACTE,gBAAgB;IAClB;IACN,qBACE,KAACC;QAAEC,MAAMpC;QAAKqC,KAAI;QAAsBvB,OAAOA;QAAOwB,QAAO;kBAC1DZ;;AAGP"} \ No newline at end of file diff --git a/src/modules/branding/adminGraphics.tsx b/src/modules/branding/adminGraphics.tsx index 1039f0d..b0f9d05 100644 --- a/src/modules/branding/adminGraphics.tsx +++ b/src/modules/branding/adminGraphics.tsx @@ -1,4 +1,4 @@ -import { getPayload } from 'payload' +import type { Payload } from 'payload' /** * White-label admin branding: the Payload admin panel's logo (login + nav) and @@ -7,13 +7,13 @@ import { getPayload } from 'payload' * automatically by `ipalKit({ whiteLabel: true })` (it injects * admin.components.graphics.Logo/Icon pointing here). * - * Server Components — they read the SiteSettings global at render. Data access - * uses the project's `@payload-config` alias (universal in Payload 3 Next apps), - * loaded via a variable specifier so the PLUGIN's own typecheck doesn't try to - * resolve it (same pattern as the optional 2FA import). Everything is wrapped in - * try/catch: on the login screen before the DB is ready, or a build with no DB, - * the component falls back to the site name text, then to null (Payload's own - * default) — never throws, never blocks the panel. + * Server Components — they read the SiteSettings global at render, using the + * `payload` instance Payload itself passes to admin server components. NO + * `import('@payload-config')`: a variable-specifier import isn't traced by the + * Next bundler ("Cannot find module '@payload-config'") — same bug class as the + * old 2FA import. Everything is wrapped in try/catch: no payload prop, DB not + * ready, etc. → site name text, then null (Payload's own default) — never + * throws, never blocks the panel. * * A0: no client brand in code. The logo/name come from the panel; if nothing is * set, nothing is forced. @@ -22,35 +22,54 @@ import { getPayload } from 'payload' type BrandingProps = { /** Upload field to render as the image. Default 'logo' (Logo) / 'favicon' (Icon). */ imageField?: string + /** Injected by Payload — current admin locale (object or code). */ + locale?: { code?: string } | string /** Field holding the site name. Default 'siteName'. */ nameField?: string + /** Injected by Payload into admin server components. */ + payload?: Payload /** SiteSettings global slug. Default 'site-settings'. */ settingsSlug?: string } type MediaLike = { url?: null | string } | null | undefined +/** A localized text field may arrive as a string or a { locale: value } map. */ +function pickText(value: unknown, locale: string | undefined): null | string { + if (typeof value === 'string') {return value} + if (value && typeof value === 'object') { + const map = value as Record + const preferred = locale ? map[locale] : undefined + if (typeof preferred === 'string') {return preferred} + const first = Object.values(map).find((v): v is string => typeof v === 'string') + return first ?? null + } + return null +} + async function loadBranding( + props: BrandingProps, settingsSlug: string, nameField: string, imageField: string, ): Promise<{ name: null | string; url: null | string }> { + const { payload } = props + if (!payload) {return { name: null, url: null }} try { - // Consumer alias — resolved in the project's build, hidden from plugin tsc. - const spec = '@payload-config' - const mod = (await import(spec)) as { default: unknown } - const payload = await getPayload({ config: mod.default as never }) + const locale = typeof props.locale === 'string' ? props.locale : props.locale?.code const settings = (await payload.findGlobal({ slug: settingsSlug as never, depth: 1, + ...(locale ? { locale: locale as never } : {}), })) as Record - const name = typeof settings[nameField] === 'string' ? (settings[nameField]) : null + const name = pickText(settings[nameField], locale) const image = settings[imageField] as MediaLike const url = image && typeof image === 'object' && typeof image.url === 'string' ? image.url : null return { name, url } - } catch { + } catch (error) { + console.warn('[ipal] admin branding: falling back to Payload default:', error) return { name: null, url: null } } } @@ -62,7 +81,7 @@ async function loadBranding( */ export async function AdminLogo(props: BrandingProps = {}) { const { imageField = 'logo', nameField = 'siteName', settingsSlug = 'site-settings' } = props - const { name, url } = await loadBranding(settingsSlug, nameField, imageField) + const { name, url } = await loadBranding(props, settingsSlug, nameField, imageField) if (url) { return (