feat: complete payment retry, reviews system, catalog mode enforcement, and UI text defaults
Deploy Canina / deploy (push) Successful in 1m48s

This commit is contained in:
parsa aghaei committed 2026-08-17 09:01:33 +03:30
1 parent e1b035d6dd
commit 2fca778930
24 files changed
+2297 -242

No files matched your search

@@ -12,7 +12,9 @@ import {
ArrowRight,
Heart,
PlusCircle,
Copy
Copy,
Phone,
AlertCircle
} from "lucide-react";
import { toPersian, cn } from "../lib/utils";
import { PRODUCTS } from "../lib/data/products";
@@ -195,6 +197,44 @@ export default function CheckoutPage() {
}
};
const getText = useSettingsStore(state => state.getText);
const isCatalogMode = getText('catalog_mode', 'false') === 'true';
const isCatalogDisableCheckout = getText('catalog_disable_checkout', 'false') === 'true';
const isCheckoutDisabled = isCatalogMode || isCatalogDisableCheckout;
if (isCheckoutDisabled) {
return (
<div className="min-h-[70vh] bg-medical-gray-50 flex items-center justify-center p-6 text-center font-vazir" dir="rtl">
<div className="max-w-md bg-white border border-medical-gray-200 rounded-3xl p-8 shadow-xl space-y-6">
<div className="w-16 h-16 bg-amber-50 text-amber-600 rounded-2xl flex items-center justify-center mx-auto">
<AlertCircle className="w-8 h-8" />
</div>
<h2 className="text-xl font-black text-medical-gray-900">
امکان ثبت سفارش آنلاین موقتاً غیرفعال است
</h2>
<p className="text-xs sm:text-sm text-medical-gray-600 font-bold leading-relaxed">
سامانه در حال حاضر در حالت کاتالوگ قرار دارد. جهت استعلام قیمت و دریافت مشاوره تخصصی می‌توانید با کارشناسان ما تماس بگیرید.
</p>
<div className="flex flex-col sm:flex-row gap-3 pt-2">
<a
href="tel:02188888888"
className="flex-1 px-4 py-3 bg-canina-blue hover:bg-canina-dark text-white rounded-xl text-xs font-black transition-all shadow-md flex items-center justify-center gap-2"
>
<Phone className="w-4 h-4" />
<span>تماس با پشتیبانی</span>
</a>
<button
onClick={() => router.push('/shop')}
className="flex-1 px-4 py-3 bg-medical-gray-100 hover:bg-medical-gray-200 text-medical-gray-700 rounded-xl text-xs font-bold transition-all"
>
مشاهده کاتالوگ
</button>
</div>
</div>
</div>
);
}
if (items.length === 0) {
return (
<div className="min-h-screen bg-medical-gray-50 flex items-center justify-center p-6" dir="rtl">
+17 -12
View File
@@ -86,6 +86,9 @@ export default function Header({
const { pets, activePetId, setActivePet } = usePetStore();
const { isLoggedIn, logout, profile } = useUserStore();
const getText = useSettingsStore(state => state.getText);
const isCatalogMode = getText('catalog_mode', 'false') === 'true';
const isCatalogDisableCart = getText('catalog_disable_cart', 'false') === 'true';
const isCartDisabled = isCatalogMode || isCatalogDisableCart;
useEffect(() => {
const loadNavFilters = async () => {
@@ -305,18 +308,20 @@ export default function Header({
)}
{/* Shopping Cart Button */}
<button
onClick={onCartOpen}
className="relative px-3.5 py-2 bg-canina-blue text-white rounded-xl text-xs font-black hover:bg-medical-gray-900 transition-all flex items-center gap-2 shadow-sm"
>
<ShoppingBag className="w-4 h-4" />
<span className="hidden sm:inline">سبد خرید</span>
{isMounted && getTotalItems() > 0 && (
<span className="w-5 h-5 bg-canina-gold text-canina-dark rounded-full text-[10px] font-black flex items-center justify-center">
{getTotalItems()}
</span>
)}
</button>
{!isCartDisabled && (
<button
onClick={onCartOpen}
className="relative px-3.5 py-2 bg-canina-blue text-white rounded-xl text-xs font-black hover:bg-medical-gray-900 transition-all flex items-center gap-2 shadow-sm"
>
<ShoppingBag className="w-4 h-4" />
<span className="hidden sm:inline">سبد خرید</span>
{isMounted && getTotalItems() > 0 && (
<span className="w-5 h-5 bg-canina-gold text-canina-dark rounded-full text-[10px] font-black flex items-center justify-center">
{getTotalItems()}
</span>
)}
</button>
)}
</div>
</div>
@@ -1,8 +1,21 @@
"use client";
import React from "react";
import { Wrench, Phone, ShieldCheck } from "lucide-react";
import { Wrench, Phone, ShieldCheck, Clock } from "lucide-react";
import { useSettingsStore } from "../lib/store/settingsStore";
export default function MaintenancePage() {
const getText = useSettingsStore((state) => state.getText);
const title = getText("maintenance_title", "سامانه در حال به‌روزرسانی و ارتقای فنی است");
const desc = getText(
"maintenance_desc",
"وب‌سایت رسمی کنینا ایران جهت ارتقای زیرساخت‌ها و بهبود عملکرد به صورت موقت در دست به‌روزرسانی است. از شکیبایی شما سپاسگزاریم."
);
const badge = getText("maintenance_badge", "سامانه در حال به‌روزرسانی و ارتقا");
const eta = getText("maintenance_eta", "زمان تقریبی بازگشایی: کمتر از ۲ ساعت آینده");
const phone = getText("maintenance_contact_phone", "۰۲۱-۸۸۸۸۸۸۸۸");
const rawPhone = phone.replace(/[^0-9]/g, "");
return (
<div className="min-h-screen bg-medical-gray-900 text-white flex flex-col items-center justify-center p-6 text-center font-vazir relative overflow-hidden" dir="rtl">
{/* Glow Effects */}
@@ -15,24 +28,31 @@ export default function MaintenancePage() {
</div>
<span className="inline-block px-4 py-1.5 bg-canina-gold/20 text-canina-gold border border-canina-gold/30 rounded-full text-xs font-black tracking-widest uppercase">
سامانه در حال به‌روزرسانی و ارتقا
{badge}
</span>
<h1 className="text-3xl sm:text-5xl font-black tracking-tight leading-tight">
به‌زودی با خدمات کامل‌تر بازمی‌گردیم
<h1 className="text-2xl sm:text-4xl font-black tracking-tight leading-tight">
{title}
</h1>
<p className="text-sm sm:text-base text-medical-gray-300 leading-relaxed">
وب‌سایت کنینا ایران جهت ارتقای زیرساخت‌ها و ارائه خدمات بهتر به شما سرپرستان و دامپزشکان محترم به صورت موقت در دست به‌روزرسانی است. از شکیبایی شما سپاسگزاریم.
{desc}
</p>
<div className="pt-4 flex flex-col sm:flex-row items-center justify-center gap-4">
{eta && (
<div className="inline-flex items-center gap-2 px-4 py-2 bg-white/5 border border-white/10 rounded-xl text-xs text-medical-gray-300 font-bold">
<Clock className="w-4 h-4 text-canina-gold" />
<span>{eta}</span>
</div>
)}
<div className="pt-2 flex flex-col sm:flex-row items-center justify-center gap-4">
<a
href="tel:0218888"
href={`tel:${rawPhone || "02188888888"}`}
className="w-full sm:w-auto px-6 py-3.5 bg-canina-blue hover:bg-canina-dark text-white font-black text-xs rounded-xl flex items-center justify-center gap-2 shadow-lg transition-all"
>
<Phone className="w-4 h-4" />
<span>پشتیبانی اضطراری: ۰۲۱-۸۸۸۸</span>
<span>پشتیبانی اضطراری: {phone}</span>
</a>
</div>
</div>
@@ -1,6 +1,6 @@
/* eslint-disable @next/next/no-img-element */
"use client";
import React from "react";
import React, { useState } from "react";
import { motion, AnimatePresence } from "motion/react";
import {
X,
@@ -14,29 +14,58 @@ import {
Truck,
PackageCheck,
XCircle,
AlertCircle
AlertCircle,
Wallet,
Building2,
Loader2,
ArrowRight,
Sparkles,
} from "lucide-react";
import { toPersian } from "../lib/utils";
import api from "../lib/services/api";
import { toast } from "sonner";
interface OrderDetailsModalProps {
isOpen: boolean;
onClose: () => void;
order: Record<string, unknown> | null;
onOrderUpdated?: (orderId: string, newStatus: string) => void;
}
export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetailsModalProps) {
export default function OrderDetailsModal({
isOpen,
onClose,
order,
onOrderUpdated,
}: OrderDetailsModalProps) {
const [retryModalOpen, setRetryModalOpen] = useState(false);
const [selectedMethod, setSelectedMethod] = useState<'online' | 'wallet' | 'card'>('online');
const [isProcessingPayment, setIsProcessingPayment] = useState(false);
if (!order) return null;
const getProductName = (p: Record<string, unknown> | undefined) => String(p?.nameFa || p?.name || p?.nameEn || 'محصول کنینا');
const getProductImage = (p: Record<string, unknown> | undefined) => String(p?.imageUrl || p?.image || '/products/product-placeholder.png');
const displayTrackingCode = String(order.trackingNumber || (typeof order.id === 'string' ? order.id.substring(0, 8) : '') || 'CN-0000');
const orderId = String(order.id || '');
const orderStatus = String(order.status || '');
const isPendingPayment = orderStatus === 'pending_payment';
const getProductName = (p: Record<string, unknown> | undefined) =>
String(p?.nameFa || p?.name || p?.nameEn || 'محصول کنینا');
const getProductImage = (p: Record<string, unknown> | undefined) =>
String(p?.imageUrl || p?.image || '/products/product-placeholder.png');
const displayTrackingCode = String(
order.trackingNumber || (typeof order.id === 'string' ? order.id.substring(0, 8) : '') || 'CN-0000'
);
const rawDate = order.date || order.createdAt;
const orderDate = rawDate ? new Date(String(rawDate)) : new Date();
const formattedDate = orderDate.toLocaleDateString("fa-IR");
const formattedTime = orderDate.toLocaleTimeString("fa-IR", { hour: '2-digit', minute: '2-digit' });
const items = Array.isArray(order.items) ? (order.items as Record<string, unknown>[]) : (Array.isArray(order.orderItems) ? (order.orderItems as Record<string, unknown>[]) : []);
const items = Array.isArray(order.items)
? (order.items as Record<string, unknown>[])
: Array.isArray(order.orderItems)
? (order.orderItems as Record<string, unknown>[])
: [];
const itemsSubtotal = items.reduce((sum: number, item: Record<string, unknown>) => {
const prod = item.product as Record<string, unknown> | undefined;
const price = Number(prod?.priceValue || item.priceValue || 0);
@@ -46,20 +75,26 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
const charityAmount = Number(order.charityDonation || 0);
const totalAmount = Number(order.total || order.totalAmount || itemsSubtotal + charityAmount);
const isRefill = Boolean(order.isRefill);
const refillDiscount = isRefill ? Math.round(itemsSubtotal * 0.05) : 0;
const paymentMethodText = order.paymentMethod === 'wallet' ? 'پرداخت از کیف پول الکترونیک' : 'پرداخت آنلاین از درگاه شتاب';
const getPaymentMethodTitle = (method?: unknown) => {
const m = String(method || '');
if (m === 'wallet') return 'کیف پول الکترونیک کنینا';
if (m === 'card' || m === 'card_to_card') return 'کارت به کارت مستقیم';
return 'درگاه پرداخت اینترنتی زیبال (شتاب)';
};
const handlePrint = () => {
const printWindow = window.open('', '_blank');
if (!printWindow) return;
const itemsHtml = items.map((item: Record<string, unknown>) => {
const prod = item.product as Record<string, unknown> | undefined;
const pName = getProductName(prod);
const pImg = getProductImage(prod);
const pPrice = Number(prod?.priceValue || item.priceValue || 0);
const rowTotal = pPrice * Number(item.quantity || 1);
return `
const itemsHtml = items
.map((item: Record<string, unknown>) => {
const prod = item.product as Record<string, unknown> | undefined;
const pName = getProductName(prod);
const pImg = getProductImage(prod);
const pPrice = Number(prod?.priceValue || item.priceValue || 0);
const rowTotal = pPrice * Number(item.quantity || 1);
return `
<tr>
<td style="padding: 14px; border-bottom: 1px solid #e5e7eb; vertical-align: middle;">
<div style="display: flex; align-items: center; gap: 12px;">
@@ -67,12 +102,19 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
<span style="font-weight: 700; color: #111827;">${pName}</span>
</div>
</td>
<td style="padding: 14px; border-bottom: 1px solid #e5e7eb; text-align: center; font-weight: 700;">${toPersian(Number(item.quantity || 1))}</td>
<td style="padding: 14px; border-bottom: 1px solid #e5e7eb; text-align: left; font-weight: 700;">${toPersian(pPrice.toLocaleString())} تومان</td>
<td style="padding: 14px; border-bottom: 1px solid #e5e7eb; text-align: left; font-weight: 900; color: #0055FF;">${toPersian(rowTotal.toLocaleString())} تومان</td>
<td style="padding: 14px; border-bottom: 1px solid #e5e7eb; text-align: center; font-weight: 700;">${toPersian(
Number(item.quantity || 1)
)}</td>
<td style="padding: 14px; border-bottom: 1px solid #e5e7eb; text-align: left; font-weight: 700;">${toPersian(
pPrice.toLocaleString()
)} تومان</td>
<td style="padding: 14px; border-bottom: 1px solid #e5e7eb; text-align: left; font-weight: 900; color: #0055FF;">${toPersian(
rowTotal.toLocaleString()
)} تومان</td>
</tr>
`;
}).join('');
})
.join('');
printWindow.document.write(`
<!DOCTYPE html>
@@ -98,8 +140,8 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
.summary-row.total { font-size: 20px; font-weight: 900; color: #fbbf24; border-top: 1px solid #334155; padding-top: 14px; margin-top: 14px; margin-bottom: 0; }
.footer { margin-top: 40px; text-align: center; font-size: 11px; color: #9ca3af; font-weight: 700; }
@media print {
body { padding: 0; }
.invoice-card { border: none; padding: 0; }
body { padding: 0; background: #fff; }
.invoice-card { border: none; padding: 0; max-width: 100%; }
}
</style>
</head>
@@ -107,33 +149,41 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
<div class="invoice-card">
<div class="header">
<div>
<div class="logo-text">CANINA | کنینا</div>
<div class="sub-logo">مکمل‌های تخصصی دامپزشکی آلمان</div>
<div class="logo-text">Canina Iran</div>
<div class="sub-logo">نماینده رسمی Canina pharma GmbH آلمان در ایران</div>
</div>
<div style="text-align: left;">
<div style="font-size: 14px; font-weight: 900; color: #111827;">کد پیگیری: ${toPersian(displayTrackingCode)}</div>
<div style="font-size: 12px; color: #6b7280; font-weight: 700;">تاریخ: ${toPersian(formattedDate)} - ساعت ${toPersian(formattedTime)}</div>
<h2 style="margin: 0; font-size: 22px; font-weight: 900; color: #111827;">صورتحساب فروش کالا و خدمات</h2>
<span style="font-size: 12px; font-weight: 700; color: #0055FF; margin-top: 4px; display: block;">شناسه فاکتور: ${toPersian(
displayTrackingCode
)}</span>
</div>
</div>
<div class="meta-grid">
<div>
<p style="margin: 0 0 6px 0;"><strong>گیرنده و آدرس:</strong> ${order.shippingAddress || "ثبت‌شده در حساب کاربری"}</p>
<p style="margin: 0;"><strong>روش پرداخت:</strong> ${paymentMethodText}</p>
<strong style="color: #4b5563;">اطلاعات سفارش:</strong>
<div style="margin-top: 6px;">تاریخ ثبت: ${toPersian(formattedDate)} - ساعت ${toPersian(
formattedTime
)}</div>
<div style="margin-top: 4px;">روش پرداخت: ${getPaymentMethodTitle(order.paymentMethod)}</div>
<div style="margin-top: 4px;">وضعیت: ${getStatusLabel(orderStatus)}</div>
</div>
<div style="text-align: left;">
<p style="margin: 0 0 6px 0;"><strong>وضعیت سفارش:</strong> ${order.status === 'delivered' ? 'تحویل شده' : 'در حال پردازش در انبار'}</p>
<p style="margin: 0;"><strong>نوع سفارش:</strong> ${isRefill ? 'تمدید خودکار (Refill)' : 'عادی'}</p>
<div>
<strong style="color: #4b5563;">نشانی تحویل گیرنده:</strong>
<div style="margin-top: 6px; line-height: 1.5;">${
String(order.shippingAddress || 'آدرس ثبتی کاربر در حساب کاربری')
}</div>
</div>
</div>
<table>
<thead>
<tr>
<th>شرح محصول</th>
<th>شرح کالا / مکمل دارویی</th>
<th style="text-align: center;">تعداد</th>
<th>قیمت واحد</th>
<th>مجموع</th>
<th style="text-align: left;">مبلغ واحد</th>
<th style="text-align: left;">مبلغ کل</th>
</tr>
</thead>
<tbody>
@@ -143,43 +193,37 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
<div class="summary-box">
<div class="summary-row">
<span>مجموع اولیه اقلام:</span>
<span>جمع اقلام:</span>
<span>${toPersian(itemsSubtotal.toLocaleString())} تومان</span>
</div>
${isRefill ? `
<div class="summary-row" style="color: #4ade80;">
<span>تخفیف تمدید خودکار (۵٪):</span>
<span>${toPersian(refillDiscount.toLocaleString())}- تومان</span>
</div>
` : ''}
${charityAmount > 0 ? `
<div class="summary-row" style="color: #f472b6;">
<span>کمک اهدایی (ردپای مهربانی):</span>
<span>${toPersian(charityAmount.toLocaleString())}+ تومان</span>
</div>
` : ''}
${
charityAmount > 0
? `
<div class="summary-row" style="color: #f472b6;">
<span>کمک به حیوانات بی‌سرپرست (ردپای مهربانی):</span>
<span>${toPersian(charityAmount.toLocaleString())}+ تومان</span>
</div>
`
: ''
}
<div class="summary-row">
<span>هزینه ارسال:</span>
<span style="color: #4ade80;">رایگان</span>
<span>هزینه بسته‌بندی و ارسال اکسپرس:</span>
<span style="color: #34d399;">رایگان (تحویل سراسری)</span>
</div>
<div class="summary-row total">
<span>مبلغ نهایی پرداخت شده:</span>
<span>مبلغ نهایی فاکتور:</span>
<span>${toPersian(totalAmount.toLocaleString())} تومان</span>
</div>
</div>
<div class="footer">
این فاکتور رسمی به صورت هوشمند و سیستمی صادر شده و فاقد نیاز به مهر و امضای فیزیکی است.<br/>
پشتیبانی کنینا آلمان: ۰۲۱-۸۸۸۸۸۸۸۸ | www.canina.ir
داروخانه تخصصی مکمل‌های کنینا ایران • تلفن پشتیبانی: ۰۲۱-۸۸۸۸۸۸۸۸ • وب‌سایت: www.canina.ir
</div>
</div>
<script>
window.onload = function() {
setTimeout(function() {
window.print();
}, 400);
};
setTimeout(function() { window.print(); }, 300);
}
</script>
</body>
</html>
@@ -187,35 +231,90 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
printWindow.document.close();
};
const getStatusIcon = (status: string) => {
switch (status) {
case 'delivered': return <CheckCircle2 className="w-5 h-5 text-green-500" />;
case 'shipped': return <Truck className="w-5 h-5 text-blue-500" />;
case 'packaged':
case 'ready_to_ship': return <PackageCheck className="w-5 h-5 text-purple-600" />;
case 'cancelled': return <XCircle className="w-5 h-5 text-red-500" />;
case 'pending_payment': return <AlertCircle className="w-5 h-5 text-rose-500" />;
default: return <Clock className="w-5 h-5 text-amber-500" />;
const handleExecuteRetryPayment = async () => {
try {
setIsProcessingPayment(true);
const res = await api.post(`/orders/${orderId}/retry-payment`, {
paymentMethod: selectedMethod,
});
if (res.data?.success) {
if (selectedMethod === 'online') {
// Initiate Zibal Payment
const payRes = await api.post('/payment/zibal/initiate', {
orderId,
});
if (payRes.data?.paymentUrl) {
toast.success('در حال انتقال به درگاه پرداخت زیبال...');
window.location.href = payRes.data.paymentUrl;
return;
}
} else if (selectedMethod === 'wallet') {
toast.success('پرداخت سفارش با موفقیت از طریق کیف پول انجام شد.');
if (onOrderUpdated) {
onOrderUpdated(orderId, 'processing');
}
setRetryModalOpen(false);
onClose();
} else {
toast.success('روش پرداخت به کارت به کارت تغییر یافت.');
if (onOrderUpdated) {
onOrderUpdated(orderId, 'pending_payment');
}
setRetryModalOpen(false);
}
}
} catch (err: any) {
console.error('Retry payment error:', err);
} finally {
setIsProcessingPayment(false);
}
};
const getStatusLabel = (status: string) => {
switch (status) {
case 'delivered': return 'تحویل شده';
case 'shipped': return 'ارسال شده';
function getStatusIcon(st: string) {
switch (st) {
case 'processing':
return <Clock className="w-5 h-5 text-amber-500" />;
case 'packaged':
case 'ready_to_ship': return 'بسته‌بندی شده (آماده ارسال)';
case 'cancelled': return 'لغو شده';
case 'pending_payment': return 'در انتظار پرداخت / ناموفق';
case 'refunded': return 'مرجوع شده';
default: return 'در حال پردازش';
case 'ready_to_ship':
return <PackageCheck className="w-5 h-5 text-purple-500" />;
case 'shipped':
return <Truck className="w-5 h-5 text-blue-500" />;
case 'delivered':
return <CheckCircle2 className="w-5 h-5 text-green-500" />;
case 'pending_payment':
return <AlertCircle className="w-5 h-5 text-rose-500" />;
case 'cancelled':
return <XCircle className="w-5 h-5 text-red-500" />;
default:
return <Package className="w-5 h-5 text-medical-gray-400" />;
}
};
}
function getStatusLabel(st: string) {
switch (st) {
case 'processing':
return 'در حال پردازش در انبار';
case 'packaged':
case 'ready_to_ship':
return 'بسته‌بندی شده (آماده ارسال)';
case 'shipped':
return 'تحویل شرکت پست / پیک';
case 'delivered':
return 'تحویل موفق به مشتری';
case 'pending_payment':
return 'در انتظار پرداخت / ناموفق';
case 'cancelled':
return 'سفارش لغو شده';
default:
return 'ثبت اولیه';
}
}
return (
<AnimatePresence>
{isOpen && (
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4">
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
@@ -223,61 +322,102 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
onClick={onClose}
className="absolute inset-0 bg-medical-gray-900/60 backdrop-blur-md"
/>
<motion.div
initial={{ opacity: 0, scale: 0.9, y: 20 }}
initial={{ opacity: 0, scale: 0.95, y: 20 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
exit={{ opacity: 0, scale: 0.9, y: 20 }}
className="bg-white w-full max-w-2xl rounded-[3.5rem] relative z-10 shadow-2xl overflow-hidden font-vazir text-right"
exit={{ opacity: 0, scale: 0.95, y: 20 }}
className="bg-white w-full max-w-3xl rounded-[2.5rem] relative z-10 shadow-2xl overflow-hidden font-vazir text-right"
dir="rtl"
>
{/* Header */}
<div className="bg-medical-gray-50 px-8 sm:px-10 py-6 sm:py-8 flex items-center justify-between border-b border-medical-gray-100">
{/* Modal Header */}
<div className="p-6 sm:p-8 bg-medical-gray-50/80 border-b border-medical-gray-100 flex items-center justify-between">
<div className="flex items-center gap-4">
<div className="w-12 h-12 sm:w-14 sm:h-14 bg-canina-blue rounded-2xl flex items-center justify-center text-white shadow-lg">
<Package className="w-6 h-6 sm:w-7 sm:h-7" />
<div className="w-12 h-12 bg-canina-blue/10 rounded-2xl flex items-center justify-center text-canina-blue">
<Package className="w-6 h-6" />
</div>
<div>
<h3 className="text-lg sm:text-xl font-black text-medical-gray-900 italic">سفارش {toPersian(displayTrackingCode)}</h3>
<p className="text-xs font-bold text-medical-gray-400">ثبت شده در {toPersian(formattedDate)} - ساعت {toPersian(formattedTime)}</p>
<h3 className="text-xl font-black text-medical-gray-900">
جزئیات کامل سفارش {toPersian(displayTrackingCode)}
</h3>
<p className="text-xs text-medical-gray-400 font-bold mt-0.5">
ثبت شده در تاریخ {toPersian(formattedDate)}
</p>
</div>
</div>
<button
onClick={onClose}
className="w-10 h-10 flex items-center justify-center rounded-xl bg-white border border-medical-gray-200 text-medical-gray-400 hover:text-red-500 transition-all"
className="w-10 h-10 rounded-xl bg-white border border-medical-gray-200 text-medical-gray-400 hover:text-medical-gray-700 flex items-center justify-center transition-colors"
>
<X className="w-5 h-5" />
</button>
</div>
{/* Pending Payment Notice Banner */}
{isPendingPayment && (
<div className="bg-rose-50 border-b border-rose-200 px-6 py-4 flex flex-col sm:flex-row sm:items-center justify-between gap-3">
<div className="flex items-center gap-3">
<AlertCircle className="w-5 h-5 text-rose-600 shrink-0" />
<div>
<span className="text-xs font-black text-rose-900 block">
پرداخت این سفارش هنوز تکمیل نشده است.
</span>
<span className="text-[11px] text-rose-700 font-medium">
می‌توانید همین حالا روش پرداخت را تغییر داده یا مجدداً پرداخت را انجام دهید.
</span>
</div>
</div>
<button
onClick={() => setRetryModalOpen(true)}
className="px-4 py-2 bg-rose-600 hover:bg-rose-700 text-white rounded-xl text-xs font-black transition-all shadow-md shadow-rose-600/20 whitespace-nowrap shrink-0 flex items-center justify-center gap-1.5"
>
<CreditCard className="w-4 h-4" />
<span>پرداخت و تکمیل سفارش</span>
</button>
</div>
)}
{/* Content Scrollable */}
<div className="max-h-[70vh] overflow-y-auto px-8 sm:px-10 py-8 space-y-8 custom-scrollbar">
<div className="max-h-[60vh] overflow-y-auto px-6 sm:px-10 py-6 space-y-6 custom-scrollbar">
{/* Summary Stats */}
<div className="grid grid-cols-3 gap-3 sm:gap-4">
<div className="bg-medical-gray-50 p-4 rounded-2xl">
<div className="text-[9px] font-black text-medical-gray-400 uppercase tracking-widest mb-1">وضعیت تحویل</div>
<div className="text-[9px] font-black text-medical-gray-400 uppercase tracking-widest mb-1">
وضعیت سفارش
</div>
<div className="flex items-center gap-2">
{getStatusIcon(String(order.status || ''))}
<span className="text-xs sm:text-sm font-black text-medical-gray-900">{getStatusLabel(String(order.status || ''))}</span>
{getStatusIcon(orderStatus)}
<span className="text-xs sm:text-sm font-black text-medical-gray-900">
{getStatusLabel(orderStatus)}
</span>
</div>
</div>
<div className="bg-medical-gray-50 p-4 rounded-2xl">
<div className="text-[9px] font-black text-medical-gray-400 uppercase tracking-widest mb-1">کد پیگیری</div>
<div className="text-xs sm:text-sm font-mono font-bold text-canina-blue">{toPersian(displayTrackingCode)}</div>
<div className="text-[9px] font-black text-medical-gray-400 uppercase tracking-widest mb-1">
کد پیگیری
</div>
<div className="text-xs sm:text-sm font-bold text-canina-blue font-vazir">
{toPersian(displayTrackingCode)}
</div>
</div>
<div className="bg-medical-gray-50 p-4 rounded-2xl">
<div className="text-[9px] font-black text-medical-gray-400 uppercase tracking-widest mb-1">زمان دقیق</div>
<div className="text-[9px] font-black text-medical-gray-400 uppercase tracking-widest mb-1">
زمان دقیق
</div>
<div className="flex items-center gap-1.5">
<Clock className="w-4 h-4 text-medical-gray-400 flex-shrink-0" />
<span className="text-xs sm:text-sm font-black text-medical-gray-900">{toPersian(formattedTime)}</span>
<span className="text-xs sm:text-sm font-black text-medical-gray-900">
{toPersian(formattedTime)}
</span>
</div>
</div>
</div>
{/* Items List */}
<div>
<h4 className="text-sm font-black text-medical-gray-900 mb-4 flex items-center gap-2">
<h4 className="text-sm font-black text-medical-gray-900 mb-3 flex items-center gap-2">
<ShoppingBag className="w-4 h-4 text-canina-blue" />
سبد محصولات خریده شده
سبد اقلام سفارش
</h4>
<div className="space-y-3">
{items.map((item: Record<string, unknown>, idx: number) => {
@@ -287,7 +427,10 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
const pPrice = Number(prod?.priceValue || item.priceValue || 0);
const itemQty = Number(item.quantity || 1);
return (
<div key={String(prod?.id || idx)} className="flex items-center justify-between p-4 border border-medical-gray-100 rounded-2xl hover:border-canina-blue transition-all">
<div
key={String(prod?.id || idx)}
className="flex items-center justify-between p-4 border border-medical-gray-100 rounded-2xl hover:border-canina-blue transition-all"
>
<div className="flex items-center gap-4">
<div className="w-14 h-14 bg-medical-gray-50 rounded-xl p-1.5 flex items-center justify-center shrink-0 border border-medical-gray-200">
<img
@@ -297,11 +440,15 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
/>
</div>
<div>
<h5 className="font-black text-medical-gray-900 text-sm">{pName}</h5>
<p className="text-xs text-medical-gray-400">{toPersian(itemQty)} عدد × {toPersian(pPrice.toLocaleString())} تومان</p>
<h5 className="font-black text-medical-gray-900 text-xs sm:text-sm">
{pName}
</h5>
<p className="text-xs text-medical-gray-400 mt-0.5">
{toPersian(itemQty)} عدد × {toPersian(pPrice.toLocaleString())} تومان
</p>
</div>
</div>
<div className="text-left font-black text-canina-blue text-sm">
<div className="text-left font-black text-canina-blue text-xs sm:text-sm">
{toPersian((pPrice * itemQty).toLocaleString())} تومان
</div>
</div>
@@ -311,14 +458,14 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
</div>
{/* Shipping & Payment */}
<div className="grid md:grid-cols-2 gap-6 pt-6 border-t border-medical-gray-100">
<div className="grid md:grid-cols-2 gap-6 pt-4 border-t border-medical-gray-100">
<div>
<h4 className="text-sm font-black text-medical-gray-900 mb-3 flex items-center gap-2">
<MapPin className="w-4 h-4 text-canina-blue" />
اطلاعات ارسال
</h4>
<p className="text-xs font-bold text-medical-gray-600 leading-relaxed bg-medical-gray-50 p-4 rounded-2xl border border-medical-gray-100">
{String(order.shippingAddress || "آدرس ثبتی کاربر در حساب کاربری")}
{String(order.shippingAddress || 'آدرس ثبتی کاربر در حساب کاربری')}
</p>
</div>
<div>
@@ -329,18 +476,14 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
<div className="space-y-2 bg-medical-gray-50 p-4 rounded-2xl border border-medical-gray-100">
<div className="flex justify-between text-xs font-bold text-medical-gray-500">
<span>روش پرداخت:</span>
<span className="text-medical-gray-900 font-black">{paymentMethodText}</span>
<span className="text-medical-gray-900 font-black">
{getPaymentMethodTitle(order.paymentMethod)}
</span>
</div>
<div className="flex justify-between text-xs font-bold text-medical-gray-500">
<span>مجموع اولیه اقلام:</span>
<span>{toPersian(itemsSubtotal.toLocaleString())} تومان</span>
</div>
{isRefill && (
<div className="flex justify-between text-xs font-bold text-green-600 bg-green-50 p-2 rounded-xl border border-green-100">
<span>رزرو هوشمند تمدید (۵٪ پاداش خرید بعدی):</span>
<span>فعال ({toPersian(Math.round(itemsSubtotal * 0.05).toLocaleString())} تومان)</span>
</div>
)}
{charityAmount > 0 && (
<div className="flex justify-between text-xs font-bold text-pink-500">
<span>کمک اهدایی (ردپای مهربانی):</span>
@@ -351,9 +494,11 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
<span>هزینه ارسال:</span>
<span className="text-green-600 font-black">رایگان</span>
</div>
<div className="flex justify-between text-sm sm:text-base font-black text-medical-gray-900 pt-2 border-t border-medical-gray-200 italic">
<span>مبلغ نهایی پرداخت شده:</span>
<span className="text-canina-blue">{toPersian(totalAmount.toLocaleString())} تومان</span>
<div className="flex justify-between text-sm sm:text-base font-black text-medical-gray-900 pt-2 border-t border-medical-gray-200">
<span>مبلغ نهایی سفارش:</span>
<span className="text-canina-blue">
{toPersian(totalAmount.toLocaleString())} تومان
</span>
</div>
</div>
</div>
@@ -361,16 +506,182 @@ export default function OrderDetailsModal({ isOpen, onClose, order }: OrderDetai
</div>
{/* Footer Actions */}
<div className="p-6 sm:p-8 bg-medical-gray-50 border-t border-medical-gray-100 flex gap-4">
<div className="p-6 sm:p-8 bg-medical-gray-50 border-t border-medical-gray-100 flex flex-col sm:flex-row gap-3">
{isPendingPayment && (
<button
onClick={() => setRetryModalOpen(true)}
className="flex-1 py-3.5 bg-emerald-600 hover:bg-emerald-700 text-white rounded-2xl font-black text-xs sm:text-sm flex items-center justify-center gap-2 shadow-lg shadow-emerald-600/20 transition-all"
>
<CreditCard className="w-4 h-4" />
<span>پرداخت آنلاین و تکمیل سفارش</span>
</button>
)}
<button
onClick={handlePrint}
className="flex-1 py-4 bg-canina-blue text-white rounded-2xl font-black text-sm flex items-center justify-center gap-3 hover:bg-medical-gray-900 transition-all shadow-lg shadow-canina-blue/20"
className="flex-1 py-3.5 bg-canina-blue hover:bg-medical-gray-900 text-white rounded-2xl font-black text-xs sm:text-sm flex items-center justify-center gap-2 transition-all shadow-md"
>
<Download className="w-5 h-5" />
دانلود و چاپ فاکتور رسمی کنینا
<Download className="w-4 h-4" />
<span>دانلود و چاپ فاکتور رسمی</span>
</button>
</div>
</motion.div>
{/* Retry Payment Method Selector Modal */}
{retryModalOpen && (
<div className="fixed inset-0 z-60 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm">
<div className="bg-white rounded-3xl p-6 sm:p-8 w-full max-w-md shadow-2xl space-y-6 font-vazir animate-in fade-in zoom-in-95 duration-150" dir="rtl">
<div className="flex items-center justify-between border-b border-medical-gray-100 pb-4">
<div className="flex items-center gap-2">
<CreditCard className="w-5 h-5 text-canina-blue" />
<h3 className="text-base font-black text-medical-gray-900">
انتخاب روش پرداخت سفارش
</h3>
</div>
<button
onClick={() => setRetryModalOpen(false)}
className="p-1 text-medical-gray-400 hover:text-medical-gray-600 rounded-lg hover:bg-medical-gray-100"
>
✕
</button>
</div>
<div className="p-3.5 bg-canina-blue/5 border border-canina-blue/10 rounded-2xl flex justify-between items-center text-xs">
<span className="font-bold text-medical-gray-600">مبلغ قابل پرداخت:</span>
<span className="font-black text-canina-blue text-sm">
{toPersian(totalAmount.toLocaleString())} تومان
</span>
</div>
{/* Methods Options */}
<div className="space-y-3">
<label
onClick={() => setSelectedMethod('online')}
className={`flex items-center justify-between p-4 rounded-2xl border-2 cursor-pointer transition-all ${
selectedMethod === 'online'
? 'border-canina-blue bg-canina-blue/5'
: 'border-medical-gray-100 hover:border-medical-gray-200'
}`}
>
<div className="flex items-center gap-3">
<div className="w-10 h-10 bg-emerald-50 text-emerald-600 rounded-xl flex items-center justify-center font-bold">
<CreditCard className="w-5 h-5" />
</div>
<div>
<div className="text-xs font-black text-medical-gray-900">
درگاه پرداخت آنلاین زیبال
</div>
<div className="text-[10px] text-medical-gray-400 font-bold mt-0.5">
پرداخت آنی با تمامی کارت‌های بانکی عضو شتاب
</div>
</div>
</div>
<div
className={`w-5 h-5 rounded-full border-2 flex items-center justify-center ${
selectedMethod === 'online'
? 'border-canina-blue bg-canina-blue'
: 'border-medical-gray-300'
}`}
>
{selectedMethod === 'online' && (
<span className="w-2 h-2 rounded-full bg-white" />
)}
</div>
</label>
<label
onClick={() => setSelectedMethod('wallet')}
className={`flex items-center justify-between p-4 rounded-2xl border-2 cursor-pointer transition-all ${
selectedMethod === 'wallet'
? 'border-canina-blue bg-canina-blue/5'
: 'border-medical-gray-100 hover:border-medical-gray-200'
}`}
>
<div className="flex items-center gap-3">
<div className="w-10 h-10 bg-purple-50 text-purple-600 rounded-xl flex items-center justify-center font-bold">
<Wallet className="w-5 h-5" />
</div>
<div>
<div className="text-xs font-black text-medical-gray-900">
کیف پول الکترونیک کنینا
</div>
<div className="text-[10px] text-medical-gray-400 font-bold mt-0.5">
کسر خودکار از موجودی کیف پول
</div>
</div>
</div>
<div
className={`w-5 h-5 rounded-full border-2 flex items-center justify-center ${
selectedMethod === 'wallet'
? 'border-canina-blue bg-canina-blue'
: 'border-medical-gray-300'
}`}
>
{selectedMethod === 'wallet' && (
<span className="w-2 h-2 rounded-full bg-white" />
)}
</div>
</label>
<label
onClick={() => setSelectedMethod('card')}
className={`flex items-center justify-between p-4 rounded-2xl border-2 cursor-pointer transition-all ${
selectedMethod === 'card'
? 'border-canina-blue bg-canina-blue/5'
: 'border-medical-gray-100 hover:border-medical-gray-200'
}`}
>
<div className="flex items-center gap-3">
<div className="w-10 h-10 bg-blue-50 text-blue-600 rounded-xl flex items-center justify-center font-bold">
<Building2 className="w-5 h-5" />
</div>
<div>
<div className="text-xs font-black text-medical-gray-900">
کارت به کارت مستقیم
</div>
<div className="text-[10px] text-medical-gray-400 font-bold mt-0.5">
واریز به شماره کارت / شبا شرکت
</div>
</div>
</div>
<div
className={`w-5 h-5 rounded-full border-2 flex items-center justify-center ${
selectedMethod === 'card'
? 'border-canina-blue bg-canina-blue'
: 'border-medical-gray-300'
}`}
>
{selectedMethod === 'card' && (
<span className="w-2 h-2 rounded-full bg-white" />
)}
</div>
</label>
</div>
<div className="flex items-center justify-end gap-3 pt-2">
<button
type="button"
onClick={() => setRetryModalOpen(false)}
className="px-4 py-2.5 text-xs font-bold text-medical-gray-600 hover:bg-medical-gray-100 rounded-xl transition-all"
>
انصراف
</button>
<button
type="button"
disabled={isProcessingPayment}
onClick={handleExecuteRetryPayment}
className="px-6 py-2.5 text-xs font-black bg-canina-blue hover:bg-canina-dark text-white rounded-xl shadow-lg shadow-canina-blue/20 transition-all flex items-center gap-2"
>
{isProcessingPayment ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<CheckCircle2 className="w-4 h-4" />
)}
<span>تایید و ادامه پرداخت</span>
</button>
</div>
</div>
</div>
)}
</div>
)}
</AnimatePresence>
+124 -80
View File
@@ -26,7 +26,8 @@ import {
ShoppingBag,
Thermometer,
AlertTriangle,
Share2
Share2,
Phone
} from "lucide-react";
const ICON_MAP: Record<string, React.ComponentType<{ className?: string }>> = {
@@ -65,6 +66,7 @@ const useCalculatorStore = create<CalculatorState>((set) => ({
import Tooltip from "./Tooltip";
import SafeImage from "./SafeImage";
import ProductReviews from "./ProductReviews";
import { useRouter } from 'next/navigation';
@@ -111,6 +113,12 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
const activePet = getActivePet();
const { petType, weight, setPetType, setWeight } = useCalculatorStore();
const { addItem } = useCartStore();
const getText = useSettingsStore((state) => state.getText);
const isCatalogMode = getText('catalog_mode', 'false') === 'true';
const isCatalogHidePrices = getText('catalog_hide_prices', 'false') === 'true';
const isCatalogDisableCart = getText('catalog_disable_cart', 'false') === 'true';
const isCartDisabled = isCatalogMode || isCatalogDisableCart;
const scientificTerms = useSettingsStore(state => state.scientificTerms);
const termKeys = useMemo(() => {
return Array.from(new Set([
@@ -663,6 +671,13 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
</div>
</section>
)}
{/* Customer Reviews & Ratings Section */}
{product && (
<div className="pt-8">
<ProductReviews productId={product.id} productName={product.name} />
</div>
)}
</div>
{/* Sticky Sidebar (Clean Buy Box) - Hidden on mobile as mobile floating buy bar is active */}
@@ -671,63 +686,78 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
<div className="absolute top-0 right-0 w-24 h-24 bg-canina-blue/5 rounded-full -mr-12 -mt-12" />
<div className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest mb-1 font-vazir">قیمت نهایی محصول</div>
<div className="text-4xl font-black font-vazir text-medical-gray-900 tracking-tighter mb-8">
{toPersian(product.price)}
<div className="text-3xl sm:text-4xl font-black font-vazir text-medical-gray-900 tracking-tighter mb-8">
{isCatalogHidePrices ? "استعلام قیمت" : toPersian(product.price)}
</div>
<div className="flex gap-4 mb-6">
{/* Quantity Selector - 40% Width */}
<div className="flex items-center gap-4 bg-medical-gray-50 border border-medical-gray-100 rounded-2xl p-2 h-16 w-[40%]">
<button
onClick={() => setItemQuantity(Math.max(1, itemQuantity - 1))}
className="w-10 h-10 flex items-center justify-center rounded-xl bg-white text-medical-gray-900 border border-medical-gray-200 hover:bg-canina-blue hover:text-white hover:border-canina-blue transition-all shadow-sm"
{isCartDisabled ? (
<div className="space-y-3">
<a
href="tel:02188888888"
className="w-full flex items-center justify-center gap-2 px-4 bg-canina-blue text-white rounded-2xl h-16 font-black text-sm hover:bg-canina-dark transition-all shadow-xl shadow-canina-blue/20 font-vazir"
>
<Minus className="w-4 h-4" />
</button>
<span className="text-xl font-black text-medical-gray-900 flex-1 text-center font-vazir">
{toPersian(itemQuantity)}
</span>
<button
onClick={() => setItemQuantity(itemQuantity + 1)}
className="w-10 h-10 flex items-center justify-center rounded-xl bg-white text-medical-gray-900 border border-medical-gray-200 hover:bg-canina-blue hover:text-white hover:border-canina-blue transition-all shadow-sm"
>
<Plus className="w-4 h-4" />
</button>
<Phone className="w-5 h-5" />
<span>مشاوره و استعلام خرید</span>
</a>
<p className="text-[11px] text-medical-gray-400 font-bold text-center">
خرید آنلاین در حالت کاتالوگ موقتاً غیرفعال است
</p>
</div>
) : (
<div className="flex gap-4 mb-6">
{/* Quantity Selector - 40% Width */}
<div className="flex items-center gap-4 bg-medical-gray-50 border border-medical-gray-100 rounded-2xl p-2 h-16 w-[40%]">
<button
onClick={() => setItemQuantity(Math.max(1, itemQuantity - 1))}
className="w-10 h-10 flex items-center justify-center rounded-xl bg-white text-medical-gray-900 border border-medical-gray-200 hover:bg-canina-blue hover:text-white hover:border-canina-blue transition-all shadow-sm"
>
<Minus className="w-4 h-4" />
</button>
<span className="text-xl font-black text-medical-gray-900 flex-1 text-center font-vazir">
{toPersian(itemQuantity)}
</span>
<button
onClick={() => setItemQuantity(itemQuantity + 1)}
className="w-10 h-10 flex items-center justify-center rounded-xl bg-white text-medical-gray-900 border border-medical-gray-200 hover:bg-canina-blue hover:text-white hover:border-canina-blue transition-all shadow-sm"
>
<Plus className="w-4 h-4" />
</button>
</div>
{/* Add to Cart / Preorder / Stock Notify Button - 60% Width */}
{(product as unknown as { isPreorder?: boolean; preorderDeposit?: number }).isPreorder ? (
<button
onClick={() => {
addItem(product, itemQuantity, { quantity: calculation.dailyDose, unit: calculation.unit });
toast.success(`پیش‌خرید ${toPersian(itemQuantity)} عدد ${product.name} به سبد شما اضافه شد`);
}}
className="w-[60%] flex items-center justify-center gap-1.5 px-4 bg-purple-700 text-white rounded-2xl h-16 font-black text-sm hover:bg-purple-800 transition-all shadow-xl shadow-purple-900/20 font-vazir whitespace-nowrap"
>
<Sparkles className="w-5 h-5 mb-1 text-amber-300" />
{((product as unknown as { preorderDeposit?: number }).preorderDeposit || 0) > 0 ? `پیش‌خرید (بیعانه: ${((product as unknown as { preorderDeposit?: number }).preorderDeposit || 0).toLocaleString('fa-IR')} تومان)` : 'ثبت پیش‌خرید (رایگان)'}
</button>
) : (product.packageSize || 0) <= 0 ? (
<button
onClick={() => toast.info("درخواست اطلاع‌رسانی موجودی ثبت شد")}
className="w-[60%] flex items-center justify-center gap-1.5 px-4 bg-amber-500 text-white rounded-2xl h-16 font-black text-sm hover:bg-amber-600 transition-all shadow-xl shadow-amber-500/20 font-vazir whitespace-nowrap"
>
<Bell className="w-5 h-5 mb-1" />
موجود شد اطلاع بده
</button>
) : (
<button
onClick={() => {
addItem(product, itemQuantity, { quantity: calculation.dailyDose, unit: calculation.unit });
toast.success(`${toPersian(itemQuantity)} عدد ${product.name} به سبد خرید اضافه شد`);
}}
className="w-[60%] flex items-center justify-center gap-1.5 px-4 bg-medical-gray-900 text-white rounded-2xl h-16 font-black text-sm hover:bg-canina-blue transition-all shadow-xl shadow-black/10 font-vazir whitespace-nowrap"
>
<ShoppingBag className="w-5 h-5 mb-1" />
افزودن به سبد خرید
</button>
)}
</div>
{/* Add to Cart / Preorder / Stock Notify Button - 60% Width */}
{(product as unknown as { isPreorder?: boolean; preorderDeposit?: number }).isPreorder ? (
<button
onClick={() => {
addItem(product, itemQuantity, { quantity: calculation.dailyDose, unit: calculation.unit });
toast.success(`پیش‌خرید ${toPersian(itemQuantity)} عدد ${product.name} به سبد شما اضافه شد`);
}}
className="w-[60%] flex items-center justify-center gap-1.5 px-4 bg-purple-700 text-white rounded-2xl h-16 font-black text-sm hover:bg-purple-800 transition-all shadow-xl shadow-purple-900/20 font-vazir whitespace-nowrap"
>
<Sparkles className="w-5 h-5 mb-1 text-amber-300" />
{((product as unknown as { preorderDeposit?: number }).preorderDeposit || 0) > 0 ? `پیش‌خرید (بیعانه: ${((product as unknown as { preorderDeposit?: number }).preorderDeposit || 0).toLocaleString('fa-IR')} تومان)` : 'ثبت پیش‌خرید (رایگان)'}
</button>
) : (product.packageSize || 0) <= 0 ? (
<button
onClick={() => toast.info("درخواست اطلاع‌رسانی موجودی ثبت شد")}
className="w-[60%] flex items-center justify-center gap-1.5 px-4 bg-amber-500 text-white rounded-2xl h-16 font-black text-sm hover:bg-amber-600 transition-all shadow-xl shadow-amber-500/20 font-vazir whitespace-nowrap"
>
<Bell className="w-5 h-5 mb-1" />
موجود شد اطلاع بده
</button>
) : (
<button
onClick={() => {
addItem(product, itemQuantity, { quantity: calculation.dailyDose, unit: calculation.unit });
toast.success(`${toPersian(itemQuantity)} عدد ${product.name} به سبد خرید اضافه شد`);
}}
className="w-[60%] flex items-center justify-center gap-1.5 px-4 bg-medical-gray-900 text-white rounded-2xl h-16 font-black text-sm hover:bg-canina-blue transition-all shadow-xl shadow-black/10 font-vazir whitespace-nowrap"
>
<ShoppingBag className="w-5 h-5 mb-1" />
افزودن به سبد خرید
</button>
)}
</div>
)}
<div className="mt-6 flex flex-col gap-3 border-t border-medical-gray-50 pt-6">
<div className="flex items-center gap-2 text-xs font-bold text-medical-gray-500 font-vazir">
@@ -878,38 +908,52 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
<div className="lg:hidden fixed bottom-0 left-0 right-0 z-40 bg-white border-t border-medical-gray-200 p-3 shadow-2xl flex items-center justify-between gap-3 font-vazir" dir="rtl">
<div>
<span className="text-[10px] text-medical-gray-400 font-bold block">قیمت نهایی</span>
<span className="text-lg font-black text-medical-gray-900 font-vazir">{toPersian(product.price)}</span>
<span className="text-base sm:text-lg font-black text-medical-gray-900 font-vazir">
{isCatalogHidePrices ? "استعلام قیمت" : toPersian(product.price)}
</span>
</div>
<div className="flex items-center gap-2 flex-1 max-w-[240px]">
<div className="flex items-center gap-1 bg-medical-gray-50 border border-medical-gray-200 rounded-xl p-1 h-11">
<button
onClick={() => setItemQuantity(Math.max(1, itemQuantity - 1))}
className="w-7 h-7 flex items-center justify-center rounded-lg bg-white text-medical-gray-900 border border-medical-gray-200 font-bold text-xs"
{isCartDisabled ? (
<a
href="tel:02188888888"
className="flex-1 bg-canina-blue text-white py-2.5 px-3 rounded-xl font-black text-xs hover:bg-canina-dark transition-all flex items-center justify-center gap-1.5 shadow-md shadow-canina-blue/20 whitespace-nowrap"
>
-
</button>
<span className="w-5 text-center font-black text-medical-gray-900 text-xs font-vazir">
{toPersian(itemQuantity)}
</span>
<button
onClick={() => setItemQuantity(itemQuantity + 1)}
className="w-7 h-7 flex items-center justify-center rounded-lg bg-white text-medical-gray-900 border border-medical-gray-200 font-bold text-xs"
>
+
</button>
</div>
<Phone className="w-4 h-4" />
استعلام و مشاوره
</a>
) : (
<>
<div className="flex items-center gap-1 bg-medical-gray-50 border border-medical-gray-200 rounded-xl p-1 h-11">
<button
onClick={() => setItemQuantity(Math.max(1, itemQuantity - 1))}
className="w-7 h-7 flex items-center justify-center rounded-lg bg-white text-medical-gray-900 border border-medical-gray-200 font-bold text-xs"
>
-
</button>
<span className="w-5 text-center font-black text-medical-gray-900 text-xs font-vazir">
{toPersian(itemQuantity)}
</span>
<button
onClick={() => setItemQuantity(itemQuantity + 1)}
className="w-7 h-7 flex items-center justify-center rounded-lg bg-white text-medical-gray-900 border border-medical-gray-200 font-bold text-xs"
>
+
</button>
</div>
<button
onClick={() => {
addItem(product, itemQuantity, { quantity: calculation.dailyDose, unit: calculation.unit });
toast.success(`${toPersian(itemQuantity)} عدد به سبد خرید اضافه شد`);
}}
className="flex-1 bg-canina-blue text-white py-2.5 px-3 rounded-xl font-black text-xs hover:bg-canina-dark transition-all flex items-center justify-center gap-1.5 shadow-md shadow-canina-blue/20 whitespace-nowrap"
>
<ShoppingBag className="w-4 h-4" />
افزودن به سبد
</button>
<button
onClick={() => {
addItem(product, itemQuantity, { quantity: calculation.dailyDose, unit: calculation.unit });
toast.success(`${toPersian(itemQuantity)} عدد به سبد خرید اضافه شد`);
}}
className="flex-1 bg-canina-blue text-white py-2.5 px-3 rounded-xl font-black text-xs hover:bg-canina-dark transition-all flex items-center justify-center gap-1.5 shadow-md shadow-canina-blue/20 whitespace-nowrap"
>
<ShoppingBag className="w-4 h-4" />
افزودن به سبد
</button>
</>
)}
</div>
</div>
</div>
@@ -0,0 +1,382 @@
"use client";
import React, { useState, useEffect, useCallback } from "react";
import {
Star,
MessageSquare,
CheckCircle2,
Reply,
Loader2,
ChevronLeft,
ChevronRight,
Send,
User,
ShieldCheck,
} from "lucide-react";
import { toast } from "sonner";
import api from "../lib/services/api";
import { toPersian } from "../lib/utils";
interface ReviewItem {
id: string;
userName: string;
rating: number;
comment: string;
adminReply?: string;
createdAt: string;
}
interface ProductReviewsProps {
productId: string;
productName: string;
}
export default function ProductReviews({ productId, productName }: ProductReviewsProps) {
const [reviews, setReviews] = useState<ReviewItem[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [page, setPage] = useState(1);
const [totalPages, setTotalPages] = useState(1);
const [stats, setStats] = useState({ averageRating: 5, totalReviews: 0 });
// Submission Form State
const [isSubmitting, setIsSubmitting] = useState(false);
const [rating, setRating] = useState(5);
const [hoverRating, setHoverRating] = useState(0);
const [comment, setComment] = useState("");
const [userName, setUserName] = useState("");
const [userPhone, setUserPhone] = useState("");
const [formOpen, setFormOpen] = useState(false);
const fetchReviews = useCallback(async () => {
if (!productId) return;
try {
setIsLoading(true);
const res = await api.get(`/products/${productId}/reviews?page=${page}&limit=5`);
if (res.data?.success) {
setReviews(res.data.data || []);
setTotalPages(res.data.pagination?.totalPages || 1);
if (res.data.stats) {
setStats(res.data.stats);
}
}
} catch (err: any) {
console.error("Failed to fetch product reviews:", err);
} finally {
setIsLoading(false);
}
}, [productId, page]);
useEffect(() => {
fetchReviews();
}, [fetchReviews]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!comment.trim()) {
toast.error("لطفاً متن نظر خود را وارد نمایید.");
return;
}
try {
setIsSubmitting(true);
const res = await api.post(`/products/${productId}/reviews`, {
rating,
comment: comment.trim(),
userName: userName.trim() || undefined,
userPhone: userPhone.trim() || undefined,
});
if (res.data?.success) {
toast.success(
res.data.message || "دیدگاه شما با موفقیت ثبت شد و پس از تایید کارشناسان منتشر خواهد شد."
);
setComment("");
setFormOpen(false);
}
} catch (err: any) {
console.error("Failed to submit review:", err);
} finally {
setIsSubmitting(false);
}
};
return (
<section className="bg-white border border-medical-gray-200 rounded-[2.5rem] p-6 sm:p-10 shadow-md space-y-8 font-vazir text-right" dir="rtl">
{/* Header & Rating Summary */}
<div className="flex flex-col md:flex-row md:items-center justify-between gap-6 pb-6 border-b border-medical-gray-100">
<div className="space-y-2">
<div className="flex items-center gap-3">
<div className="w-12 h-12 bg-canina-gold/10 text-canina-gold rounded-2xl flex items-center justify-center shadow-xs">
<Star className="w-6 h-6 fill-canina-gold" />
</div>
<div>
<h3 className="text-xl sm:text-2xl font-black text-medical-gray-900">
نظرات و تجربیات خریداران
</h3>
<p className="text-xs text-medical-gray-400 font-bold mt-0.5">
دیدگاه‌های ثبت‌شده درباره اثرگذاری مکمل {productName}
</p>
</div>
</div>
</div>
{/* Rating Score Badge & Add Review Button */}
<div className="flex flex-wrap items-center gap-4">
<div className="flex items-center gap-3 px-5 py-3 bg-medical-gray-50 border border-medical-gray-100 rounded-2xl">
<div className="flex items-center gap-1">
{Array.from({ length: 5 }).map((_, i) => (
<Star
key={i}
className={`w-4 h-4 ${
i < Math.round(stats.averageRating)
? "fill-amber-400 text-amber-400"
: "text-medical-gray-200"
}`}
/>
))}
</div>
<div className="text-sm font-black text-medical-gray-900">
{toPersian(stats.averageRating)} از ۵
</div>
<span className="text-xs text-medical-gray-400 font-bold border-r border-medical-gray-200 pr-2">
({toPersian(stats.totalReviews)} دیدگاه)
</span>
</div>
<button
onClick={() => setFormOpen(!formOpen)}
className="px-5 py-3 bg-canina-blue hover:bg-canina-dark text-white rounded-2xl text-xs font-black transition-all shadow-md shadow-canina-blue/20 flex items-center gap-2"
>
<MessageSquare className="w-4 h-4" />
<span>{formOpen ? "بستن فرم" : "ثبت دیدگاه جدید"}</span>
</button>
</div>
</div>
{/* Submission Form (Accordion / Collapsible) */}
{formOpen && (
<form
onSubmit={handleSubmit}
className="bg-medical-gray-50/80 border border-medical-gray-200 rounded-3xl p-6 sm:p-8 space-y-5 animate-in fade-in duration-200"
>
<div className="flex items-center justify-between border-b border-medical-gray-200 pb-3">
<h4 className="text-sm font-black text-medical-gray-900 flex items-center gap-2">
<Send className="w-4 h-4 text-canina-blue" />
ارسال نظر و امتیاز برای {productName}
</h4>
<span className="text-[11px] text-medical-gray-400 font-bold">
نظر شما پس از تایید مدیریت نمایش داده می‌شود
</span>
</div>
{/* Star Rating Selector */}
<div>
<label className="block text-xs font-black text-medical-gray-700 mb-2">
امتیاز شما به کیفیت و اثرگذاری محصول:
</label>
<div className="flex items-center gap-2">
{Array.from({ length: 5 }).map((_, i) => {
const starVal = i + 1;
const active = starVal <= (hoverRating || rating);
return (
<button
type="button"
key={i}
onMouseEnter={() => setHoverRating(starVal)}
onMouseLeave={() => setHoverRating(0)}
onClick={() => setRating(starVal)}
className="p-1 text-2xl transition-transform hover:scale-110"
>
<Star
className={`w-7 h-7 ${
active
? "fill-amber-400 text-amber-400"
: "text-medical-gray-300"
}`}
/>
</button>
);
})}
<span className="text-xs font-bold text-medical-gray-600 mr-2">
{toPersian(rating)} ستاره
</span>
</div>
</div>
{/* Name & Phone Inputs */}
<div className="grid sm:grid-cols-2 gap-4">
<div>
<label className="block text-xs font-black text-medical-gray-700 mb-1.5">
نام و نام خانوادگی (اختیاری):
</label>
<input
type="text"
value={userName}
onChange={(e) => setUserName(e.target.value)}
placeholder="مثلاً علی محمدی"
className="w-full px-4 py-2.5 bg-white border border-medical-gray-200 rounded-xl text-xs font-bold outline-none focus:ring-2 focus:ring-canina-blue/20"
/>
</div>
<div>
<label className="block text-xs font-black text-medical-gray-700 mb-1.5">
شماره موبایل (اختیاری - محرمانه):
</label>
<input
type="tel"
value={userPhone}
onChange={(e) => setUserPhone(e.target.value)}
placeholder="0912..."
className="w-full px-4 py-2.5 bg-white border border-medical-gray-200 rounded-xl text-xs font-bold outline-none focus:ring-2 focus:ring-canina-blue/20 font-mono"
dir="ltr"
/>
</div>
</div>
{/* Comment Textarea */}
<div>
<label className="block text-xs font-black text-medical-gray-700 mb-1.5">
متن دیدگاه یا تجربه مصرف: <span className="text-rose-500">*</span>
</label>
<textarea
required
rows={4}
value={comment}
onChange={(e) => setComment(e.target.value)}
placeholder="تجربه خود را از نحوه مصرف، تغییرات بالینی پت و اثربخشی این مکمل بنویسید..."
className="w-full p-4 bg-white border border-medical-gray-200 rounded-2xl text-xs sm:text-sm font-medium outline-none focus:ring-2 focus:ring-canina-blue/20 resize-none leading-relaxed"
/>
</div>
<div className="flex justify-end gap-3 pt-2">
<button
type="button"
onClick={() => setFormOpen(false)}
className="px-5 py-2.5 bg-medical-gray-200 hover:bg-medical-gray-300 text-medical-gray-700 rounded-xl text-xs font-bold transition-all"
>
انصراف
</button>
<button
type="submit"
disabled={isSubmitting}
className="px-6 py-2.5 bg-canina-blue hover:bg-canina-dark text-white rounded-xl text-xs font-black transition-all shadow-md flex items-center gap-2"
>
{isSubmitting ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<CheckCircle2 className="w-4 h-4" />
)}
<span>ثبت و ارسال دیدگاه</span>
</button>
</div>
</form>
)}
{/* Reviews List */}
<div className="space-y-4">
{isLoading ? (
<div className="py-12 text-center text-medical-gray-400 font-bold text-xs flex flex-col items-center gap-2">
<Loader2 className="w-6 h-6 animate-spin text-canina-blue" />
<span>در حال دریافت نظرات خریداران...</span>
</div>
) : reviews.length === 0 ? (
<div className="py-12 text-center bg-medical-gray-50/50 border border-dashed border-medical-gray-200 rounded-3xl">
<p className="text-sm font-bold text-medical-gray-500">
هنوز دیدگاهی برای این محصول ثبت نشده است.
</p>
<p className="text-xs text-medical-gray-400 font-medium mt-1">
اولین نفری باشید که تجربه خود را درباره این محصول به اشتراک می‌گذارید.
</p>
</div>
) : (
reviews.map((rev) => {
const date = new Date(rev.createdAt);
return (
<div
key={rev.id}
className="bg-medical-gray-50/60 border border-medical-gray-100 rounded-3xl p-5 sm:p-6 space-y-3 hover:bg-medical-gray-50 transition-colors"
>
<div className="flex flex-wrap items-center justify-between gap-3">
<div className="flex items-center gap-2.5">
<div className="w-9 h-9 bg-canina-blue/10 text-canina-blue rounded-xl flex items-center justify-center font-black text-xs">
<User className="w-4 h-4" />
</div>
<div>
<div className="text-xs sm:text-sm font-black text-medical-gray-900 flex items-center gap-2">
<span>{rev.userName}</span>
<span className="inline-flex items-center gap-1 text-[10px] font-bold text-emerald-600 bg-emerald-50 px-2 py-0.5 rounded-md border border-emerald-200">
<ShieldCheck className="w-3 h-3" />
خریدار تایید شده
</span>
</div>
<div className="text-[10px] text-medical-gray-400 font-bold mt-0.5">
{toPersian(date.toLocaleDateString("fa-IR"))}
</div>
</div>
</div>
{/* Stars */}
<div className="flex items-center gap-1">
{Array.from({ length: 5 }).map((_, i) => (
<Star
key={i}
className={`w-3.5 h-3.5 ${
i < rev.rating
? "fill-amber-400 text-amber-400"
: "text-medical-gray-200"
}`}
/>
))}
</div>
</div>
{/* Review Text */}
<p className="text-xs sm:text-sm text-medical-gray-700 font-medium leading-relaxed whitespace-pre-wrap pt-1">
{rev.comment}
</p>
{/* Admin Reply */}
{rev.adminReply && (
<div className="mt-3 p-3.5 bg-white border-r-3 border-canina-blue rounded-2xl text-xs space-y-1 shadow-xs">
<span className="font-black text-canina-blue flex items-center gap-1">
<Reply className="w-3.5 h-3.5 rotate-180" />
پاسخ کارشناس کنینا ایران:
</span>
<p className="text-medical-gray-600 font-medium leading-relaxed">
{rev.adminReply}
</p>
</div>
)}
</div>
);
})
)}
{/* Pagination Controls */}
{totalPages > 1 && (
<div className="flex items-center justify-between pt-4 border-t border-medical-gray-100">
<span className="text-xs font-bold text-medical-gray-400">
صفحه {toPersian(page)} از {toPersian(totalPages)}
</span>
<div className="flex items-center gap-2">
<button
disabled={page <= 1 || isLoading}
onClick={() => setPage((p) => Math.max(1, p - 1))}
className="px-3 py-1.5 border border-medical-gray-200 rounded-xl text-xs font-bold hover:bg-medical-gray-50 disabled:opacity-40 transition-all flex items-center gap-1"
>
<ChevronRight className="w-4 h-4" />
<span>قبلی</span>
</button>
<button
disabled={page >= totalPages || isLoading}
onClick={() => setPage((p) => Math.min(totalPages, p + 1))}
className="px-3 py-1.5 border border-medical-gray-200 rounded-xl text-xs font-bold hover:bg-medical-gray-50 disabled:opacity-40 transition-all flex items-center gap-1"
>
<span>بعدی</span>
<ChevronLeft className="w-4 h-4" />
</button>
</div>
</div>
)}
</div>
</section>
);
}
@@ -21,7 +21,7 @@ import { useRouter, useSearchParams } from 'next/navigation';
export default function UserDashboard() {
const router = useRouter();
const searchParams = useSearchParams();
const { profile, isLoggedIn, logout, updateProfile, addAddress, updateAddress, deleteAddress, setDefaultAddress, topUpWallet } = useUserStore();
const { profile, isLoggedIn, logout, updateProfile, addAddress, updateAddress, deleteAddress, setDefaultAddress, topUpWallet, fetchProfile } = useUserStore();
const { pets, activePetId, setActivePet, removePet } = usePetStore();
const isWithdrawalEnabled = useSettingsStore((s) => s.getBoolean('wallet_withdrawal_enabled', false));
@@ -1430,6 +1430,20 @@ export default function UserDashboard() {
</div>
</div>
)}
{/* Order Details & Retry Payment Modal */}
<OrderDetailsModal
isOpen={!!selectedOrder}
onClose={() => setSelectedOrder(null)}
order={selectedOrder}
onOrderUpdated={async () => {
try {
await fetchProfile();
} catch (e) {
console.error(e);
}
}}
/>
</div>
);
}