fix(lint&types): resolve all lint warnings, typecheck errors and effect state updates across frontend application and admin panel
This commit is contained in:
1 parent
920dd532e8
commit
c1b2f416ed
29 files changed
+442
-352
No files matched your search
@@ -1,11 +1,11 @@
|
||||
"use client";
|
||||
import React, { useState } from "react";
|
||||
import { motion, AnimatePresence } from "motion/react";
|
||||
import { motion } from "motion/react";
|
||||
import { User, ShoppingBag, Wallet, MapPin, LogOut, ChevronRight, Package, Calendar, UserCircle, ShoppingCart, Trash2, Edit2, Phone, Hash, CheckCircle2, ArrowUpCircle, ArrowDownCircle, Info, Clock, CheckCircle, Heart, Sparkles, MessageSquare, Send, Stethoscope, FileText } from "lucide-react";
|
||||
import { OrderRowSkeleton } from "./Skeleton";
|
||||
import { useUserStore, Address } from "../lib/store/userStore";
|
||||
import { useCartStore } from "../lib/store/cartStore";
|
||||
import { toPersian, cn } from "../lib/utils";
|
||||
import { toPersian, toEnglishDigits, cn } from "../lib/utils";
|
||||
import { toast } from "sonner";
|
||||
import OrderDetailsModal from "./OrderDetailsModal";
|
||||
import AddressModal from "./AddressModal";
|
||||
@@ -16,7 +16,7 @@ import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function UserDashboard() {
|
||||
const router = useRouter();
|
||||
const { profile, isLoggedIn, logout, addAddress, updateAddress, deleteAddress, setDefaultAddress, topUpWallet } = useUserStore();
|
||||
const { profile, isLoggedIn, logout, updateProfile, addAddress, updateAddress, deleteAddress, setDefaultAddress, topUpWallet } = useUserStore();
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!isLoggedIn && typeof window !== "undefined") {
|
||||
@@ -29,12 +29,19 @@ export default function UserDashboard() {
|
||||
const [activeTab, setActiveTab] = React.useState<"profile" | "orders" | "wallet" | "addresses" | "tickets">("profile");
|
||||
const [isLoadingOrders, setIsLoadingOrders] = useState(false);
|
||||
|
||||
|
||||
// Fetch fresh profile data (which includes orders) whenever orders tab is opened
|
||||
React.useEffect(() => {
|
||||
if (activeTab === "orders") {
|
||||
setIsLoadingOrders(true);
|
||||
useUserStore.getState().fetchProfile().finally(() => setIsLoadingOrders(false));
|
||||
let isSubscribed = true;
|
||||
Promise.resolve().then(() => {
|
||||
if (isSubscribed) setIsLoadingOrders(true);
|
||||
});
|
||||
useUserStore.getState().fetchProfile().finally(() => {
|
||||
if (isSubscribed) setIsLoadingOrders(false);
|
||||
});
|
||||
return () => {
|
||||
isSubscribed = false;
|
||||
};
|
||||
}
|
||||
}, [activeTab]);
|
||||
const [selectedOrder, setSelectedOrder] = useState<any>(null);
|
||||
@@ -51,21 +58,29 @@ export default function UserDashboard() {
|
||||
// Profile State
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const [isSavingProfile, setIsSavingProfile] = useState(false);
|
||||
const [profileForm, setProfileForm] = useState({
|
||||
const [profileForm, setProfileForm] = useState(() => ({
|
||||
firstName: profile.firstName || "",
|
||||
lastName: profile.lastName || "",
|
||||
email: profile.email || "",
|
||||
mobile: profile.mobile || ""
|
||||
});
|
||||
}));
|
||||
|
||||
// Sync profile data on change
|
||||
React.useEffect(() => {
|
||||
setProfileForm({
|
||||
firstName: profile.firstName || "",
|
||||
lastName: profile.lastName || "",
|
||||
email: profile.email || "",
|
||||
mobile: profile.mobile || ""
|
||||
let isSubscribed = true;
|
||||
Promise.resolve().then(() => {
|
||||
if (isSubscribed) {
|
||||
setProfileForm({
|
||||
firstName: profile.firstName || "",
|
||||
lastName: profile.lastName || "",
|
||||
email: profile.email || "",
|
||||
mobile: profile.mobile || ""
|
||||
});
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
isSubscribed = false;
|
||||
};
|
||||
}, [profile]);
|
||||
|
||||
if (!isLoggedIn) {
|
||||
@@ -74,17 +89,10 @@ export default function UserDashboard() {
|
||||
|
||||
const handleSaveProfile = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!isEditing) return;
|
||||
|
||||
const cleanPhone = profileForm.mobile.trim();
|
||||
if (!/^09\d{9}$/.test(cleanPhone)) {
|
||||
toast.error("شماره موبایل وارد شده معتبر نیست (باید ۱۱ رقم باشد و با ۰۹ شروع شود)");
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSavingProfile(true);
|
||||
try {
|
||||
await useUserStore.getState().updateProfile({
|
||||
const cleanPhone = toEnglishDigits(profileForm.mobile);
|
||||
await updateProfile({
|
||||
firstName: profileForm.firstName,
|
||||
lastName: profileForm.lastName,
|
||||
email: profileForm.email,
|
||||
@@ -92,8 +100,8 @@ export default function UserDashboard() {
|
||||
});
|
||||
setIsEditing(false);
|
||||
toast.success("اطلاعات کاربری با موفقیت ویرایش شد");
|
||||
} catch (err: any) {
|
||||
toast.error(err.message || "خطا در ویرایش اطلاعات");
|
||||
} catch {
|
||||
toast.error("خطا در ویرایش اطلاعات");
|
||||
} finally {
|
||||
setIsSavingProfile(false);
|
||||
}
|
||||
@@ -111,7 +119,7 @@ export default function UserDashboard() {
|
||||
} else {
|
||||
await addAddress(addr);
|
||||
}
|
||||
} catch (err) {
|
||||
} catch {
|
||||
toast.error("خطا در ثبت آدرس");
|
||||
}
|
||||
setEditingAddress(null);
|
||||
@@ -127,7 +135,7 @@ export default function UserDashboard() {
|
||||
try {
|
||||
await deleteAddress(addressToDelete.id);
|
||||
toast.success("آدرس با موفقیت حذف شد");
|
||||
} catch (err) {
|
||||
} catch {
|
||||
toast.error("خطا در حذف آدرس");
|
||||
}
|
||||
setAddressToDelete(null);
|
||||
@@ -370,7 +378,7 @@ export default function UserDashboard() {
|
||||
<div className="text-sm font-black text-medical-gray-900 group-hover:text-canina-blue transition-colors italic">سفارش {toPersian(order.trackingNumber || order.id?.substring(0, 8))}</div>
|
||||
<div className="text-[10px] font-bold text-medical-gray-400 flex items-center gap-1">
|
||||
<Calendar className="w-3 h-3 opacity-30" />
|
||||
{toPersian(new Date(order.date || (order as any).createdAt).toLocaleDateString("fa-IR"))} - ساعت {toPersian(new Date(order.date || (order as any).createdAt).toLocaleTimeString("fa-IR", { hour: '2-digit', minute: '2-digit' }))}
|
||||
{toPersian(new Date(order.date || (order as unknown as Record<string, string>).createdAt || 0).toLocaleDateString("fa-IR"))} - ساعت {toPersian(new Date(order.date || (order as unknown as Record<string, string>).createdAt || 0).toLocaleTimeString("fa-IR", { hour: '2-digit', minute: '2-digit' }))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -477,7 +485,7 @@ export default function UserDashboard() {
|
||||
try {
|
||||
await setDefaultAddress(addr.id);
|
||||
toast.success("آدرس پیشفرض با موفقیت تغییر کرد");
|
||||
} catch (err) {
|
||||
} catch {
|
||||
toast.error("خطا در تغییر آدرس پیشفرض");
|
||||
}
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user