feat: restore profile pets dropdown, fix logout handler, cleanup task titles, fix maintenance guard, add catalog settings & shipping fee calculation
Deploy Canina / deploy (push) Waiting to run
Deploy Canina / deploy (push) Waiting to run
This commit is contained in:
1 parent
c79b0fa394
commit
81a2837c04
5 files changed
+196
-40
No files matched your search
@@ -76,6 +76,8 @@ export default function CheckoutPage() {
|
||||
}, [profile, isLoggedIn]);
|
||||
|
||||
const roundStep = Number(useSettingsStore((state) => state.getText('CHARITY_ROUND_STEP', '10000'))) || 10000;
|
||||
const shippingFeeSetting = useSettingsStore((state) => state.getText('shipping_fee', '0'));
|
||||
const shippingFee = Number(shippingFeeSetting) || 0;
|
||||
const subtotal = getSubtotal();
|
||||
const remainder = subtotal % roundStep;
|
||||
const roundUpDiff = remainder === 0 ? roundStep : roundStep - remainder;
|
||||
@@ -91,7 +93,7 @@ export default function CheckoutPage() {
|
||||
};
|
||||
|
||||
const handleFinalize = async () => {
|
||||
const totalAmount = getTotal();
|
||||
const totalAmount = getTotal() + shippingFee;
|
||||
setLoading(true);
|
||||
const activePet = getActivePet();
|
||||
|
||||
@@ -618,12 +620,16 @@ export default function CheckoutPage() {
|
||||
)}
|
||||
<div className="flex justify-between text-sm font-bold text-white/80">
|
||||
<span>هزینه ارسال</span>
|
||||
<span className="text-green-400 uppercase tracking-widest text-[10px] font-black">رایگان</span>
|
||||
{shippingFee > 0 ? (
|
||||
<span className="font-vazir font-bold text-white">{toPersian(shippingFee.toLocaleString())} تومان</span>
|
||||
) : (
|
||||
<span className="text-green-400 uppercase tracking-widest text-[10px] font-black">رایگان</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex justify-between items-end pt-4">
|
||||
<span className="text-xl font-black italic text-white">مبلغ نهایی</span>
|
||||
<div className="text-left">
|
||||
<p className="text-3xl font-black text-canina-gold leading-none font-vazir">{toPersian(getTotal().toLocaleString())}</p>
|
||||
<p className="text-3xl font-black text-canina-gold leading-none font-vazir">{toPersian((getTotal() + shippingFee).toLocaleString())}</p>
|
||||
<p className="text-[10px] text-white/50 font-bold mt-1">تومان</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -728,13 +734,17 @@ export default function CheckoutPage() {
|
||||
<AddressModal
|
||||
isOpen={showAddressModal}
|
||||
onClose={() => setShowAddressModal(false)}
|
||||
onSave={(newAddr) => {
|
||||
const currentAddresses = profile.addresses || [];
|
||||
const updatedAddresses = [newAddr, ...currentAddresses];
|
||||
updateProfile({ addresses: updatedAddresses });
|
||||
setSelectedAddressId(newAddr.id);
|
||||
setShowAddressModal(false);
|
||||
toast.success('آدرس جدید اضافه شد و به عنوان آدرس تحویل انتخاب گردید.');
|
||||
onSave={async (newAddr) => {
|
||||
try {
|
||||
await useUserStore.getState().addAddress(newAddr);
|
||||
const updatedProfile = useUserStore.getState().profile;
|
||||
if (updatedProfile.addresses && updatedProfile.addresses.length > 0) {
|
||||
setSelectedAddressId(updatedProfile.addresses[0].id);
|
||||
}
|
||||
setShowAddressModal(false);
|
||||
} catch (e) {
|
||||
console.error("Failed to add address", e);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -43,6 +43,8 @@ export default function Header({
|
||||
const [isAuthModalOpen, setIsAuthModalOpen] = useState(false);
|
||||
const [isPrescriptionModalOpen, setIsPrescriptionModalOpen] = useState(false);
|
||||
const [isPetSwitcherOpen, setIsPetSwitcherOpen] = useState(false);
|
||||
const [isProfileMenuOpen, setIsProfileMenuOpen] = useState(false);
|
||||
const userProfileRef = useRef<HTMLDivElement>(null);
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
|
||||
|
||||
@@ -114,6 +116,9 @@ export default function Header({
|
||||
if (petMenuRef.current && !petMenuRef.current.contains(event.target as Node)) {
|
||||
setIsPetSwitcherOpen(false);
|
||||
}
|
||||
if (userProfileRef.current && !userProfileRef.current.contains(event.target as Node)) {
|
||||
setIsProfileMenuOpen(false);
|
||||
}
|
||||
}
|
||||
document.addEventListener("mousedown", handleClickOutside);
|
||||
return () => document.removeEventListener("mousedown", handleClickOutside);
|
||||
@@ -193,16 +198,100 @@ export default function Header({
|
||||
<span>ثبت نسخه دامپزشک</span>
|
||||
</button>
|
||||
|
||||
{/* User Account Button */}
|
||||
{/* User Account Button with Dropdown & Pets List */}
|
||||
{isLoggedIn ? (
|
||||
<Link
|
||||
href="/dashboard"
|
||||
className="flex items-center justify-center p-2.5 sm:px-3 sm:py-2 bg-medical-gray-50 hover:bg-medical-gray-100 border border-medical-gray-200 rounded-xl text-xs font-black text-medical-gray-900 transition-all"
|
||||
title="حساب کاربری"
|
||||
>
|
||||
<User className="w-4 h-4 text-canina-blue" />
|
||||
<span className="hidden sm:inline">{profile.firstName || 'حساب کاربری'}</span>
|
||||
</Link>
|
||||
<div className="relative" ref={userProfileRef}>
|
||||
<button
|
||||
onClick={() => setIsProfileMenuOpen(!isProfileMenuOpen)}
|
||||
className="flex items-center gap-1.5 p-2 sm:px-3 sm:py-2 bg-medical-gray-50 hover:bg-medical-gray-100 border border-medical-gray-200 rounded-xl text-xs font-black text-medical-gray-900 transition-all cursor-pointer"
|
||||
>
|
||||
<User className="w-4 h-4 text-canina-blue" />
|
||||
<span className="hidden sm:inline">{profile.firstName || 'حساب کاربری'}</span>
|
||||
<ChevronDown className={cn("w-3.5 h-3.5 text-medical-gray-500 transition-transform duration-200", isProfileMenuOpen && "rotate-180")} />
|
||||
</button>
|
||||
|
||||
<AnimatePresence>
|
||||
{isProfileMenuOpen && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 8, scale: 0.96 }}
|
||||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
||||
exit={{ opacity: 0, y: 8, scale: 0.96 }}
|
||||
className="absolute left-0 mt-2 w-64 bg-white rounded-2xl shadow-xl border border-medical-gray-100 overflow-hidden z-50 p-2 text-xs font-vazir"
|
||||
>
|
||||
{/* User info header */}
|
||||
<div className="px-3 py-2.5 bg-medical-gray-50 rounded-xl mb-1">
|
||||
<p className="font-black text-medical-gray-900 truncate">
|
||||
{profile.firstName ? `${profile.firstName} ${profile.lastName || ''}` : 'کاربر عزیز'}
|
||||
</p>
|
||||
<p className="text-[10px] text-medical-gray-500 font-mono mt-0.5 truncate">{profile.mobile || profile.email}</p>
|
||||
</div>
|
||||
|
||||
{/* Pets List Section */}
|
||||
<div className="py-1">
|
||||
<div className="flex items-center justify-between px-3 py-1.5 text-[11px] font-black text-medical-gray-500">
|
||||
<span className="flex items-center gap-1">
|
||||
<HeartPulse className="w-3.5 h-3.5 text-canina-blue" />
|
||||
پتهای من ({pets.length})
|
||||
</span>
|
||||
<Link href="/dashboard" onClick={() => setIsProfileMenuOpen(false)} className="text-canina-blue hover:underline text-[10px]">
|
||||
مدیریت
|
||||
</Link>
|
||||
</div>
|
||||
{pets.length > 0 ? (
|
||||
<div className="space-y-1 max-h-32 overflow-y-auto">
|
||||
{pets.map((p) => (
|
||||
<button
|
||||
key={p.id}
|
||||
onClick={() => {
|
||||
setActivePet(p.id);
|
||||
setIsProfileMenuOpen(false);
|
||||
toast.success(`پت فعال به ${p.name} تغییر یافت`);
|
||||
}}
|
||||
className={cn(
|
||||
"w-full flex items-center justify-between px-3 py-1.5 rounded-lg text-right transition-colors",
|
||||
p.id === activePetId ? "bg-canina-blue/10 text-canina-blue font-bold" : "hover:bg-medical-gray-50 text-medical-gray-700"
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-2 truncate">
|
||||
<span className="text-sm">{(p.type === 'سگ' || p.type === ('dog' as any)) ? '🐶' : '🐱'}</span>
|
||||
<span className="truncate">{p.name}</span>
|
||||
</div>
|
||||
{p.id === activePetId && <Check className="w-3.5 h-3.5 shrink-0" />}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="px-3 py-2 text-[10px] text-medical-gray-400 text-center">پتی ثبت نشده است</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="border-t border-medical-gray-100 my-1" />
|
||||
|
||||
{/* Direct Navigation Links */}
|
||||
<Link
|
||||
href="/dashboard"
|
||||
onClick={() => setIsProfileMenuOpen(false)}
|
||||
className="flex items-center gap-2 px-3 py-2 hover:bg-medical-gray-50 text-medical-gray-700 rounded-xl font-bold transition-colors"
|
||||
>
|
||||
<User className="w-4 h-4 text-canina-blue" />
|
||||
<span>داشبورد کاربری</span>
|
||||
</Link>
|
||||
|
||||
<button
|
||||
onClick={() => {
|
||||
logout();
|
||||
setIsProfileMenuOpen(false);
|
||||
toast.success('از حساب کاربری خارج شدید');
|
||||
}}
|
||||
className="w-full flex items-center gap-2 px-3 py-2 hover:bg-rose-50 text-rose-600 rounded-xl font-bold transition-colors text-right"
|
||||
>
|
||||
<LogOut className="w-4 h-4" />
|
||||
<span>خروج از حساب</span>
|
||||
</button>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => setIsAuthModalOpen(true)}
|
||||
|
||||
Reference in new issue
Block a user