diff --git a/components/shared/quick-create/QuickChat.tsx b/components/shared/quick-create/QuickChat.tsx index 8f36cad..c150acf 100644 --- a/components/shared/quick-create/QuickChat.tsx +++ b/components/shared/quick-create/QuickChat.tsx @@ -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 = ({ 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 = ({ bot, onReset }) => { inputRef.current?.focus({ preventScroll: true }); }; - const accentColors: Record = { - 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 (
diff --git a/lib/bot-templates.ts b/lib/bot-templates.ts index 39bc639..303d834 100644 --- a/lib/bot-templates.ts +++ b/lib/bot-templates.ts @@ -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')[]; diff --git a/lib/config/colors.ts b/lib/config/colors.ts index 137b9c0..655b138 100644 --- a/lib/config/colors.ts +++ b/lib/config/colors.ts @@ -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 = { + 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 = { +export const COLOR_CLASSES: Record = { 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 = { +export const ACCENT_BORDER_CLASSES: Record = { 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 = { } as const; /** - * Light background color classes (for cards, badges) + * Light background color classes (for restricted color set) */ -export const ACCENT_BG_CLASSES: Record = { +export const ACCENT_BG_CLASSES: Record = { blue: 'bg-blue-100', green: 'bg-green-100', indigo: 'bg-indigo-100', @@ -58,9 +138,9 @@ export const ACCENT_BG_CLASSES: Record = { } as const; /** - * Text color classes for accent colors + * Text color classes (for restricted color set) */ -export const ACCENT_TEXT_CLASSES: Record = { +export const ACCENT_TEXT_CLASSES: Record = { blue: 'text-blue-600', green: 'text-green-600', indigo: 'text-indigo-600', @@ -72,24 +152,24 @@ export const ACCENT_TEXT_CLASSES: Record = { * 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'; diff --git a/lib/supabase.ts b/lib/supabase.ts index 9225625..dab69bd 100644 --- a/lib/supabase.ts +++ b/lib/supabase.ts @@ -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: { diff --git a/lib/validations/custom-bot.ts b/lib/validations/custom-bot.ts index 7e61599..eb9f357 100644 --- a/lib/validations/custom-bot.ts +++ b/lib/validations/custom-bot.ts @@ -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 diff --git a/types/bot.ts b/types/bot.ts index 923cc85..86730d1 100644 --- a/types/bot.ts +++ b/types/bot.ts @@ -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[]; }