'use client' import { useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { z } from 'zod' import { toast } from 'sonner' import { Loader2, Palette } from 'lucide-react' import { trpc } from '@/lib/trpc/client' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from '@/components/ui/form' const hexColorRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/ const formSchema = z.object({ platform_name: z.string().min(1, 'Platform name is required'), primary_color: z.string().regex(hexColorRegex, 'Invalid hex color'), secondary_color: z.string().regex(hexColorRegex, 'Invalid hex color'), accent_color: z.string().regex(hexColorRegex, 'Invalid hex color'), }) type FormValues = z.infer interface BrandingSettingsFormProps { settings: { platform_name?: string primary_color?: string secondary_color?: string accent_color?: string } } export function BrandingSettingsForm({ settings }: BrandingSettingsFormProps) { const utils = trpc.useUtils() const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { platform_name: settings.platform_name || 'Monaco Ocean Protection Challenge', primary_color: settings.primary_color || '#de0f1e', secondary_color: settings.secondary_color || '#053d57', accent_color: settings.accent_color || '#557f8c', }, }) const updateSettings = trpc.settings.updateMultiple.useMutation({ onSuccess: () => { toast.success('Branding settings saved successfully') utils.settings.getByCategory.invalidate({ category: 'BRANDING' }) }, onError: (error) => { toast.error(`Failed to save settings: ${error.message}`) }, }) const onSubmit = (data: FormValues) => { updateSettings.mutate({ settings: [ { key: 'platform_name', value: data.platform_name }, { key: 'primary_color', value: data.primary_color }, { key: 'secondary_color', value: data.secondary_color }, { key: 'accent_color', value: data.accent_color }, ], }) } const watchedColors = form.watch(['primary_color', 'secondary_color', 'accent_color']) return (
( Platform Name The display name shown across the platform )} /> {/* Color Preview */}

Color Preview

Primary
Secondary
Accent
( Primary Color
Used for CTAs, alerts, and primary actions
)} /> ( Secondary Color
Used for headers and sidebar
)} /> ( Accent Color
Used for links and secondary elements
)} /> ) }