diff --git a/app/profile/page.js b/app/profile/page.js
index 992e139..883fd1c 100644
--- a/app/profile/page.js
+++ b/app/profile/page.js
@@ -1,9 +1,9 @@
-'use client';
+"use client";
-import { useState, useEffect } from 'react';
-import { motion } from 'framer-motion';
-import { useRouter } from 'next/navigation';
-import Link from 'next/link';
+import { useState, useEffect } from "react";
+import { motion } from "framer-motion";
+import { useRouter } from "next/navigation";
+import Link from "next/link";
import {
User,
Mail,
@@ -17,11 +17,11 @@ import {
Calendar,
MapPin,
Loader2,
- Pencil
-} from 'lucide-react';
-import toast, { Toaster } from 'react-hot-toast';
-import AuthService from '../services/AuthService';
-import { getCustomerByUserId, getOwnerByUserId } from '../utils/api';
+ Pencil,
+} from "lucide-react";
+import toast, { Toaster } from "react-hot-toast";
+import AuthService from "../services/AuthService";
+import { getCustomerByUserId, getOwnerByUserId } from "../utils/api";
export default function ProfilePage() {
const router = useRouter();
@@ -29,52 +29,65 @@ export default function ProfilePage() {
const [isLoading, setIsLoading] = useState(true);
const [editingBio, setEditingBio] = useState(false);
- const [bioDraft, setBioDraft] = useState('');
+ const [bioDraft, setBioDraft] = useState("");
const [formData, setFormData] = useState({
- name: '',
- email: '',
- phone: '',
- whatsapp: '',
- bio: '',
- location: '',
- joinedDate: ''
+ name: "",
+ email: "",
+ phone: "",
+ whatsapp: "",
+ bio: "",
+ location: "",
+ joinedDate: "",
});
- const [avatarPreview, setAvatarPreview] = useState('');
+ const [avatarPreview, setAvatarPreview] = useState("");
useEffect(() => {
const authUser = AuthService.getUser();
if (authUser) {
const userData = {
id: authUser.id,
- name: authUser.name || '',
- email: authUser.email || '',
- phone: authUser.phone || '',
- role: AuthService.isOwner() ? 'owner' : 'customer',
+ name: authUser.name || "",
+ email: authUser.email || "",
+ phone: authUser.phone || "",
+ role: AuthService.isOwner() ? "owner" : "customer",
};
setUser(userData);
async function fetchProfile() {
try {
- const fetchFn = userData.role === 'owner' ? getOwnerByUserId : getCustomerByUserId;
+ const fetchFn =
+ userData.role === "owner" ? getOwnerByUserId : getCustomerByUserId;
const profile = await fetchFn(userData.id);
if (profile) {
const profileData = {
- name: profile.fullName || profile.name || `${profile.firstName || ''} ${profile.lastName || ''}`.trim() || userData.name || '',
- email: profile.email || userData.email || '',
- phone: profile.phone || profile.phoneNumber || userData.phone || '',
- whatsapp: profile.whatsAppNumber || profile.whatsapp || '',
- bio: profile.bio || '',
- location: profile.address || profile.location || '',
+ name:
+ profile.fullName ||
+ profile.name ||
+ `${profile.firstName || ""} ${profile.lastName || ""}`.trim() ||
+ userData.name ||
+ "",
+ email: profile.email || userData.email || "",
+ phone:
+ profile.phone || profile.phoneNumber || userData.phone || "",
+ whatsapp: profile.whatsAppNumber || profile.whatsapp || "",
+ bio: profile.bio || "",
+ location: profile.address || profile.location || "",
joinedDate: profile.createdAt
- ? new Date(profile.createdAt).toLocaleDateString('ar-SA', { month: 'long', year: 'numeric' })
- : new Date().toLocaleDateString('ar-SA', { month: 'long', year: 'numeric' }),
+ ? new Date(profile.createdAt).toLocaleDateString("ar-SA", {
+ month: "long",
+ year: "numeric",
+ })
+ : new Date().toLocaleDateString("ar-SA", {
+ month: "long",
+ year: "numeric",
+ }),
};
setFormData(profileData);
setBioDraft(profileData.bio);
- localStorage.setItem('userProfile', JSON.stringify(profileData));
+ localStorage.setItem("userProfile", JSON.stringify(profileData));
setIsLoading(false);
return;
}
@@ -82,59 +95,62 @@ export default function ProfilePage() {
// Ignore API errors and fall back to local data.
}
- const savedProfile = localStorage.getItem('userProfile');
+ const savedProfile = localStorage.getItem("userProfile");
let profileData;
if (savedProfile) {
profileData = JSON.parse(savedProfile);
} else {
profileData = {
- name: userData.name || '',
- email: userData.email || '',
- phone: '',
- whatsapp: '',
- bio: '',
- location: '',
- joinedDate: new Date().toLocaleDateString('ar-SA', { month: 'long', year: 'numeric' })
+ name: userData.name || "",
+ email: userData.email || "",
+ phone: "",
+ whatsapp: "",
+ bio: "",
+ location: "",
+ joinedDate: new Date().toLocaleDateString("ar-SA", {
+ month: "long",
+ year: "numeric",
+ }),
};
}
setFormData(profileData);
- setBioDraft(profileData.bio || '');
+ setBioDraft(profileData.bio || "");
setIsLoading(false);
}
- const savedAvatar = localStorage.getItem('userAvatar');
+ const savedAvatar = localStorage.getItem("userAvatar");
if (savedAvatar) {
setAvatarPreview(savedAvatar);
}
fetchProfile();
} else {
- router.push('/login');
+ router.push("/login");
}
}, [router]);
const startBioEditing = () => {
- setBioDraft(formData.bio || '');
+ setBioDraft(formData.bio || "");
setEditingBio(true);
};
const cancelBioEditing = () => {
- setBioDraft(formData.bio || '');
+ setBioDraft(formData.bio || "");
setEditingBio(false);
};
const saveBio = () => {
const updatedData = { ...formData, bio: bioDraft };
setFormData(updatedData);
- localStorage.setItem('userProfile', JSON.stringify(updatedData));
+ localStorage.setItem("userProfile", JSON.stringify(updatedData));
setEditingBio(false);
- toast.success('تم تحديث نبذة عني بنجاح');
+ toast.success("تم تحديث نبذة عني بنجاح");
};
const fadeInUp = {
initial: { opacity: 0, y: 20 },
animate: { opacity: 1, y: 0 },
- transition: { duration: 0.5 }
+ transition: { duration: 0.5 },
};
if (isLoading) {
@@ -177,12 +193,12 @@ export default function ProfilePage() {
- نحن هنا لمساعدتك. تواصل معنا عبر النموذج أدناه أو من خلال معلومات الاتصال المباشرة + نحن هنا لمساعدتك. تواصل معنا عبر النموذج أدناه أو من خلال معلومات + الاتصال المباشرة
@@ -63,7 +76,9 @@ export default function SupportPage() { className="md:col-span-2" >