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
@@ -117,7 +117,7 @@ export default function PetProfile({ initialView, advisorNeed }: {
|
||||
const recommendedProducts = useMemo(() => {
|
||||
if (!activePet || products.length === 0) return [];
|
||||
|
||||
let picks: { product: Product, reason?: string }[] = [];
|
||||
const picks: { product: Product, reason?: string }[] = [];
|
||||
|
||||
// Priority 1: Match activePet.medicalConditions directly against product.symptoms
|
||||
if (activePet.medicalConditions && activePet.medicalConditions.length > 0) {
|
||||
|
||||
@@ -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("خطا در تغییر آدرس پیشفرض");
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
"use client";
|
||||
import React, { useState } from "react";
|
||||
import { Play, PlayCircle, Star, ShieldCheck, X } from "lucide-react";
|
||||
import { Play, Star, ShieldCheck, X } from "lucide-react";
|
||||
import { motion, AnimatePresence } from "motion/react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import SafeImage from "./SafeImage";
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import { videoService, Video } from "../lib/services/videoService";
|
||||
|
||||
export interface TestimonialItem {
|
||||
id?: string;
|
||||
clinicName?: string;
|
||||
vetName?: string;
|
||||
imageUrl?: string;
|
||||
quote?: string;
|
||||
title?: string;
|
||||
thumbnail?: string;
|
||||
videoUrl?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
const FALLBACK_VIDEOS = [
|
||||
{
|
||||
id: "v1",
|
||||
@@ -38,11 +49,10 @@ const FALLBACK_VIDEOS = [
|
||||
}
|
||||
];
|
||||
|
||||
export default function VetGallery({ testimonials = [] }: { testimonials?: any[] }) {
|
||||
const router = useRouter();
|
||||
export default function VetGallery({ testimonials = [] }: { testimonials?: TestimonialItem[] }) {
|
||||
const getText = useSettingsStore(state => state.getText);
|
||||
const [apiVideos, setApiVideos] = useState<Video[]>([]);
|
||||
const [selectedVideo, setSelectedVideo] = useState<any>(null);
|
||||
const [selectedVideo, setSelectedVideo] = useState<any | null>(null);
|
||||
|
||||
React.useEffect(() => {
|
||||
videoService.getVideos({ featured: true, limit: 3 }).then((data) => {
|
||||
@@ -55,13 +65,13 @@ export default function VetGallery({ testimonials = [] }: { testimonials?: any[]
|
||||
const displayItems = testimonials.length > 0
|
||||
? testimonials.map((t, idx) => ({
|
||||
id: t.id || `t-${idx}`,
|
||||
title: t.clinicName ? `${t.vetName} — ${t.clinicName}` : t.vetName,
|
||||
doctor: t.vetName,
|
||||
title: t.clinicName ? `${t.vetName} — ${t.clinicName}` : (t.vetName || ''),
|
||||
doctor: t.vetName || '',
|
||||
duration: "۰۲:۰۰",
|
||||
thumbnail: t.imageUrl || "https://images.unsplash.com/photo-1576091160550-217359f42f8c?auto=format&fit=crop&q=80&w=400",
|
||||
videoUrl: "https://www.w3schools.com/html/mov_bbb.mp4",
|
||||
description: t.quote,
|
||||
quote: t.quote
|
||||
description: t.quote || '',
|
||||
quote: t.quote || ''
|
||||
}))
|
||||
: (apiVideos.length > 0 ? apiVideos : FALLBACK_VIDEOS);
|
||||
|
||||
@@ -102,7 +112,7 @@ export default function VetGallery({ testimonials = [] }: { testimonials?: any[]
|
||||
<div className="absolute inset-0 bg-medical-gray-900/20 group-hover:bg-transparent transition-colors z-10" />
|
||||
<SafeImage
|
||||
src={video.thumbnail || video.imageUrl || '/images/vets/vet1.webp'}
|
||||
alt={video.title || video.vetName}
|
||||
alt={video.title || video.vetName || 'ویدیو دامپزشک'}
|
||||
className="w-full h-full"
|
||||
imgClassName="object-cover grayscale-[30%] group-hover:grayscale-0 transition-all duration-700"
|
||||
/>
|
||||
@@ -117,7 +127,7 @@ export default function VetGallery({ testimonials = [] }: { testimonials?: any[]
|
||||
</div>
|
||||
</div>
|
||||
<h4 className="text-lg font-black text-medical-gray-900 mb-2 group-hover:text-canina-blue transition-colors leading-tight font-vazir">
|
||||
{video.title || video.quote?.substring(0, 40) + '...'}
|
||||
{video.title || (video.quote ? video.quote.substring(0, 40) + '...' : '')}
|
||||
</h4>
|
||||
<div className="flex items-center gap-2 text-medical-gray-500 font-bold text-sm font-vazir">
|
||||
<ShieldCheck className="w-4 h-4 text-canina-blue" />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
import React, { useState } from "react";
|
||||
import { motion, AnimatePresence } from "motion/react";
|
||||
import { ChevronRight, PlayCircle, Star, ShieldCheck, X, Search, Clock, User } from "lucide-react";
|
||||
import { ChevronRight, PlayCircle, ShieldCheck, X, Search, Clock, User } from "lucide-react";
|
||||
import SafeImage from "./SafeImage";
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('CartDrawer', () => {
|
||||
coupon: null,
|
||||
applyCoupon: vi.fn(),
|
||||
addItem: vi.fn(),
|
||||
} as any);
|
||||
} as unknown as ReturnType<typeof useCartStore>);
|
||||
|
||||
render(<CartDrawer isOpen={true} onClose={vi.fn()} onCheckout={vi.fn()} />);
|
||||
|
||||
@@ -64,7 +64,7 @@ describe('CartDrawer', () => {
|
||||
coupon: null,
|
||||
applyCoupon: vi.fn(),
|
||||
addItem: vi.fn(),
|
||||
} as any);
|
||||
} as unknown as ReturnType<typeof useCartStore>);
|
||||
|
||||
render(<CartDrawer isOpen={true} onClose={vi.fn()} onCheckout={vi.fn()} />);
|
||||
|
||||
@@ -86,7 +86,7 @@ describe('CartDrawer', () => {
|
||||
coupon: null,
|
||||
applyCoupon: vi.fn(),
|
||||
addItem: vi.fn(),
|
||||
} as any);
|
||||
} as unknown as ReturnType<typeof useCartStore>);
|
||||
|
||||
render(<CartDrawer isOpen={true} onClose={vi.fn()} onCheckout={vi.fn()} />);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ describe('FeaturedProducts', () => {
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(usePetStore).mockReturnValue({
|
||||
getActivePet: () => null,
|
||||
} as any);
|
||||
} as unknown as ReturnType<typeof usePetStore>);
|
||||
});
|
||||
|
||||
it('renders loading skeletons initially', () => {
|
||||
@@ -48,7 +48,7 @@ describe('FeaturedProducts', () => {
|
||||
});
|
||||
|
||||
it('renders products once loaded', async () => {
|
||||
vi.mocked(productService.getFeaturedProducts).mockResolvedValue(mockProducts as any);
|
||||
vi.mocked(productService.getFeaturedProducts).mockResolvedValue(mockProducts as unknown as ReturnType<typeof productService.getFeaturedProducts>);
|
||||
render(<FeaturedProducts onProductClick={vi.fn()} onShopNavigate={vi.fn()} />);
|
||||
|
||||
await waitFor(() => {
|
||||
@@ -59,7 +59,7 @@ describe('FeaturedProducts', () => {
|
||||
|
||||
it('calls onProductClick when product card is clicked', async () => {
|
||||
const handleProductClick = vi.fn();
|
||||
vi.mocked(productService.getFeaturedProducts).mockResolvedValue(mockProducts as any);
|
||||
vi.mocked(productService.getFeaturedProducts).mockResolvedValue(mockProducts as unknown as ReturnType<typeof productService.getFeaturedProducts>);
|
||||
render(<FeaturedProducts onProductClick={handleProductClick} onShopNavigate={vi.fn()} />);
|
||||
|
||||
await waitFor(() => {
|
||||
@@ -72,7 +72,7 @@ describe('FeaturedProducts', () => {
|
||||
|
||||
it('calls onShopNavigate when navigation link is clicked', async () => {
|
||||
const handleShopNavigate = vi.fn();
|
||||
vi.mocked(productService.getFeaturedProducts).mockResolvedValue(mockProducts as any);
|
||||
vi.mocked(productService.getFeaturedProducts).mockResolvedValue(mockProducts as unknown as ReturnType<typeof productService.getFeaturedProducts>);
|
||||
render(<FeaturedProducts onProductClick={vi.fn()} onShopNavigate={handleShopNavigate} />);
|
||||
|
||||
const navBtn = screen.getByText('مشاهده تمامی محصولات');
|
||||
|
||||
@@ -25,21 +25,21 @@ describe('Header', () => {
|
||||
|
||||
vi.mocked(useCartStore).mockReturnValue({
|
||||
getTotalItems: () => 3,
|
||||
} as any);
|
||||
} as unknown as ReturnType<typeof useCartStore>);
|
||||
|
||||
vi.mocked(usePetStore).mockReturnValue({
|
||||
pets: [],
|
||||
activePetId: null,
|
||||
setActivePet: vi.fn(),
|
||||
getActivePet: () => null,
|
||||
} as any);
|
||||
} as unknown as ReturnType<typeof usePetStore>);
|
||||
|
||||
vi.mocked(useUserStore).mockReturnValue({
|
||||
role: 'User_Guest',
|
||||
isLoggedIn: false,
|
||||
logout: vi.fn(),
|
||||
profile: { firstName: '' },
|
||||
} as any);
|
||||
} as unknown as ReturnType<typeof useUserStore>);
|
||||
});
|
||||
|
||||
it('renders brand name and login button when guest', () => {
|
||||
@@ -65,14 +65,14 @@ describe('Header', () => {
|
||||
isLoggedIn: true,
|
||||
logout: vi.fn(),
|
||||
profile: { firstName: 'کوروش' },
|
||||
} as any);
|
||||
} as unknown as ReturnType<typeof useUserStore>);
|
||||
|
||||
vi.mocked(usePetStore).mockReturnValue({
|
||||
pets: [{ id: 'pet-1', name: 'ملوس', type: 'گربه' }],
|
||||
activePetId: 'pet-1',
|
||||
setActivePet: vi.fn(),
|
||||
getActivePet: () => ({ id: 'pet-1', name: 'ملوس', type: 'گربه' }),
|
||||
} as any);
|
||||
} as unknown as ReturnType<typeof usePetStore>);
|
||||
|
||||
render(
|
||||
<Header
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('Hero', () => {
|
||||
return fallback;
|
||||
});
|
||||
|
||||
vi.mocked(useSettingsStore).mockImplementation((selector: any) => selector({ getText: mockGetText }));
|
||||
vi.mocked(useSettingsStore).mockImplementation((selector: (state: { getText: (key: string, fallback: string) => string }) => unknown) => selector({ getText: mockGetText }) as ReturnType<typeof selector>);
|
||||
|
||||
render(<Hero onShopNavigate={vi.fn()} />);
|
||||
|
||||
@@ -31,8 +31,8 @@ describe('Hero', () => {
|
||||
});
|
||||
|
||||
it('calls onShopNavigate when "مشاهده محصولات" button is clicked', () => {
|
||||
const mockGetText = vi.fn().mockImplementation((key, fallback) => fallback);
|
||||
vi.mocked(useSettingsStore).mockImplementation((selector: any) => selector({ getText: mockGetText }));
|
||||
const mockGetText = vi.fn().mockImplementation((_key, fallback) => fallback);
|
||||
vi.mocked(useSettingsStore).mockImplementation((selector: (state: { getText: (key: string, fallback: string) => string }) => unknown) => selector({ getText: mockGetText }) as ReturnType<typeof selector>);
|
||||
|
||||
const handleShopNavigate = vi.fn();
|
||||
render(<Hero onShopNavigate={handleShopNavigate} />);
|
||||
|
||||
Reference in new issue
Block a user