/** * @file components/settings/SettingsView.tsx * @description Main settings container component for managing user profile and preferences. */ "use client"; import { useState } from "react"; import { UserAvatar } from "@/components/ui/UserAvatar"; import { UserStatus, User } from "@/db/schema"; import { MEMBER_STATUS_COLOR_CLASSES, MEMBER_COLOR_OPTIONS, } from "@/lib/constants/member.styles"; import { UserRound, Palette } from "lucide-react"; /** Props for the SettingsView component. */ interface SettingsViewProps { userId: string; currentUser: User; } /** Renders the user settings view for profile management, status selection, and avatar color customization. */ export function SettingsView({ userId, currentUser }: SettingsViewProps) { const [selectedStatus, setSelectedStatus] = useState( currentUser.status, ); const [selectedColor, setSelectedColor] = useState( currentUser.color || MEMBER_COLOR_OPTIONS[0], ); const statuses: { label: string; value: UserStatus }[] = [ { label: "Online", value: "ONLINE" }, { label: "Offline", value: "OFFLINE" }, { label: "AFK", value: "AFK" }, { label: "DND", value: "DND" }, ]; /** Updates local status state on user selection. */ const handleStatusChange = async (newStatus: UserStatus) => { setSelectedStatus(newStatus); try { await fetch("/api/users/profile", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ status: newStatus }), }); } catch (err) { console.error("Failed to update status", err); } }; /** Updates local avatar color state on user selection. */ const handleColorChange = async (newColor: string) => { setSelectedColor(newColor); try { await fetch("/api/users/profile", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ color: newColor }), }); } catch (err) { console.error("Failed to update color", err); } }; if (!currentUser) return null; const userWithUpdatedSettings = { ...currentUser, status: selectedStatus, color: selectedColor, }; return (
{/* Header */}

User Settings

Manage your profile, status, and account settings.

{/* Profile Overview Card */}

{currentUser.username}

{currentUser.email}

{/* Status Selection */}

Online Status

{statuses.map((status) => { const isSelected = selectedStatus === status.value; const statusBgColor = MEMBER_STATUS_COLOR_CLASSES[status.value]; return ( ); })}
{/* Color Palette Selection */}

Profile Color

{MEMBER_COLOR_OPTIONS.map((colorClass) => { const isSelected = selectedColor === colorClass; return (
); }