'use client' import Image from 'next/image' import Link from 'next/link' import { ArrowLeft } from 'lucide-react' import { useState } from 'react' import { updateUsername, updateProfile } from '../lib/auth/actions' interface SettingsPageProps { user: { id: string name?: string | null email?: string | null image?: string | null } currentUsername: string | null currentGithubUrl: string | null currentXUrl: string | null } export function SettingsPage({ user, currentUsername, currentGithubUrl, currentXUrl, }: SettingsPageProps) { const [username, setUsername] = useState(currentUsername ?? '') const [githubUrl, setGithubUrl] = useState(currentGithubUrl ?? '') const [xUrl, setXUrl] = useState(currentXUrl ?? '') const [isSavingUsername, setIsSavingUsername] = useState(false) const [isSavingSocial, setIsSavingSocial] = useState(false) const [usernameMessage, setUsernameMessage] = useState<{ type: 'success' | 'error' text: string } | null>(null) const [socialMessage, setSocialMessage] = useState<{ type: 'success' | 'error' text: string } | null>(null) const handleSaveUsername = async (e: React.FormEvent) => { e.preventDefault() setUsernameMessage(null) setIsSavingUsername(true) const result = await updateUsername(username) if (result.success) { setUsernameMessage({ type: 'success', text: 'Username updated successfully' }) } else { setUsernameMessage({ type: 'error', text: result.error ?? 'Failed to update username' }) } setIsSavingUsername(false) } const handleSaveSocial = async (e: React.FormEvent) => { e.preventDefault() setSocialMessage(null) setIsSavingSocial(true) const result = await updateProfile({ githubUrl: githubUrl.trim() || null, xUrl: xUrl.trim() || null, }) if (result.success) { setSocialMessage({ type: 'success', text: 'Social links updated successfully' }) } else { setSocialMessage({ type: 'error', text: result.error ?? 'Failed to update social links' }) } setIsSavingSocial(false) } const usernameChanged = username.trim() !== (currentUsername ?? '') const socialChanged = (githubUrl.trim() || '') !== (currentGithubUrl ?? '') || (xUrl.trim() || '') !== (currentXUrl ?? '') return (
Back

Settings

{/* Profile Section */}

Profile

{user.image ? ( {user.name ) : (
{user.name?.[0]?.toUpperCase() || user.email?.[0]?.toUpperCase() || 'U'}
)}
{user.name &&
{user.name}
} {user.email && (
{user.email}
)}

Your public display name on the community hub.

{ setUsername(e.target.value) setUsernameMessage(null) }} placeholder="your-username" className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50" disabled={isSavingUsername} minLength={3} maxLength={30} pattern="[a-zA-Z0-9_-]+" />

3-30 characters. Letters, numbers, hyphens, and underscores only.

{usernameMessage && (
{usernameMessage.text}
)}
{/* Social Links Section */}

Social Links

{ setGithubUrl(e.target.value) setSocialMessage(null) }} placeholder="https://github.com/yourusername" className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50" disabled={isSavingSocial} />
{ setXUrl(e.target.value) setSocialMessage(null) }} placeholder="https://x.com/yourusername" className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50" disabled={isSavingSocial} />
{socialMessage && (
{socialMessage.text}
)}
) }