"use client"; import { useEffect, useRef, useState } from "react"; import { Camera, Loader2, Save } from "lucide-react"; import { Input } from "@multica/ui/components/ui/input"; import { Label } from "@multica/ui/components/ui/label"; import { Button } from "@multica/ui/components/ui/button"; import { Card, CardContent } from "@multica/ui/components/ui/card"; import { toast } from "sonner"; import { useAuthStore } from "@multica/core/auth"; import { api } from "@multica/core/api"; import { useFileUpload } from "@multica/core/hooks/use-file-upload"; export function AccountTab() { const user = useAuthStore((s) => s.user); const setUser = useAuthStore((s) => s.setUser); const [profileName, setProfileName] = useState(user?.name ?? ""); const [profileSaving, setProfileSaving] = useState(false); const { upload, uploading } = useFileUpload(api); const fileInputRef = useRef(null); useEffect(() => { setProfileName(user?.name ?? ""); }, [user]); const initials = (user?.name ?? "") .split(" ") .map((w) => w[0]) .join("") .toUpperCase() .slice(0, 2); const handleAvatarUpload = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; // Reset input so the same file can be re-selected e.target.value = ""; try { const result = await upload(file); if (!result) return; const updated = await api.updateMe({ avatar_url: result.link }); setUser(updated); toast.success("Avatar updated"); } catch (err) { toast.error(err instanceof Error ? err.message : "Failed to upload avatar"); } }; const handleProfileSave = async () => { setProfileSaving(true); try { const updated = await api.updateMe({ name: profileName }); setUser(updated); toast.success("Profile updated"); } catch (e) { toast.error(e instanceof Error ? e.message : "Failed to update profile"); } finally { setProfileSaving(false); } }; return (

Profile

{/* Avatar upload */}
Click to upload avatar
setProfileName(e.target.value)} className="mt-1" />
); }