37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import type { TenantEvent } from '../api';
|
|
|
|
export type BrandingPalette = {
|
|
colors: string[];
|
|
font?: string;
|
|
};
|
|
|
|
export function extractBrandingPalette(settings: TenantEvent['settings'] | null | undefined): BrandingPalette {
|
|
const colors: string[] = [];
|
|
let font: string | undefined;
|
|
|
|
if (settings && typeof settings === 'object') {
|
|
const brand = (settings as Record<string, unknown>).branding;
|
|
if (brand && typeof brand === 'object') {
|
|
const colorPalette = (brand as Record<string, unknown>).colors;
|
|
if (colorPalette && typeof colorPalette === 'object') {
|
|
const paletteRecord = colorPalette as Record<string, unknown>;
|
|
for (const key of Object.keys(paletteRecord)) {
|
|
const value = paletteRecord[key];
|
|
if (typeof value === 'string' && value.trim().length) {
|
|
colors.push(value);
|
|
}
|
|
}
|
|
}
|
|
const fontValue = (brand as Record<string, unknown>).font_family;
|
|
if (typeof fontValue === 'string' && fontValue.trim()) {
|
|
font = fontValue.trim();
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
colors,
|
|
font,
|
|
};
|
|
}
|