/** * @file components/settings/SettingsView.tsx * @description Settings view component for updating user profile attributes like online status and avatar color. */ "use client"; import { UserAvatar } from "@/components/ui/UserAvatar"; import { UserStatus } from "@/db/schema"; import { MEMBER_STATUS_COLOR_CLASSES, MEMBER_COLOR_OPTIONS, } from "@/lib/constants/member.styles"; import { UserRound, Palette } from "lucide-react"; import { useUser } from "@/lib/context/UserContext"; /** Renders the user settings view allowing profile, online status, and color customizations. */ export function SettingsView() { const { currentUser, updateCurrentUser } = useUser(); const statuses: { label: string; value: UserStatus }[] = [ { label: "Online", value: "ONLINE" }, { label: "Offline", value: "OFFLINE" }, { label: "AFK", value: "AFK" }, { label: "DND", value: "DND" }, ]; /** Sends optimistic updates to context and persists profile changes to the server API. */ const updateProfile = (fields: Partial) => { updateCurrentUser(fields); fetch("/api/users/profile", { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify(fields), }).catch((err) => console.error("Failed to update profile", err)); }; if (!currentUser) return null; 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 = currentUser.status === status.value; return ( ); })}
{/* Color Palette Selection */}

Profile Color

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