refactor: consolidate accent colors into SSOT config

- Create lib/config/colors.ts as single source of truth for all colors
- AccentColor (16 colors) for bot templates
- CustomBotAccentColor (5 colors) for custom bots (matches DB constraint)
- Remove hardcoded color maps from QuickChat.tsx
- Derive types from Zod schemas instead of separate definitions
- Add justification comment for any type in supabase mock
- Remove console.error from production code

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
g-butandClaude Opus 4.5 committed 2026-01-27 23:23:04 +01:00
1 parent 4d9a76435e
commit b15cdcd432
6 files changed
+118 -47

No files matched your search

+4 -22
View File
@@ -2,6 +2,7 @@
import { type FC, useState, useRef, useEffect, useCallback } from 'react';
import { type BotTemplate } from '@/lib/bot-templates';
import { getAccentColorBgClass } from '@/lib/config/colors';
interface CreatedBot {
template: BotTemplate;
@@ -142,8 +143,8 @@ export const QuickChat: FC<QuickChatProps> = ({ bot, onReset }) => {
};
setMessages((prev) => [...prev, assistantMessage]);
} catch (error) {
console.error('Chat error:', error);
} catch {
// Error already handled by showing user-friendly message below
const errorMessage: Message = {
id: `error-${Date.now()}`,
role: 'assistant',
@@ -161,26 +162,7 @@ export const QuickChat: FC<QuickChatProps> = ({ bot, onReset }) => {
inputRef.current?.focus({ preventScroll: true });
};
const accentColors: Record<string, string> = {
blue: 'bg-blue-500',
pink: 'bg-pink-500',
rose: 'bg-rose-500',
purple: 'bg-purple-500',
amber: 'bg-amber-500',
green: 'bg-green-500',
red: 'bg-red-500',
orange: 'bg-orange-500',
slate: 'bg-slate-500',
indigo: 'bg-indigo-500',
teal: 'bg-teal-500',
cyan: 'bg-cyan-500',
yellow: 'bg-yellow-500',
sky: 'bg-sky-500',
stone: 'bg-stone-500',
violet: 'bg-violet-500',
};
const accentColor = accentColors[bot.template.accentColor] || 'bg-purple-500';
const accentColor = getAccentColorBgClass(bot.template.accentColor);
return (
<div className="max-w-3xl mx-auto">
+3 -1
View File
@@ -4,6 +4,8 @@
* Pre-configured templates that make bot creation as easy as picking an emoji
*/
import { type AccentColor } from '@/lib/config/colors';
export type TemplateCategory = 'memorial' | 'legends' | 'gods' | 'magical' | 'helpers';
export interface BotTemplate {
@@ -23,7 +25,7 @@ export interface BotTemplate {
systemPromptTemplate: string;
starterQuestions: string[];
accentColor: string;
accentColor: AccentColor;
// What user needs to provide
requiredFields: ('name' | 'photo' | 'memories' | 'relationship')[];
+100 -20
View File
@@ -1,19 +1,100 @@
/**
* Color Configuration
* Accent Colors Configuration - SSOT
* @module lib/config/colors
*
* SSOT for color-related configurations.
* Import from here instead of hardcoding color classes.
* Single source of truth for all accent colors used throughout the app.
* All color types, schemas, and Tailwind mappings should derive from here.
*/
import { z } from 'zod';
/**
* Accent color options for bots and UI elements
* All accent colors available in the system.
* Used by bot templates and internal features.
*/
export const ACCENT_COLORS = ['blue', 'green', 'indigo', 'red', 'amber'] as const;
export const ACCENT_COLORS = [
'blue',
'green',
'indigo',
'red',
'amber',
'pink',
'rose',
'purple',
'orange',
'slate',
'yellow',
'sky',
'stone',
'violet',
'cyan',
'teal',
] as const;
/**
* Accent colors available for custom bots (user-created).
* Subset of ACCENT_COLORS - matches database CHECK constraint.
*/
export const CUSTOM_BOT_ACCENT_COLORS = [
'blue',
'green',
'indigo',
'red',
'amber',
] as const;
/**
* Type for all accent colors in the system
*/
export type AccentColor = (typeof ACCENT_COLORS)[number];
/**
* Color picker options with labels (for forms)
* Type for custom bot accent colors (restricted set)
*/
export type CustomBotAccentColor = (typeof CUSTOM_BOT_ACCENT_COLORS)[number];
/**
* Zod schema for all accent colors
*/
export const AccentColorSchema = z.enum(ACCENT_COLORS);
/**
* Zod schema for custom bot accent colors (matches DB constraint)
*/
export const CustomBotAccentColorSchema = z.enum(CUSTOM_BOT_ACCENT_COLORS);
/**
* Tailwind background color classes for each accent color (500 weight)
*/
export const ACCENT_COLOR_BG_CLASSES: Record<AccentColor, string> = {
blue: 'bg-blue-500',
green: 'bg-green-500',
indigo: 'bg-indigo-500',
red: 'bg-red-500',
amber: 'bg-amber-500',
pink: 'bg-pink-500',
rose: 'bg-rose-500',
purple: 'bg-purple-500',
orange: 'bg-orange-500',
slate: 'bg-slate-500',
yellow: 'bg-yellow-500',
sky: 'bg-sky-500',
stone: 'bg-stone-500',
violet: 'bg-violet-500',
cyan: 'bg-cyan-500',
teal: 'bg-teal-500',
};
/**
* Get the Tailwind bg class for an accent color
* Falls back to purple if color not found
*/
export function getAccentColorBgClass(color: string): string {
return ACCENT_COLOR_BG_CLASSES[color as AccentColor] || 'bg-purple-500';
}
/**
* Color picker options with labels (for forms) - uses restricted set
*/
export const ACCENT_COLOR_OPTIONS = [
{ value: 'blue', label: 'Blue', class: 'bg-blue-500' },
@@ -24,10 +105,9 @@ export const ACCENT_COLOR_OPTIONS = [
] as const;
/**
* Composite color classes for themed UI (solid backgrounds)
* Used in bot chat pages, headers, buttons
* Composite color classes for themed UI (for restricted color set)
*/
export const COLOR_CLASSES: Record<AccentColor, { bg: string; text: string; border: string }> = {
export const COLOR_CLASSES: Record<CustomBotAccentColor, { bg: string; text: string; border: string }> = {
blue: { bg: 'bg-blue-500', text: 'text-blue-600', border: 'border-blue-200' },
green: { bg: 'bg-green-500', text: 'text-green-600', border: 'border-green-200' },
indigo: { bg: 'bg-indigo-500', text: 'text-indigo-600', border: 'border-indigo-200' },
@@ -36,9 +116,9 @@ export const COLOR_CLASSES: Record<AccentColor, { bg: string; text: string; bord
};
/**
* Border color classes for accent colors (used in cards, buttons, etc.)
* Border color classes (for restricted color set)
*/
export const ACCENT_BORDER_CLASSES: Record<AccentColor, string> = {
export const ACCENT_BORDER_CLASSES: Record<CustomBotAccentColor, string> = {
blue: 'border-blue-200 hover:border-blue-300',
green: 'border-green-200 hover:border-green-300',
indigo: 'border-indigo-200 hover:border-indigo-300',
@@ -47,9 +127,9 @@ export const ACCENT_BORDER_CLASSES: Record<AccentColor, string> = {
} as const;
/**
* Light background color classes (for cards, badges)
* Light background color classes (for restricted color set)
*/
export const ACCENT_BG_CLASSES: Record<AccentColor, string> = {
export const ACCENT_BG_CLASSES: Record<CustomBotAccentColor, string> = {
blue: 'bg-blue-100',
green: 'bg-green-100',
indigo: 'bg-indigo-100',
@@ -58,9 +138,9 @@ export const ACCENT_BG_CLASSES: Record<AccentColor, string> = {
} as const;
/**
* Text color classes for accent colors
* Text color classes (for restricted color set)
*/
export const ACCENT_TEXT_CLASSES: Record<AccentColor, string> = {
export const ACCENT_TEXT_CLASSES: Record<CustomBotAccentColor, string> = {
blue: 'text-blue-600',
green: 'text-green-600',
indigo: 'text-indigo-600',
@@ -72,24 +152,24 @@ export const ACCENT_TEXT_CLASSES: Record<AccentColor, string> = {
* Get border class for an accent color with fallback
*/
export function getAccentBorderClass(color: string | null | undefined): string {
return ACCENT_BORDER_CLASSES[color as AccentColor] || ACCENT_BORDER_CLASSES.blue;
return ACCENT_BORDER_CLASSES[color as CustomBotAccentColor] || ACCENT_BORDER_CLASSES.blue;
}
/**
* Get background class for an accent color with fallback
* Get light background class for an accent color with fallback
*/
export function getAccentBgClass(color: string | null | undefined): string {
return ACCENT_BG_CLASSES[color as AccentColor] || ACCENT_BG_CLASSES.blue;
return ACCENT_BG_CLASSES[color as CustomBotAccentColor] || ACCENT_BG_CLASSES.blue;
}
/**
* Get text class for an accent color with fallback
*/
export function getAccentTextClass(color: string | null | undefined): string {
return ACCENT_TEXT_CLASSES[color as AccentColor] || ACCENT_TEXT_CLASSES.blue;
return ACCENT_TEXT_CLASSES[color as CustomBotAccentColor] || ACCENT_TEXT_CLASSES.blue;
}
/**
* Default accent color
*/
export const DEFAULT_ACCENT_COLOR: AccentColor = 'blue';
export const DEFAULT_ACCENT_COLOR: CustomBotAccentColor = 'blue';
+3
View File
@@ -149,6 +149,9 @@ export function createClientComponentClient() {
);
}
// Return mock during SSG - will be replaced on hydration
// Using 'any' here because properly typing the full Supabase client mock
// would require importing internal Supabase types that aren't exported.
// This mock is only used during build-time SSG, never at runtime.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const mockClient: any = {
auth: {
+3 -1
View File
@@ -6,11 +6,13 @@
*/
import { z } from 'zod';
import { CustomBotAccentColorSchema } from '@/lib/config/colors';
/**
* Valid accent colors for bot themes
* Re-exported from SSOT in lib/config/colors.ts
*/
export const AccentColorSchema = z.enum(['blue', 'green', 'indigo', 'red', 'amber']);
export const AccentColorSchema = CustomBotAccentColorSchema;
/**
* Bot menu item schema
+5 -3
View File
@@ -1,4 +1,5 @@
import React from 'react';
import { type CustomBotAccentColor } from '@/lib/config/colors';
export interface Feature {
title: string;
@@ -31,9 +32,10 @@ export interface BotMenuItem {
}
/**
* Accent colors available for bot pages
* Accent colors available for bot pages (restricted set of 5 colors)
* Re-exported from SSOT in lib/config/colors.ts
*/
export type BotAccentColor = 'blue' | 'green' | 'indigo' | 'red' | 'amber';
export type { CustomBotAccentColor as BotAccentColor } from '@/lib/config/colors';
/**
* Navigation configuration for bot pages
@@ -46,7 +48,7 @@ export interface BotNavConfig {
/** Short description shown in nav */
navDescription?: string;
/** Accent color theme */
accentColor: BotAccentColor;
accentColor: CustomBotAccentColor;
/** Menu items for page sections */
menuItems: BotMenuItem[];
}