diff --git a/frontend/src/app/profile/page.tsx b/frontend/src/app/profile/page.tsx index f52d8d6..6822a81 100644 --- a/frontend/src/app/profile/page.tsx +++ b/frontend/src/app/profile/page.tsx @@ -1,226 +1,18 @@ "use client" -import { useEffect, useState } from "react" +import { useEffect } from "react" import { useRouter } from "next/navigation" -import { authApi, profileApi, type ApiUser } from "@/lib/api" -import { Button } from "@/components/ui/button" -import { Input } from "@/components/ui/input" -import { Textarea } from "@/components/ui/textarea" -import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" -import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" -import { Label } from "@/components/ui/label" -import { Loader2, User, Mail, Shield, Save, Upload } from "lucide-react" -import { toast } from "sonner" -export default function ProfilePage() { +export default function ProfileRedirect() { const router = useRouter() - const [user, setUser] = useState(null) - const [isLoading, setIsLoading] = useState(true) - const [isSaving, setIsSaving] = useState(false) - - // Form State - const [formData, setFormData] = useState({ - name: "", - email: "", - phone: "", - bio: "", - }) useEffect(() => { - loadProfile() - }, []) - - const loadProfile = async () => { - try { - setIsLoading(true) - const userData = await authApi.getCurrentUser() - setUser(userData) - setFormData({ - name: userData.name || userData.fullName || "", - email: userData.email || "", - phone: userData.phone || "", - bio: userData.bio || "", - }) - } catch (error) { - console.error("Failed to load profile:", error) - toast.error("Failed to load profile") - router.push("/login") // Redirect if unauthorized - } finally { - setIsLoading(false) - } - } - - const handleInputChange = (e: React.ChangeEvent) => { - const { name, value } = e.target - setFormData(prev => ({ ...prev, [name]: value })) - } - - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault() - if (!user) return - - try { - setIsSaving(true) - // Call update API - await profileApi.update({ - name: formData.name, - // email: formData.email, // Often email update requires verification, let's allow it if API supports - phone: formData.phone, - bio: formData.bio, - }) - toast.success("Profile updated successfully") - // Reload to ensure sync - await loadProfile() - } catch (error) { - console.error("Failed to update profile:", error) - toast.error("Failed to update profile") - } finally { - setIsSaving(false) - } - } - - const handleAvatarUpload = async (e: React.ChangeEvent) => { - const file = e.target.files?.[0] - if (!file) return - - try { - setIsLoading(true) // Show global loading for avatar - toast.info("Uploading avatar...") - await profileApi.uploadAvatar(file) - toast.success("Avatar uploaded!") - await loadProfile() - } catch (error) { - console.error("Avatar upload failed:", error) - toast.error("Failed to upload avatar") - } finally { - setIsLoading(false) - } - } - - if (isLoading && !user) { - return ( -
- -
- ) - } - - if (!user) return null + router.replace("/dashboard/profile") + }, [router]) return ( -
-

My Profile

- -
- - {/* Left Column: Avatar & Basic Info */} -
- - -
- - - {user.name?.charAt(0).toUpperCase()} - -
- - -
-
- {user.name || user.fullName} - {user.email} -
- - - {user.role} - -
-
-
-
- - {/* Right Column: Edit Form */} -
- - - Personal Information - Update your personal details here. - - -
-
- -
- - -
-
- -
- -
- - -
-

To change your email, please contact support.

-
- -
- - -
- -
- -