"use client"; import { useEffect, useState } from "react"; import { useForm, useFieldArray } from "react-hook-form"; import { Loader2, MapPin, Plus, Save, Trash2, Upload, User as UserIcon, Briefcase, GraduationCap } from "lucide-react"; import Image from "next/image"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, CardFooter } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { Separator } from "@/components/ui/separator"; import { Navbar } from "@/components/navbar"; import { Footer } from "@/components/footer"; import { useToast } from "@/hooks/use-toast"; // We'll update api.ts to include usersApi.updateMe later // Mocking for now or assuming it exists import { storageApi, usersApi } from "@/lib/api"; type Experience = { company: string; position: string; description: string; startDate: string; endDate: string; }; type Education = { institution: string; degree: string; field: string; startDate: string; endDate: string; }; type ProfileFormValues = { fullName: string; email: string; phone: string; whatsapp: string; bio: string; skills: string; // Comma separated for input experience: Experience[]; education: Education[]; }; export default function ProfilePage() { const { toast } = useToast(); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [user, setUser] = useState(null); const [profilePic, setProfilePic] = useState(null); const { register, control, handleSubmit, reset, setValue, watch } = useForm({ defaultValues: { experience: [], education: [] } }); const { fields: expFields, append: appendExp, remove: removeExp } = useFieldArray({ control, name: "experience" }); const { fields: eduFields, append: appendEdu, remove: removeEdu } = useFieldArray({ control, name: "education" }); useEffect(() => { fetchProfile(); }, []); const fetchProfile = async () => { try { setLoading(true); // Assuming getMe exists, if not we create it // const userData = await usersApi.getMe(); // For now, let's assume valid response structure based on our backend implementation // But api.ts might not have getMe yet. // To be safe, we might implement getMe in api.ts first? // Or we check what is available. // Current 'authApi.me' might be available? // Let's assume we can fetch user. // Fallback mock for development if backend not ready // const userData = mockUser; const userData = await usersApi.getMe(); // We will ensure this exists in api.ts setUser(userData); setProfilePic(userData.profilePictureUrl || null); reset({ fullName: userData.name, email: userData.email, // phone: userData.phone, // Phone might not be in Core User yet? We didn't add it to Entity. bio: userData.bio || "", skills: userData.skills?.join(", ") || "", experience: userData.experience || [], education: userData.education || [] }); } catch (error) { console.error(error); toast({ title: "Erro ao carregar perfil", description: "Não foi possível carregar seus dados.", variant: "destructive" }); } finally { setLoading(false); } }; const handleAvatarUpload = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; try { toast({ title: "Enviando foto..." }); toast({ title: "Enviando foto..." }); // 1. Upload via Proxy (avoids CORS) const { publicUrl } = await storageApi.uploadFile(file, "avatars"); // 2. Update state setProfilePic(publicUrl); toast({ title: "Foto enviada!", description: "Não esqueça de salvar o perfil." }); } catch (err) { console.error(err); toast({ title: "Erro no upload", variant: "destructive" }); } }; const onSubmit = async (data: ProfileFormValues) => { try { setSaving(true); const skillsArray = data.skills.split(",").map(s => s.trim()).filter(Boolean); await usersApi.updateMe({ fullName: data.fullName, bio: data.bio, profilePictureUrl: profilePic || undefined, skills: skillsArray, experience: data.experience, education: data.education }); toast({ title: "Perfil atualizado com sucesso!" }); } catch (error) { console.error(error); toast({ title: "Erro ao atualizar", variant: "destructive" }); } finally { setSaving(false); } }; if (loading) { return
; } return (

Meu Perfil

Gerencie suas informações profissionais e pessoais.

{/* Basic Info & Photo */} Informações Básicas Sua identidade na plataforma.