diff --git a/frontend/application/components/ArchivePage.tsx b/frontend/application/components/ArchivePage.tsx index 1e421001..6cbb81a9 100644 --- a/frontend/application/components/ArchivePage.tsx +++ b/frontend/application/components/ArchivePage.tsx @@ -366,35 +366,37 @@ export default function ArchivePage({
{/* Standard Breadcrumb Navigation & Integrated Back Button */} -
-
- router.push('/')}>خانه - - { setSelectedCategory("all"); }}>کاتالوگ +
+ {/* Back Button - always visible */} + + + {/* Breadcrumb - truncates on mobile */} +
+ router.push('/')}>خانه + + { setSelectedCategory("all"); }}>کاتالوگ {selectedCategory !== "all" && ( <> - - {CATEGORY_LABELS[selectedCategory] || selectedCategory} + + {CATEGORY_LABELS[selectedCategory] || selectedCategory} )}
-
- - -
+ {/* Mobile Filter Button */} +
diff --git a/frontend/application/components/AuthModal.tsx b/frontend/application/components/AuthModal.tsx index e38a16de..a336bc95 100644 --- a/frontend/application/components/AuthModal.tsx +++ b/frontend/application/components/AuthModal.tsx @@ -1,7 +1,7 @@ "use client"; import React, { useState, useEffect, useRef } from "react"; import { motion, AnimatePresence } from "motion/react"; -import { X, User, Building2, Heart, ShieldCheck, Phone, Key, LogIn, ArrowRight, RefreshCw } from "lucide-react"; +import { X, User, Building2, Heart, ShieldCheck, Phone, Key, LogIn, ArrowRight, RefreshCw, Lock } from "lucide-react"; import { useUserStore, UserRole } from "../lib/store/userStore"; import { authService } from "../lib/services/authService"; import { toast } from "sonner"; @@ -14,9 +14,10 @@ interface AuthModalProps { export default function AuthModal({ isOpen, onClose }: AuthModalProps) { const { setRole, setLoggedIn, fetchProfile } = useUserStore(); - const [view, setView] = useState<"login" | "register" | "otp-phone" | "otp">("login"); + const [view, setView] = useState<"login" | "register" | "otp-phone" | "otp" | "forgot-password" | "forgot-otp" | "reset-password">("login"); const [phoneNumber, setPhoneNumber] = useState(""); const [password, setPassword] = useState(""); + const [newPassword, setNewPassword] = useState(""); const [email, setEmail] = useState(""); const [firstName, setFirstName] = useState(""); const [lastName, setLastName] = useState(""); @@ -40,6 +41,7 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) { setView("login"); setPhoneNumber(""); setPassword(""); + setNewPassword(""); setEmail(""); setFirstName(""); setLastName(""); @@ -159,6 +161,67 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) { } }; + const handleForgotSendOtp = async (e: React.FormEvent) => { + e.preventDefault(); + const cleanPhone = phoneNumber.trim(); + if (!/^09\d{9}$/.test(cleanPhone)) { + toast.error("شماره موبایل نامعتبر است"); + return; + } + setIsLoading(true); + try { + const res = await authService.sendOtp(cleanPhone); + if ((res as any).code) { + toast.info(`کد تایید (تست): ${(res as any).code}`, { duration: 10000 }); + } else { + toast.success("کد بازیابی رمز پیامک شد"); + } + setView("forgot-otp"); + setCountdown(120); + } catch (err: any) { + toast.error(err.message || "خطا در ارسال کد"); + } finally { + setIsLoading(false); + } + }; + + const handleForgotVerifyOtp = async (e: React.FormEvent) => { + e.preventDefault(); + if (otpCode.trim().length !== 5) { + toast.error("کد باید ۵ رقم باشد"); + return; + } + setIsLoading(true); + try { + // Verify OTP - if success, allow password reset + await authService.verifyOtp(phoneNumber.trim(), otpCode.trim()); + setView("reset-password"); + } catch (err: any) { + toast.error(err.message || "کد تایید نامعتبر است"); + } finally { + setIsLoading(false); + } + }; + + const handleResetPassword = async (e: React.FormEvent) => { + e.preventDefault(); + if (newPassword.length < 6) { + toast.error("رمز جدید باید حداقل ۶ کاراکتر باشد"); + return; + } + setIsLoading(true); + try { + // Use authService to update password after OTP verification + await authService.updateProfile({ password: newPassword } as any); + toast.success("رمز عبور با موفقیت تغییر یافت"); + setView("login"); + } catch (err: any) { + toast.error(err.message || "خطا در تغییر رمز"); + } finally { + setIsLoading(false); + } + }; + return ( {isOpen && ( @@ -219,10 +282,13 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) { className="space-y-4" >
- + setPhoneNumber(e.target.value.replace(/[^0-9]/g, ''))} @@ -231,9 +297,12 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) { />
- + setPassword(e.target.value)} @@ -242,7 +311,7 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) { />
-
+
- +
+ + +
)} + + {/* Forgot Password - Enter Phone */} + {view === "forgot-password" && ( + +
+ +

برای بازیابی رمز عبور، کد تایید به شمارهتان ارسال می‌شود

+
+
+ + setPhoneNumber(e.target.value.replace(/[^0-9]/g, ''))} + disabled={isLoading} + className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-xl py-3 px-4 focus:ring-2 focus:ring-canina-blue/20 outline-none font-bold text-left tracking-widest" + /> +
+ + +
+ )} + + {/* Forgot Password - Enter OTP */} + {view === "forgot-otp" && ( + +

کد ارسال شده به {toPersian(phoneNumber)} را وارد کنید

+
+ setOtpCode(e.target.value.replace(/[^0-9]/g, ''))} + disabled={isLoading} + className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-2xl py-4 pl-4 pr-4 focus:ring-2 focus:ring-canina-blue/20 outline-none font-black text-2xl text-center tracking-[0.5em]" + /> +
+ {countdown > 0 ? ( +

ارسال مجدد پس از {toPersian(countdown)} ثانیه

+ ) : ( + + )} + +
+ )} + + {/* Reset Password */} + {view === "reset-password" && ( + +
+

هویت تایید شد. رمز جدید خود را وارد کنید

+
+
+ + setNewPassword(e.target.value)} + disabled={isLoading} + className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-xl py-3 px-4 focus:ring-2 focus:ring-canina-blue/20 outline-none text-left" + /> +
+ +
+ )} +
diff --git a/frontend/application/components/CheckoutPage.tsx b/frontend/application/components/CheckoutPage.tsx index dd8639b8..a8991afb 100644 --- a/frontend/application/components/CheckoutPage.tsx +++ b/frontend/application/components/CheckoutPage.tsx @@ -36,9 +36,27 @@ export default function CheckoutPage() { const [dbProducts, setDbProducts] = useState([]); const [paymentMethod, setPaymentMethod] = useState('online'); + const [selectedAddressId, setSelectedAddressId] = useState(''); + const [showNewAddressForm, setShowNewAddressForm] = useState(false); + + // Custom manual address state if guest or not using stored addresses + const [manualName, setManualName] = useState(''); + const [manualPhone, setManualPhone] = useState(''); + const [manualAddress, setManualAddress] = useState(''); + useEffect(() => { productService.getProducts({ limit: 999 }).then(res => setDbProducts(res.data)); - }, []); + + // Set default selected address if logged in + if (profile.addresses && profile.addresses.length > 0) { + const def = profile.addresses.find(a => a.isDefault) || profile.addresses[0]; + setSelectedAddressId(def.id); + } else if (profile.firstName) { + // Pre-fill profile info for manual fields + setManualName(`${profile.firstName} ${profile.lastName}`.trim()); + setManualPhone(profile.mobile || ''); + } + }, [profile]); const subtotal = getSubtotal(); const roundedAmount = Math.ceil(subtotal / 10000) * 10000; @@ -55,26 +73,49 @@ export default function CheckoutPage() { }; const handleFinalize = async () => { + const totalAmount = getTotal(); + + if (paymentMethod === 'wallet' && profile.walletBalance < totalAmount) { + toast.error("اعتبار کیف پول شما کافی نیست. لطفاً ابتدا آن را شارژ کنید یا روش پرداخت دیگری انتخاب کنید."); + return; + } + setLoading(true); const activePet = getActivePet(); try { - // 1. Register the order in the backend + // 1. If using wallet, deduct balance and add purchase transaction + if (paymentMethod === 'wallet') { + const newBalance = profile.walletBalance - totalAmount; + const newTransaction = { + id: `TR-${Math.floor(Math.random() * 90000) + 10000}`, + type: 'purchase' as const, + amount: totalAmount, + date: new Date().toISOString(), + status: 'success' as const + }; + await updateProfile({ + walletBalance: newBalance, + transactions: [newTransaction, ...(profile.transactions || [])] + }); + } + + // 2. Register the order in the backend const orderId = await addOrder({ items: [...items], - total: getTotal(), + total: totalAmount, charityDonation: charityDonation, petId: activePet?.id }); - // 2. Update user charity total + // 3. Update user charity total if (charityDonation > 0) { - updateProfile({ + await updateProfile({ charityDonationTotal: (profile.charityDonationTotal || 0) + charityDonation }); } - // 3. Update pet consumptions for the refill logic + // 4. Update pet consumptions for the refill logic if (activePet) { const newConsumptions = [...(activePet.consumptions || [])]; @@ -158,20 +199,99 @@ export default function CheckoutPage() {

اطلاعات ارسال

-
-
- - -
-
- - -
-
- -