feat: complete settings sync, standard UI inputs, prescriptions flow, pet profile and checkout enhancements
Deploy Canina / deploy (push) Failing after 51s
Deploy Canina / deploy (push) Failing after 51s
This commit is contained in:
1 parent
b3c60a1a7d
commit
6df92f03d7
32 files changed
+61750
-59151
No files matched your search
@@ -33,7 +33,7 @@ import api from "../lib/services/api";
|
||||
export default function CheckoutPage() {
|
||||
const router = useRouter();
|
||||
const { items, getTotal, getSubtotal, isSubscribed, charityDonation, setCharityDonation, addOrder, clearCart } = useCartStore();
|
||||
const { getActivePet, updatePet } = usePetStore();
|
||||
const { pets, activePetId, getActivePet, updatePet } = usePetStore();
|
||||
const { profile, isLoggedIn } = useUserStore();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [useRoundUp, setUseRoundUp] = useState(false);
|
||||
@@ -41,6 +41,7 @@ export default function CheckoutPage() {
|
||||
const [showTopUpModal, setShowTopUpModal] = useState(false);
|
||||
const [showAddressModal, setShowAddressModal] = useState(false);
|
||||
|
||||
const [selectedPetId, setSelectedPetId] = useState<string | null>(activePetId || (pets[0]?.id ?? null));
|
||||
const [selectedAddressId, setSelectedAddressId] = useState<string>('');
|
||||
|
||||
// Custom manual address state if guest or not using stored addresses
|
||||
@@ -130,7 +131,7 @@ export default function CheckoutPage() {
|
||||
charityDonation: charityDonation,
|
||||
paymentMethod: paymentMethod,
|
||||
isRefill: isSubscribed,
|
||||
petId: activePet?.id,
|
||||
petId: selectedPetId || undefined,
|
||||
shippingAddress: shippingAddressStr
|
||||
});
|
||||
|
||||
@@ -442,6 +443,47 @@ export default function CheckoutPage() {
|
||||
)}
|
||||
</section>
|
||||
|
||||
{/* Pet Selection */}
|
||||
{pets.length > 0 && (
|
||||
<section className="bg-white rounded-[2rem] sm:rounded-[3rem] border border-medical-gray-200 p-5 sm:p-8 overflow-hidden relative">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-purple-100 text-purple-700 rounded-2xl flex items-center justify-center font-black">🐾</div>
|
||||
<div>
|
||||
<h2 className="text-lg font-black text-medical-gray-900 italic">انتخاب همدم (حیوان خانگی)</h2>
|
||||
<p className="text-xs text-medical-gray-500">برای ثبت سابقه خرید در پرونده سلامت پت، همدم موردنظر را انتخاب کنید:</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSelectedPetId(null)}
|
||||
className={cn(
|
||||
"p-3 rounded-2xl border-2 text-xs font-black transition-all flex items-center justify-center gap-2 cursor-pointer",
|
||||
selectedPetId === null ? "border-canina-blue bg-canina-blue/10 text-canina-blue shadow-xs" : "border-medical-gray-100 text-medical-gray-500 hover:bg-medical-gray-50"
|
||||
)}
|
||||
>
|
||||
<span>هیچکدام (خرید عمومی)</span>
|
||||
</button>
|
||||
{pets.map(p => (
|
||||
<button
|
||||
key={p.id}
|
||||
type="button"
|
||||
onClick={() => setSelectedPetId(p.id)}
|
||||
className={cn(
|
||||
"p-3 rounded-2xl border-2 text-xs font-black transition-all flex items-center justify-center gap-2 cursor-pointer",
|
||||
selectedPetId === p.id ? "border-canina-blue bg-canina-blue/10 text-canina-blue shadow-xs" : "border-medical-gray-100 text-medical-gray-600 hover:bg-medical-gray-50"
|
||||
)}
|
||||
>
|
||||
<span>🐾 {p.name} ({p.breed || p.type})</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{/* Step 2: Payment */}
|
||||
<section className="bg-white rounded-[2rem] sm:rounded-[3rem] border border-medical-gray-200 p-5 sm:p-10 overflow-hidden relative">
|
||||
<div className="absolute top-0 right-0 w-2.5 sm:w-3 h-full bg-medical-gray-900 opacity-20" />
|
||||
|
||||
@@ -84,6 +84,32 @@ export default function Hero({ banners = [], onShopNavigate }: { banners?: Banne
|
||||
}
|
||||
};
|
||||
|
||||
const touchStartX = useRef<number | null>(null);
|
||||
const touchEndX = useRef<number | null>(null);
|
||||
const minSwipeDistance = 40;
|
||||
|
||||
const onTouchStart = (e: React.TouchEvent) => {
|
||||
touchEndX.current = null;
|
||||
touchStartX.current = e.targetTouches[0].clientX;
|
||||
};
|
||||
|
||||
const onTouchMove = (e: React.TouchEvent) => {
|
||||
touchEndX.current = e.targetTouches[0].clientX;
|
||||
};
|
||||
|
||||
const onTouchEnd = () => {
|
||||
if (!touchStartX.current || !touchEndX.current) return;
|
||||
const distance = touchStartX.current - touchEndX.current;
|
||||
const isLeftSwipe = distance > minSwipeDistance;
|
||||
const isRightSwipe = distance < -minSwipeDistance;
|
||||
|
||||
if (isLeftSwipe) {
|
||||
handleNextSlide();
|
||||
} else if (isRightSwipe) {
|
||||
handlePrevSlide();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="relative overflow-hidden bg-white py-16 lg:py-28 border-b border-medical-gray-100">
|
||||
{/* Background patterns */}
|
||||
@@ -160,7 +186,12 @@ export default function Hero({ banners = [], onShopNavigate }: { banners?: Banne
|
||||
transition={{ duration: 0.8, ease: "easeOut" }}
|
||||
className="relative z-10"
|
||||
>
|
||||
<div className="aspect-square bg-gradient-to-br from-slate-200 to-slate-300 rounded-[2.5rem] overflow-hidden border-4 border-white shadow-2xl relative group">
|
||||
<div
|
||||
className="aspect-square bg-gradient-to-br from-slate-200 to-slate-300 rounded-[2.5rem] overflow-hidden border-4 border-white shadow-2xl relative group touch-pan-y"
|
||||
onTouchStart={onTouchStart}
|
||||
onTouchMove={onTouchMove}
|
||||
onTouchEnd={onTouchEnd}
|
||||
>
|
||||
<AnimatePresence mode="wait">
|
||||
<motion.img
|
||||
key={activeImageUrl}
|
||||
|
||||
@@ -30,11 +30,12 @@ import { usePetStore, PetProfile as GlobalPetProfile, Reminder, HealthLog } from
|
||||
import { useCartStore } from "../lib/store/cartStore";
|
||||
import SafeImage from "./SafeImage";
|
||||
import SmartAdvisor from "./SmartAdvisor";
|
||||
import OrderDetailsModal from "./OrderDetailsModal";
|
||||
import { toast } from "sonner";
|
||||
import { toPersian, cn } from "../lib/utils";
|
||||
import api from "../lib/services/api";
|
||||
import api, { BASE_DOMAIN } from "../lib/services/api";
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
export default function PetProfile({ initialView, advisorNeed, embedded = false }: {
|
||||
initialView?: "index" | "detail" | "add" | "edit",
|
||||
@@ -42,16 +43,26 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
embedded?: boolean
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const { pets, addPet, removePet, setActivePet, getActivePet, updatePet, addReminder, toggleReminder, addHealthLog } = usePetStore();
|
||||
const { orders } = useCartStore();
|
||||
const activePet = getActivePet();
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [products, setProducts] = useState<Product[]>([]);
|
||||
const [prescriptions, setPrescriptions] = useState<any[]>([]);
|
||||
const [selectedInvoiceOrder, setSelectedInvoiceOrder] = useState<any | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
productService.getProducts({ limit: 999 })
|
||||
.then(res => setProducts(res.data))
|
||||
.catch(err => console.error("Error fetching products in PetProfile:", err));
|
||||
|
||||
api.get("/prescriptions")
|
||||
.then(res => {
|
||||
const data = Array.isArray(res.data) ? res.data : (res.data?.data || []);
|
||||
setPrescriptions(data);
|
||||
})
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -67,7 +78,16 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
}
|
||||
}, [initialView]);
|
||||
|
||||
const [activePetTab, setActivePetTab] = useState<"health" | "orders">("health");
|
||||
const [activePetTab, setActivePetTab] = useState<"health" | "orders" | "prescriptions">("health");
|
||||
|
||||
// URL query param retention for tab
|
||||
useEffect(() => {
|
||||
const tabParam = searchParams.get('tab');
|
||||
if (tabParam && ['health', 'orders', 'prescriptions'].includes(tabParam)) {
|
||||
setActivePetTab(tabParam as "health" | "orders" | "prescriptions");
|
||||
}
|
||||
}, [searchParams]);
|
||||
|
||||
const [petToDelete, setPetToDelete] = useState<GlobalPetProfile | null>(null);
|
||||
|
||||
// Modal states
|
||||
@@ -95,6 +115,11 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
return orders.filter(o => o.petId === activePet.id);
|
||||
}, [activePet, orders]);
|
||||
|
||||
const petPrescriptions = useMemo(() => {
|
||||
if (!activePet) return [];
|
||||
return prescriptions.filter(rx => rx.petId === activePet.id || rx.pet?.id === activePet.id || rx.petName === activePet.name);
|
||||
}, [activePet, prescriptions]);
|
||||
|
||||
const petCharityTotal = useMemo(() => {
|
||||
return petOrders.reduce((sum, o) => sum + (Number(o.charityDonation) || 0), 0);
|
||||
}, [petOrders]);
|
||||
@@ -139,18 +164,39 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
});
|
||||
}
|
||||
|
||||
// Priority 2: Biological factors
|
||||
if (activePet.age > 7) {
|
||||
const heart = products.find(p => p.id === "herz-vital" || p.slug?.includes("herz"));
|
||||
if (heart && !picks.some(x => x.product.id === heart.id)) {
|
||||
picks.push({ product: heart, reason: "محافظت از قلب پتهای مسن" });
|
||||
}
|
||||
// Priority 2: Biological & Life-stage factors
|
||||
if (activePet.age >= 7) {
|
||||
const seniorSupplements = products.filter(p =>
|
||||
(p.id === "herz-vital" || p.slug?.includes("herz") || p.name.includes("قلب") || p.benefits?.includes("مسن")) &&
|
||||
(p.suitableFor === activePet.type || p.suitableFor === "هر دو")
|
||||
);
|
||||
seniorSupplements.forEach(p => {
|
||||
if (!picks.some(x => x.product.id === p.id)) {
|
||||
picks.push({ product: p, reason: "محافظت از قلب و مفاصل در سنین بالا" });
|
||||
}
|
||||
});
|
||||
} else if (activePet.age > 0 && activePet.age <= 1) {
|
||||
const growthSupplements = products.filter(p =>
|
||||
(p.name.includes("رشد") || p.benefits?.includes("تغذیه توله") || p.benefits?.includes("کلسیم")) &&
|
||||
(p.suitableFor === activePet.type || p.suitableFor === "هر دو")
|
||||
);
|
||||
growthSupplements.forEach(p => {
|
||||
if (!picks.some(x => x.product.id === p.id)) {
|
||||
picks.push({ product: p, reason: "تغذیه متوازن و تقویت اسکلت در دوره رشد" });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Fill defaults if needed
|
||||
if (picks.length < 4) {
|
||||
const defaults = products.filter(p => !picks.some(x => x.product.id === p.id) && (p.suitableFor === activePet.type || p.suitableFor === "هر دو"));
|
||||
defaults.slice(0, 4 - picks.length).forEach(p => picks.push({ product: p }));
|
||||
if (activePet.activityLevel === "زیاد") {
|
||||
const performanceSupplements = products.filter(p =>
|
||||
(p.name.includes("انرژی") || p.benefits?.includes("عضله") || p.benefits?.includes("مفصل")) &&
|
||||
(p.suitableFor === activePet.type || p.suitableFor === "هر دو")
|
||||
);
|
||||
performanceSupplements.forEach(p => {
|
||||
if (!picks.some(x => x.product.id === p.id)) {
|
||||
picks.push({ product: p, reason: "تقویت مفاصل و ریکاوری برای سطح فعالیت بالا" });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return picks;
|
||||
@@ -609,6 +655,19 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
<span className="font-black text-sm italic">{condition}</span>
|
||||
</button>
|
||||
))}
|
||||
|
||||
<div className="pt-2">
|
||||
<label className="block text-[10px] font-black text-medical-gray-400 uppercase tracking-widest mb-2 pr-2">
|
||||
توضیحات و سوابق تکمیلی (اختیاری)
|
||||
</label>
|
||||
<textarea
|
||||
rows={3}
|
||||
value={formData.extraNotes || formData.notes || ""}
|
||||
onChange={e => setFormData({ ...formData, extraNotes: e.target.value, notes: e.target.value })}
|
||||
placeholder="سابقه جراحی، حساسیت دارویی، رژیم غذایی یا هر نکته دیگری که پزشکان کنینا باید بدانند..."
|
||||
className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-2xl p-4 text-xs font-medium text-medical-gray-900 focus:ring-2 focus:ring-canina-blue/20 outline-none resize-none leading-relaxed"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
@@ -876,12 +935,13 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
<div className="flex border-b border-medical-gray-200 gap-8 px-4">
|
||||
{[
|
||||
{ id: "health", label: "داشبورد سلامت و یادآوریها", icon: <Heart className="w-4 h-4" /> },
|
||||
{ id: "orders", label: "سوابق خرید و تاریخچه تخصصی", icon: <Package className="w-4 h-4" /> },
|
||||
{ id: "orders", label: "سوابق خرید و فاکتورها", icon: <Package className="w-4 h-4" /> },
|
||||
{ id: "prescriptions", label: "نسخههای پزشکی این همدم", icon: <Stethoscope className="w-4 h-4" /> },
|
||||
].map(tab => (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setActivePetTab(tab.id as "health" | "orders")}
|
||||
className={`pb-4 flex items-center gap-2 text-sm font-black transition-all relative ${activePetTab === tab.id ? "text-canina-blue" : "text-medical-gray-400 hover:text-medical-gray-600"}`}
|
||||
onClick={() => setActivePetTab(tab.id as "health" | "orders" | "prescriptions")}
|
||||
className={`pb-4 flex items-center gap-2 text-sm font-black transition-all relative cursor-pointer ${activePetTab === tab.id ? "text-canina-blue" : "text-medical-gray-400 hover:text-medical-gray-600"}`}
|
||||
>
|
||||
{tab.icon}
|
||||
{tab.label}
|
||||
@@ -899,40 +959,48 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
<div className="w-12 h-12 bg-white rounded-2xl flex items-center justify-center text-canina-blue shadow-lg border border-medical-gray-100">
|
||||
<Star className="w-6 h-6" />
|
||||
</div>
|
||||
<h3 className="text-3xl font-black text-medical-gray-900 italic">توصیههای درمانی اختصاصی</h3>
|
||||
<h3 className="text-3xl font-black text-medical-gray-900 italic">توصیههای درمانی هوشمند</h3>
|
||||
</div>
|
||||
<p className="text-[10px] font-black text-medical-gray-400 uppercase tracking-wider">کاتالوگ ۲۰۲۴ آلمان</p>
|
||||
<p className="text-[10px] font-black text-medical-gray-400 uppercase tracking-wider">کاتالوگ رسمی کنینا آلمان</p>
|
||||
</div>
|
||||
|
||||
<div className="grid md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||
{recommendedProducts.map(({ product: p, reason }) => (
|
||||
<motion.div
|
||||
key={p.id}
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
whileInView={{ opacity: 1, y: 0 }}
|
||||
viewport={{ once: true }}
|
||||
onClick={() => router.push(`/shop/${p.slug || p.id}`)}
|
||||
className="bg-white rounded-[2.5rem] p-6 border border-medical-gray-200 hover:shadow-2xl transition-all cursor-pointer group flex flex-col justify-between relative overflow-hidden"
|
||||
>
|
||||
{reason && (
|
||||
<div className="absolute top-0 left-0 right-0 bg-canina-blue/10 py-2 px-4 text-[9px] font-black text-canina-blue text-center border-b border-canina-blue/10">
|
||||
{reason}
|
||||
{recommendedProducts.length === 0 ? (
|
||||
<div className="p-8 bg-medical-gray-50/70 border border-dashed border-medical-gray-200 rounded-3xl text-center">
|
||||
<p className="text-xs font-bold text-medical-gray-500">
|
||||
بر اساس آخرین وضعیت پایش شده، نیاز درمانی فعالی برای {activePet.name} ثبت نشده است. جهت حفظ سلامتی عمومی میتوانید از کاتالوگ محصولات دیدن فرمایید.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||
{recommendedProducts.map(({ product: p, reason }) => (
|
||||
<motion.div
|
||||
key={p.id}
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
whileInView={{ opacity: 1, y: 0 }}
|
||||
viewport={{ once: true }}
|
||||
onClick={() => router.push(`/shop/${p.slug || p.id}`)}
|
||||
className="bg-white rounded-[2.5rem] p-6 border border-medical-gray-200 hover:shadow-2xl transition-all cursor-pointer group flex flex-col justify-between relative overflow-hidden"
|
||||
>
|
||||
{reason && (
|
||||
<div className="absolute top-0 left-0 right-0 bg-canina-blue/10 py-2 px-4 text-[9px] font-black text-canina-blue text-center border-b border-canina-blue/10">
|
||||
{reason}
|
||||
</div>
|
||||
)}
|
||||
<div className={cn("aspect-square bg-medical-gray-50 rounded-[1.5rem] p-6 mb-6 flex items-center justify-center overflow-hidden", reason ? "mt-8" : "")}>
|
||||
<SafeImage src={p.image} alt={p.name} className="w-full h-full group-hover:scale-110 transition-transform duration-500" imgClassName="object-contain" />
|
||||
</div>
|
||||
)}
|
||||
<div className={cn("aspect-square bg-medical-gray-50 rounded-[1.5rem] p-6 mb-6 flex items-center justify-center overflow-hidden", reason ? "mt-8" : "")}>
|
||||
<SafeImage src={p.image} alt={p.name} className="w-full h-full group-hover:scale-110 transition-transform duration-500" imgClassName="object-contain" />
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="text-lg font-black text-medical-gray-900 group-hover:text-canina-blue transition-colors mb-2 italic">{p.name}</h4>
|
||||
<p className="text-xs text-medical-gray-400 line-clamp-2 leading-relaxed mb-6 font-medium">{p.benefits}</p>
|
||||
<button className="w-full py-3.5 bg-medical-gray-900 text-white rounded-xl text-[10px] font-black uppercase tracking-widest group-hover:bg-canina-blue transition-colors flex items-center justify-center gap-2">
|
||||
بررسی تخصصی
|
||||
<ChevronLeft className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</motion.div>
|
||||
))}
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="text-lg font-black text-medical-gray-900 group-hover:text-canina-blue transition-colors mb-2 italic">{p.name}</h4>
|
||||
<p className="text-xs text-medical-gray-400 line-clamp-2 leading-relaxed mb-6 font-medium">{p.benefits}</p>
|
||||
<button className="w-full py-3.5 bg-medical-gray-900 text-white rounded-xl text-[10px] font-black uppercase tracking-widest group-hover:bg-canina-blue transition-colors flex items-center justify-center gap-2">
|
||||
بررسی تخصصی
|
||||
<ChevronLeft className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</motion.div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<div className="grid lg:grid-cols-2 gap-10">
|
||||
@@ -979,9 +1047,6 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
<p className="text-[10px] text-medical-gray-400 font-bold">{toPersian(reminder.time)} - {reminder.frequency}</p>
|
||||
</div>
|
||||
</div>
|
||||
<span className={cn("text-[10px] font-black italic", isCompleted ? "text-green-600" : "text-medical-gray-400")}>
|
||||
{isCompleted ? "انجام شد" : "در انتظار"}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})
|
||||
@@ -992,38 +1057,38 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
onClick={() => setIsAddingReminder(true)}
|
||||
className="w-full mt-8 py-5 border-2 border-dashed border-medical-gray-200 rounded-2xl text-medical-gray-400 font-black hover:border-canina-blue hover:text-canina-blue transition-all flex items-center justify-center gap-2"
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
افزودن یادآور جدید
|
||||
<Plus className="w-5 h-5" />
|
||||
تعریف یادآور درمانی جدید
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Health Logs */}
|
||||
<div className="bg-white rounded-[3rem] border border-medical-gray-200 p-10 shadow-sm">
|
||||
<div className="flex items-center gap-3 mb-10">
|
||||
<ClipboardList className="w-8 h-8 text-canina-blue" />
|
||||
<h3 className="text-2xl font-black text-medical-gray-900 italic">تایملاین سلامت</h3>
|
||||
<div className="flex items-center justify-between mb-10">
|
||||
<div className="flex items-center gap-3">
|
||||
<Activity className="w-8 h-8 text-canina-blue" />
|
||||
<h3 className="text-2xl font-black text-medical-gray-900 italic">گزارشات سلامت</h3>
|
||||
</div>
|
||||
<ClipboardList className="w-6 h-6 text-canina-blue" />
|
||||
</div>
|
||||
|
||||
<div className="space-y-6 max-h-[400px] overflow-y-auto pr-2 scrollbar-hide">
|
||||
<div className="space-y-4">
|
||||
{(activePet?.logs || []).length === 0 ? (
|
||||
<div className="text-center py-10 bg-medical-gray-50 rounded-2xl border border-dashed border-medical-gray-200">
|
||||
<p className="text-sm font-bold text-medical-gray-400 italic">هنوز گزارشی ثبت نشده است</p>
|
||||
</div>
|
||||
) : (
|
||||
(activePet?.logs || []).map((log) => (
|
||||
<div key={log.id} className="bg-medical-gray-50 p-6 rounded-[2.5rem] border border-medical-gray-100 relative group">
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
<div className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest">
|
||||
{toPersian(new Date(log.date).toLocaleDateString("fa-IR"))}
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<div className="px-2 py-0.5 bg-canina-blue/10 text-canina-blue rounded-full text-[8px] font-black">{log.appetite}</div>
|
||||
<div className="px-2 py-0.5 bg-green-500/10 text-green-500 rounded-full text-[8px] font-black">{log.energy}</div>
|
||||
(activePet?.logs || []).slice(0, 3).map((log) => (
|
||||
<div key={log.id} className="p-5 bg-medical-gray-50 rounded-2xl border border-medical-gray-100 flex items-center justify-between">
|
||||
<div>
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span className="text-[10px] font-black bg-white px-2 py-0.5 rounded-md border border-medical-gray-200 text-medical-gray-600">
|
||||
{toPersian(new Date(log.date).toLocaleDateString("fa-IR"))}
|
||||
</span>
|
||||
<span className="text-xs font-black text-medical-gray-900">اشتها: {log.appetite} | انرژی: {log.energy}</span>
|
||||
</div>
|
||||
{log.note && <p className="text-[11px] text-medical-gray-500 line-clamp-1">{log.note}</p>}
|
||||
</div>
|
||||
<p className="text-sm text-medical-gray-600 font-medium leading-relaxed italic">
|
||||
{log.note || "وضعیتی برای این روز ثبت نشده است."}
|
||||
</p>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
@@ -1038,7 +1103,7 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
) : activePetTab === "orders" ? (
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
@@ -1051,7 +1116,7 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-3xl font-black text-medical-gray-900 italic">تاریخچه خرید {activePet.name}</h3>
|
||||
<p className="text-xs font-bold text-medical-gray-400 mt-1">لیست محصولات خریداری شده ویژه این پرونده سلامت</p>
|
||||
<p className="text-xs font-bold text-medical-gray-400 mt-1">برای مشاهده جزئیات کامل فاکتور و پیگیری، روی هر سفارش کلیک کنید</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-left">
|
||||
@@ -1066,50 +1131,124 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
<Package className="w-12 h-12" />
|
||||
</div>
|
||||
<p className="text-medical-gray-400 font-black text-xl italic">هنوز سفارشی برای {activePet.name} ثبت نکردهاید.</p>
|
||||
<button onClick={() => router.push('/shop')} className="bg-canina-blue text-white px-10 py-4 rounded-2xl font-black hover:scale-105 transition-all">شروع اولین خرید</button>
|
||||
<button onClick={() => router.push('/shop')} className="bg-canina-blue text-white px-10 py-4 rounded-2xl font-black hover:scale-105 transition-all cursor-pointer">شروع اولین خرید</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-5">
|
||||
{petOrders.map(order =>
|
||||
order.items.map(item => (
|
||||
<motion.div
|
||||
key={`${order.id}-${item.product.id}`}
|
||||
initial={{ opacity: 0, x: 20 }}
|
||||
animate={{ opacity: 1, x: 0 }}
|
||||
whileHover={{ x: -10, backgroundColor: "rgba(249, 250, 251, 1)" }}
|
||||
className="p-6 bg-white rounded-[2.5rem] border border-medical-gray-200 flex items-center justify-between gap-6 transition-all cursor-pointer group shadow-sm hover:shadow-xl"
|
||||
onClick={() => router.push(`/shop/${item.product.slug || item.product.id}`)}
|
||||
>
|
||||
{/* Info on Left (Text side) */}
|
||||
<div className="flex-1 text-right">
|
||||
<h4 className="text-xl font-black text-medical-gray-900 group-hover:text-canina-blue transition-colors mb-2 italic">{item.product.name}</h4>
|
||||
<div className="flex flex-wrap gap-x-6 gap-y-2 items-center">
|
||||
<div className="flex items-center gap-1.5 text-xs font-bold text-medical-gray-500">
|
||||
<Calendar className="w-4 h-4 text-canina-blue/40" />
|
||||
{toPersian(new Date(order.date).toLocaleDateString("fa-IR", { year: 'numeric', month: 'long', day: 'numeric' }))}
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5 px-3 py-1 bg-green-50 text-green-600 rounded-full text-[10px] font-black italic">
|
||||
<Check className="w-3 h-3" />
|
||||
تایید شده و تحویل شده
|
||||
</div>
|
||||
<div className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest bg-medical-gray-50 px-3 py-1 rounded-lg">
|
||||
فاکتور: {toPersian(order.id)}
|
||||
</div>
|
||||
{petOrders.map(order => (
|
||||
<motion.div
|
||||
key={order.id}
|
||||
initial={{ opacity: 0, x: 20 }}
|
||||
animate={{ opacity: 1, x: 0 }}
|
||||
whileHover={{ x: -6 }}
|
||||
onClick={() => setSelectedInvoiceOrder(order)}
|
||||
className="p-6 bg-white rounded-[2.5rem] border border-medical-gray-200 hover:border-canina-blue/50 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-6 transition-all cursor-pointer group shadow-sm hover:shadow-xl"
|
||||
>
|
||||
<div className="flex-1 text-right">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<span className="text-xs font-black text-medical-gray-900">سفارش #{toPersian(order.id.slice(-6))}</span>
|
||||
<span className="text-[10px] font-black px-2.5 py-0.5 rounded-full bg-green-50 text-green-600">
|
||||
{toPersian(order.items.length)} قلم کالا
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-x-6 gap-y-2 items-center text-xs text-medical-gray-500 font-bold">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Calendar className="w-4 h-4 text-canina-blue/40" />
|
||||
{toPersian(new Date(order.date).toLocaleDateString("fa-IR", { year: 'numeric', month: 'long', day: 'numeric' }))}
|
||||
</div>
|
||||
<div className="text-canina-blue font-black">
|
||||
مبلغ کل: {toPersian(order.total.toLocaleString())} تومان
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Image on Right (Icon side) */}
|
||||
<div className="w-20 h-20 shrink-0 bg-medical-gray-50 rounded-[1.5rem] p-3 flex items-center justify-center border border-medical-gray-100 group-hover:bg-white transition-colors relative overflow-hidden">
|
||||
<SafeImage
|
||||
src={item.product.image}
|
||||
alt={item.product.name}
|
||||
className="w-full h-full"
|
||||
imgClassName="object-contain"
|
||||
/>
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
{order.items.slice(0, 3).map((item, idx) => (
|
||||
<div key={idx} className="w-14 h-14 bg-medical-gray-50 rounded-2xl p-2 flex items-center justify-center border border-medical-gray-100 overflow-hidden">
|
||||
<SafeImage src={item.product.image} alt={item.product.name} className="w-full h-full" imgClassName="object-contain" />
|
||||
</div>
|
||||
))}
|
||||
<div className="px-4 py-2 bg-canina-blue/10 text-canina-blue text-xs font-black rounded-xl group-hover:bg-canina-blue group-hover:text-white transition-colors">
|
||||
مشاهده فاکتور
|
||||
</div>
|
||||
</motion.div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</motion.div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
) : (
|
||||
/* Prescriptions Tab */
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
className="bg-white rounded-[4rem] border border-medical-gray-200 p-12 min-h-[500px] shadow-sm"
|
||||
>
|
||||
<div className="flex items-center justify-between mb-12">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="w-14 h-14 bg-canina-blue text-white rounded-[1.5rem] flex items-center justify-center shadow-xl">
|
||||
<Stethoscope className="w-7 h-7" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-3xl font-black text-medical-gray-900 italic">نسخههای پزشکی {activePet.name}</h3>
|
||||
<p className="text-xs font-bold text-medical-gray-400 mt-1">پرونده نسخههای بارگذاری شده و نظرات تخصصی پزشکان کنینا</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{petPrescriptions.length === 0 ? (
|
||||
<div className="py-24 text-center space-y-6">
|
||||
<div className="w-24 h-24 bg-medical-gray-50 rounded-full flex items-center justify-center mx-auto text-medical-gray-200 shadow-inner">
|
||||
<Stethoscope className="w-12 h-12" />
|
||||
</div>
|
||||
<p className="text-medical-gray-400 font-black text-xl italic">هنوز نسخه پزشکی برای {activePet.name} ثبت نشده است.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-6">
|
||||
{petPrescriptions.map((rx: any) => (
|
||||
<div
|
||||
key={rx.id}
|
||||
className="p-6 bg-medical-gray-50/70 rounded-[2.5rem] border border-medical-gray-200 flex flex-col md:flex-row items-start md:items-center justify-between gap-6"
|
||||
>
|
||||
<div className="space-y-2 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs font-black text-medical-gray-900">نسخه شماره #{rx.id.slice(0, 8)}</span>
|
||||
<span className={`text-[10px] font-black px-2.5 py-0.5 rounded-full ${
|
||||
rx.status === 'APPROVED' ? 'bg-green-100 text-green-700' : rx.status === 'REJECTED' ? 'bg-red-100 text-red-700' : 'bg-amber-100 text-amber-700'
|
||||
}`}>
|
||||
{rx.status === 'APPROVED' ? 'تایید شده توسط پزشک' : rx.status === 'REJECTED' ? 'عدم تایید' : 'در حال بررسی تخصصی'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="text-xs text-medical-gray-500 font-bold flex items-center gap-2">
|
||||
<Calendar className="w-4 h-4 text-canina-blue" />
|
||||
<span>تاریخ ثبت: {toPersian(new Date(rx.createdAt).toLocaleDateString("fa-IR", { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit' }))}</span>
|
||||
</div>
|
||||
{rx.notes && (
|
||||
<p className="text-xs text-medical-gray-600 bg-white p-3 rounded-xl border border-medical-gray-200">
|
||||
<strong className="text-medical-gray-800 block mb-0.5">یادداشت شما:</strong>
|
||||
{rx.notes}
|
||||
</p>
|
||||
)}
|
||||
{rx.adminNotes && (
|
||||
<p className="text-xs text-canina-blue bg-canina-blue/5 p-3 rounded-xl border border-canina-blue/10 font-bold">
|
||||
<strong className="text-canina-dark block mb-0.5">پاسخ و دستور مصرف پزشک کنینا:</strong>
|
||||
{rx.adminNotes.split('__PRESCRIBED_PRODUCTS__:')[0]}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="shrink-0 flex items-center gap-3">
|
||||
<a
|
||||
href={rx.fileUrl.startsWith('http') ? rx.fileUrl : `${BASE_DOMAIN}${rx.fileUrl}`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="px-4 py-2.5 bg-white text-canina-blue border border-canina-blue/20 rounded-xl text-xs font-black hover:bg-canina-blue hover:text-white transition-all shadow-xs"
|
||||
>
|
||||
مشاهده فایل نسخه
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
@@ -1290,6 +1429,12 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
{/* Invoice Modal for Pet Purchase History */}
|
||||
<OrderDetailsModal
|
||||
isOpen={!!selectedInvoiceOrder}
|
||||
order={selectedInvoiceOrder}
|
||||
onClose={() => setSelectedInvoiceOrder(null)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
"use client";
|
||||
import React, { useState } from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { motion, AnimatePresence } from "motion/react";
|
||||
import { Upload, CheckCircle2, X, Send, Stethoscope } from "lucide-react";
|
||||
import { Upload, CheckCircle2, X, Send, Stethoscope, Plus, Dog, Cat, Phone, FileText } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { useUserStore } from "../lib/store/userStore";
|
||||
import { usePetStore } from "../lib/store/usePetStore";
|
||||
|
||||
interface PrescriptionUploadModalProps {
|
||||
isOpen: boolean;
|
||||
@@ -10,13 +12,35 @@ interface PrescriptionUploadModalProps {
|
||||
}
|
||||
|
||||
export default function PrescriptionUploadModal({ isOpen, onClose }: PrescriptionUploadModalProps) {
|
||||
const { isLoggedIn, profile } = useUserStore();
|
||||
const { pets, activePetId, addPet } = usePetStore();
|
||||
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [petName, setPetName] = useState("");
|
||||
const [phone, setPhone] = useState("");
|
||||
const [notes, setNotes] = useState("");
|
||||
const [selectedPetOption, setSelectedPetOption] = useState<string>("active"); // petId or 'new'
|
||||
const [newPetName, setNewPetName] = useState("");
|
||||
const [newPetType, setNewPetType] = useState<"سگ" | "گربه">("سگ");
|
||||
const [newPetBreed, setNewPetBreed] = useState("");
|
||||
const [newPetAge, setNewPetAge] = useState<string>("");
|
||||
const [newPetWeight, setNewPetWeight] = useState<string>("");
|
||||
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [isSuccess, setIsSuccess] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
if (isLoggedIn && profile?.mobile) {
|
||||
setPhone(profile.mobile);
|
||||
}
|
||||
if (pets.length > 0) {
|
||||
setSelectedPetOption(activePetId || pets[0].id);
|
||||
} else {
|
||||
setSelectedPetOption("new");
|
||||
}
|
||||
}
|
||||
}, [isOpen, isLoggedIn, profile?.mobile, pets, activePetId]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
@@ -27,9 +51,11 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
|
||||
const resetForm = () => {
|
||||
setFile(null);
|
||||
setPetName("");
|
||||
setPhone("");
|
||||
setNotes("");
|
||||
setNewPetName("");
|
||||
setNewPetBreed("");
|
||||
setNewPetAge("");
|
||||
setNewPetWeight("");
|
||||
setIsSubmitting(false);
|
||||
setIsSuccess(false);
|
||||
};
|
||||
@@ -48,10 +74,25 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
|
||||
const cleanPhone = phone.trim();
|
||||
if (!/^09\d{9}$/.test(cleanPhone)) {
|
||||
toast.error("شماره همراه وارد شده معتبر نیست. (مثال: ۰۹۱۲۳۴۵۶۷۸۹)");
|
||||
toast.error("شماره همراه معتبر نیست. (مثال: ۰۹۱۲۳۴۵۶۷۸۹)");
|
||||
return;
|
||||
}
|
||||
|
||||
let finalPetId: string | undefined = undefined;
|
||||
let finalPetName: string | undefined = undefined;
|
||||
|
||||
if (selectedPetOption !== "new") {
|
||||
finalPetId = selectedPetOption;
|
||||
const found = pets.find(p => p.id === selectedPetOption);
|
||||
if (found) finalPetName = found.name;
|
||||
} else {
|
||||
if (!newPetName.trim()) {
|
||||
toast.error("لطفاً نام همدم (پت) را وارد کنید.");
|
||||
return;
|
||||
}
|
||||
finalPetName = newPetName.trim();
|
||||
}
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
const api = (await import("../lib/services/api")).default;
|
||||
@@ -62,17 +103,43 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
});
|
||||
const fileUrl = uploadRes.data?.data?.url || uploadRes.data?.url || uploadRes.data?.filename || file.name;
|
||||
|
||||
// Submit prescription to backend with petName and phone for automatic user & pet profile creation
|
||||
await api.post("/prescriptions", {
|
||||
const payload: Record<string, any> = {
|
||||
fileUrl,
|
||||
phone: cleanPhone,
|
||||
petName: petName.trim() || undefined,
|
||||
notes: notes.trim() || undefined
|
||||
});
|
||||
notes: notes.trim() || undefined,
|
||||
};
|
||||
|
||||
if (finalPetId) {
|
||||
payload.petId = finalPetId;
|
||||
payload.petName = finalPetName;
|
||||
} else {
|
||||
payload.petName = finalPetName;
|
||||
payload.petType = newPetType;
|
||||
payload.petBreed = newPetBreed.trim() || undefined;
|
||||
payload.petAge = newPetAge ? parseFloat(newPetAge) : 0;
|
||||
payload.petWeight = newPetWeight ? parseFloat(newPetWeight) : 0;
|
||||
}
|
||||
|
||||
await api.post("/prescriptions", payload);
|
||||
|
||||
if (selectedPetOption === "new" && finalPetName) {
|
||||
addPet({
|
||||
name: finalPetName,
|
||||
type: newPetType,
|
||||
breed: newPetBreed.trim() || "نامشخص",
|
||||
age: newPetAge ? parseFloat(newPetAge) : 0,
|
||||
weight: newPetWeight ? parseFloat(newPetWeight) : 0,
|
||||
activityLevel: "متوسط",
|
||||
medicalConditions: [],
|
||||
reminders: [],
|
||||
logs: [],
|
||||
consumptions: []
|
||||
});
|
||||
}
|
||||
|
||||
setIsSubmitting(false);
|
||||
setIsSuccess(true);
|
||||
toast.success("نسخه پزشکی شما با موفقیت ثبت و ارسال شد.");
|
||||
toast.success("نسخه پزشکی شما با موفقیت ثبت شد.");
|
||||
} catch (error) {
|
||||
console.error("[PrescriptionUpload] Submission error:", error);
|
||||
setIsSubmitting(false);
|
||||
@@ -82,18 +149,18 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm" dir="rtl font-vazir">
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm font-vazir" dir="rtl">
|
||||
<motion.div
|
||||
initial={{ opacity: 0, scale: 0.95 }}
|
||||
animate={{ opacity: 1, scale: 1 }}
|
||||
exit={{ opacity: 0, scale: 0.95 }}
|
||||
className="bg-white rounded-3xl max-w-lg w-full overflow-hidden shadow-2xl border border-medical-gray-200"
|
||||
className="bg-white rounded-3xl max-w-lg w-full max-h-[90vh] overflow-y-auto shadow-2xl border border-medical-gray-200 flex flex-col"
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="bg-canina-blue text-white p-6 relative">
|
||||
<div className="bg-canina-blue text-white p-6 relative shrink-0">
|
||||
<button
|
||||
onClick={handleClose}
|
||||
className="absolute left-5 top-5 text-white/80 hover:text-white bg-white/10 p-1.5 rounded-full transition-colors"
|
||||
className="absolute left-5 top-5 text-white/80 hover:text-white bg-white/10 p-1.5 rounded-full transition-colors cursor-pointer"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
@@ -102,14 +169,14 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
<Stethoscope className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-lg font-black font-vazir">خرید سریع با نسخه دامپزشک</h3>
|
||||
<p className="text-xs text-blue-100 mt-0.5">آپلود نسخه برای تامین فوری و مشاوره تخصصی</p>
|
||||
<h3 className="text-lg font-black font-vazir">بررسی تخصصی نسخه دامپزشک</h3>
|
||||
<p className="text-xs text-blue-100 mt-0.5">آپلود نسخه جهت تامین فوری دارو و مکملهای اورجینال آلمان</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Body */}
|
||||
<div className="p-6">
|
||||
<div className="p-6 flex-1">
|
||||
{isSuccess ? (
|
||||
<div className="text-center py-8 space-y-4">
|
||||
<div className="w-16 h-16 bg-green-100 text-green-600 rounded-full flex items-center justify-center mx-auto">
|
||||
@@ -117,11 +184,11 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
</div>
|
||||
<h4 className="text-lg font-black text-medical-gray-900">نسخه با موفقیت ثبت شد</h4>
|
||||
<p className="text-xs text-medical-gray-500 max-w-sm mx-auto leading-relaxed">
|
||||
کارشناسان و دامپزشکان کنینا نسخه شما را بررسی کرده و ظرف حداکثر ۱۵ دقیقه جهت هماهنگی ارسال دارو با شما تماس خواهند گرفت.
|
||||
تیم پزشکی و کارشناسان کنینا نسخه شما را بررسی کرده و اقلام تجویزی را به پرونده شما اضافه میکنند. به محض آمادهسازی، پیامک اطلاعرسانی برای شما ارسال خواهد شد.
|
||||
</p>
|
||||
<button
|
||||
onClick={handleClose}
|
||||
className="px-6 py-2.5 bg-canina-blue text-white rounded-xl text-xs font-black hover:bg-canina-dark transition-all"
|
||||
className="px-8 py-3 bg-canina-blue text-white rounded-xl text-xs font-black hover:bg-canina-dark transition-all cursor-pointer shadow-md shadow-canina-blue/20"
|
||||
>
|
||||
متوجه شدم
|
||||
</button>
|
||||
@@ -130,7 +197,7 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
{/* Upload Zone */}
|
||||
<div>
|
||||
<label className="block text-xs font-black text-medical-gray-700 mb-2">تصویر نسخه پزشکی *</label>
|
||||
<label className="block text-xs font-black text-medical-gray-700 mb-2">تصویر یا فایل نسخه دامپزشک *</label>
|
||||
<div className="border-2 border-dashed border-medical-gray-300 hover:border-canina-blue rounded-2xl p-4 text-center cursor-pointer transition-colors relative bg-medical-gray-50/50">
|
||||
<input
|
||||
type="file"
|
||||
@@ -138,71 +205,173 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
onChange={handleFileChange}
|
||||
className="absolute inset-0 opacity-0 cursor-pointer"
|
||||
/>
|
||||
<Upload className="w-8 h-8 text-medical-gray-400 mx-auto mb-2" />
|
||||
{file ? (
|
||||
<span className="text-xs font-bold text-canina-blue block">{file.name}</span>
|
||||
) : (
|
||||
<>
|
||||
<span className="text-xs font-bold text-medical-gray-600 block">کلیک کنید یا فایل نسخه را بکشید</span>
|
||||
<span className="text-[10px] text-medical-gray-400 block mt-1">فرمتهای JPG، PNG یا PDF (حداکثر ۵ مگابایت)</span>
|
||||
</>
|
||||
)}
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<div className="w-10 h-10 rounded-full bg-canina-blue/10 flex items-center justify-center text-canina-blue">
|
||||
<Upload className="w-5 h-5" />
|
||||
</div>
|
||||
{file ? (
|
||||
<div className="text-xs font-bold text-canina-blue truncate max-w-xs">{file.name}</div>
|
||||
) : (
|
||||
<>
|
||||
<p className="text-xs font-bold text-medical-gray-700">برای انتخاب فایل یا عکس نسخه کلیک کنید</p>
|
||||
<span className="text-[10px] text-medical-gray-400">فرمتهای مجاز: JPG, PNG, PDF (حداکثر ۱۰ مگابایت)</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-xs font-black text-medical-gray-700 mb-1.5">نام پت (اختیاری)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={petName}
|
||||
onChange={(e) => setPetName(e.target.value)}
|
||||
placeholder="مثال: لوسی"
|
||||
className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-xl px-3 py-2 text-xs font-bold focus:ring-2 focus:ring-canina-blue/20 outline-none"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-black text-medical-gray-700 mb-1.5">شماره همراه جهت هماهنگی *</label>
|
||||
{/* Pet Selection or Inline Creation */}
|
||||
<div className="space-y-2">
|
||||
<label className="block text-xs font-black text-medical-gray-700">این نسخه برای کدام همدم است؟ *</label>
|
||||
{pets.length > 0 && (
|
||||
<div className="grid grid-cols-2 gap-2 mb-2">
|
||||
{pets.map((p) => (
|
||||
<button
|
||||
key={p.id}
|
||||
type="button"
|
||||
onClick={() => setSelectedPetOption(p.id)}
|
||||
className={`p-2.5 rounded-xl border text-xs font-bold flex items-center gap-2 transition-all cursor-pointer ${
|
||||
selectedPetOption === p.id
|
||||
? "border-canina-blue bg-canina-blue/10 text-canina-blue shadow-xs font-black"
|
||||
: "border-medical-gray-200 text-medical-gray-600 hover:bg-medical-gray-50"
|
||||
}`}
|
||||
>
|
||||
{p.type === "سگ" ? <Dog className="w-4 h-4 shrink-0" /> : <Cat className="w-4 h-4 shrink-0 text-amber-500" />}
|
||||
<span className="truncate">{p.name} ({p.breed || p.type})</span>
|
||||
</button>
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSelectedPetOption("new")}
|
||||
className={`p-2.5 rounded-xl border text-xs font-bold flex items-center justify-center gap-1.5 transition-all cursor-pointer ${
|
||||
selectedPetOption === "new"
|
||||
? "border-canina-blue bg-canina-blue/10 text-canina-blue font-black"
|
||||
: "border-dashed border-medical-gray-300 text-medical-gray-500 hover:bg-medical-gray-50"
|
||||
}`}
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
<span>همدم جدید</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Inline Pet Info Form if "new" or no pets */}
|
||||
{(selectedPetOption === "new" || pets.length === 0) && (
|
||||
<div className="p-3.5 bg-medical-gray-50/80 rounded-2xl border border-medical-gray-200 space-y-3 animate-in fade-in duration-200">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-[11px] font-black text-medical-gray-800">مشخصات همدم جدید:</span>
|
||||
<div className="flex gap-1.5">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setNewPetType("سگ")}
|
||||
className={`px-3 py-1 rounded-lg text-xs font-bold transition-all cursor-pointer ${
|
||||
newPetType === "سگ" ? "bg-canina-blue text-white shadow-xs" : "bg-white text-medical-gray-600 border border-medical-gray-200"
|
||||
}`}
|
||||
>
|
||||
سگ
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setNewPetType("گربه")}
|
||||
className={`px-3 py-1 rounded-lg text-xs font-bold transition-all cursor-pointer ${
|
||||
newPetType === "گربه" ? "bg-canina-blue text-white shadow-xs" : "bg-white text-medical-gray-600 border border-medical-gray-200"
|
||||
}`}
|
||||
>
|
||||
گربه
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="نام حیوان خانگی *"
|
||||
value={newPetName}
|
||||
onChange={(e) => setNewPetName(e.target.value)}
|
||||
className="w-full bg-white border border-medical-gray-200 rounded-xl px-3 py-2 text-xs font-bold focus:outline-none focus:ring-2 focus:ring-canina-blue/20"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="نژاد (مثلاً ژرمن، پرشین)"
|
||||
value={newPetBreed}
|
||||
onChange={(e) => setNewPetBreed(e.target.value)}
|
||||
className="w-full bg-white border border-medical-gray-200 rounded-xl px-3 py-2 text-xs font-bold focus:outline-none focus:ring-2 focus:ring-canina-blue/20"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input
|
||||
type="number"
|
||||
placeholder="سن (سال)"
|
||||
value={newPetAge}
|
||||
onChange={(e) => setNewPetAge(e.target.value)}
|
||||
className="w-full bg-white border border-medical-gray-200 rounded-xl px-3 py-2 text-xs font-bold focus:outline-none focus:ring-2 focus:ring-canina-blue/20"
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
step="0.1"
|
||||
placeholder="وزن (کیلوگرم)"
|
||||
value={newPetWeight}
|
||||
onChange={(e) => setNewPetWeight(e.target.value)}
|
||||
className="w-full bg-white border border-medical-gray-200 rounded-xl px-3 py-2 text-xs font-bold focus:outline-none focus:ring-2 focus:ring-canina-blue/20"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Phone Number */}
|
||||
<div>
|
||||
<label className="block text-xs font-black text-medical-gray-700 mb-1">
|
||||
شماره همراه جهت هماهنگی و پیامک تایید *
|
||||
</label>
|
||||
<div className="relative">
|
||||
<input
|
||||
type="tel"
|
||||
dir="ltr"
|
||||
required
|
||||
placeholder="۰۹۱۲۳۴۵۶۷۸۹"
|
||||
value={phone}
|
||||
onChange={(e) => setPhone(e.target.value)}
|
||||
placeholder="۰۹۱۲..."
|
||||
className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-xl px-3 py-2 text-xs font-bold focus:ring-2 focus:ring-canina-blue/20 outline-none text-left"
|
||||
dir="ltr"
|
||||
className="w-full bg-white border border-medical-gray-200 rounded-xl py-2.5 px-3 text-xs font-mono font-bold text-medical-gray-900 focus:outline-none focus:ring-2 focus:ring-canina-blue/20"
|
||||
/>
|
||||
<Phone className="w-4 h-4 text-medical-gray-400 absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none" />
|
||||
</div>
|
||||
{isLoggedIn && profile?.mobile && (
|
||||
<span className="text-[10px] text-green-600 font-bold block mt-1">
|
||||
✓ شماره از حساب کاربری شما شناسایی شد.
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Additional Notes */}
|
||||
<div>
|
||||
<label className="block text-xs font-black text-medical-gray-700 mb-1.5">توضیحات تکمیلی (اختیاری)</label>
|
||||
<label className="block text-xs font-black text-medical-gray-700 mb-1">توضیحات و علائم خاص (اختیاری)</label>
|
||||
<textarea
|
||||
rows={2}
|
||||
placeholder="نکات پزشک، حساسیت دارویی یا شرایط خاص..."
|
||||
value={notes}
|
||||
onChange={(e) => setNotes(e.target.value)}
|
||||
placeholder="اگر توضیحات خاصی درباره سابقه درمانی پت دارید بنویسید..."
|
||||
className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-xl px-3 py-2 text-xs font-bold focus:ring-2 focus:ring-canina-blue/20 outline-none"
|
||||
className="w-full bg-white border border-medical-gray-200 rounded-xl p-3 text-xs font-medium text-medical-gray-900 focus:outline-none focus:ring-2 focus:ring-canina-blue/20 resize-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="pt-2 flex items-center justify-end gap-3 border-t border-medical-gray-100">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClose}
|
||||
className="px-4 py-2.5 rounded-xl text-xs font-bold text-medical-gray-500 hover:bg-medical-gray-100 transition-colors"
|
||||
>
|
||||
انصراف
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="px-6 py-2.5 bg-canina-blue text-white rounded-xl text-xs font-black hover:bg-canina-dark transition-all flex items-center gap-2 shadow-md shadow-canina-blue/20 disabled:opacity-50"
|
||||
>
|
||||
<Send className="w-3.5 h-3.5" />
|
||||
<span>{isSubmitting ? "در حال ارسال..." : "ارسال نسخه و سفارش سریع"}</span>
|
||||
</button>
|
||||
</div>
|
||||
{/* Submit Button */}
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="w-full py-3.5 bg-canina-blue text-white rounded-xl font-black text-xs hover:bg-canina-dark transition-all flex items-center justify-center gap-2 shadow-lg shadow-canina-blue/20 disabled:opacity-50 cursor-pointer"
|
||||
>
|
||||
{isSubmitting ? (
|
||||
<div className="w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin" />
|
||||
) : (
|
||||
<>
|
||||
<Send className="w-4 h-4" />
|
||||
<span>ارسال نسخه و ثبت درخواست تامین</span>
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -15,6 +15,7 @@ import TopUpModal from "./TopUpModal";
|
||||
import { ticketService, Ticket, TicketMessage } from "../lib/services/ticketService";
|
||||
import { usePetStore } from "../lib/store/usePetStore";
|
||||
import PetProfile from "./PetProfile";
|
||||
import api, { BASE_DOMAIN } from "../lib/services/api";
|
||||
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
@@ -33,17 +34,37 @@ export default function UserDashboard() {
|
||||
}, [isLoggedIn, router]);
|
||||
|
||||
const { orders } = useCartStore();
|
||||
const [activeTab, setActiveTab] = React.useState<"profile" | "orders" | "wallet" | "addresses" | "tickets" | "pets" | "overview">("profile");
|
||||
const [activeTab, setActiveTab] = React.useState<"profile" | "orders" | "wallet" | "addresses" | "tickets" | "pets" | "prescriptions" | "overview">("profile");
|
||||
|
||||
// Set tab from URL query param if present
|
||||
useEffect(() => {
|
||||
const tabParam = searchParams.get('tab');
|
||||
if (tabParam && ['profile', 'orders', 'wallet', 'addresses', 'tickets', 'pets'].includes(tabParam)) {
|
||||
setActiveTab(tabParam as "profile" | "orders" | "wallet" | "addresses" | "tickets" | "pets");
|
||||
if (tabParam && ['profile', 'orders', 'wallet', 'addresses', 'tickets', 'pets', 'prescriptions'].includes(tabParam)) {
|
||||
setActiveTab(tabParam as "profile" | "orders" | "wallet" | "addresses" | "tickets" | "pets" | "prescriptions");
|
||||
}
|
||||
}, [searchParams]);
|
||||
|
||||
const [isLoadingOrders, setIsLoadingOrders] = useState(false);
|
||||
const [prescriptions, setPrescriptions] = useState<any[]>([]);
|
||||
const [isLoadingPrescriptions, setIsLoadingPrescriptions] = useState(false);
|
||||
|
||||
const fetchPrescriptions = React.useCallback(async () => {
|
||||
try {
|
||||
setIsLoadingPrescriptions(true);
|
||||
const res = await api.get('/prescriptions');
|
||||
setPrescriptions(Array.isArray(res.data) ? res.data : (res.data?.data || []));
|
||||
} catch {
|
||||
// ignore
|
||||
} finally {
|
||||
setIsLoadingPrescriptions(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (activeTab === 'prescriptions') {
|
||||
fetchPrescriptions();
|
||||
}
|
||||
}, [activeTab, fetchPrescriptions]);
|
||||
|
||||
// Tickets State
|
||||
const [tickets, setTickets] = useState<Ticket[]>([]);
|
||||
@@ -343,6 +364,7 @@ export default function UserDashboard() {
|
||||
{ id: "profile", label: "اطلاعات فردی", icon: <UserCircle className="w-5 h-5" /> },
|
||||
{ id: "pets", label: "پتهای من", icon: <Dog className="w-5 h-5" /> },
|
||||
{ id: "orders", label: "سفارشات من", icon: <Package className="w-5 h-5" /> },
|
||||
{ id: "prescriptions", label: "نسخههای من", icon: <Stethoscope className="w-5 h-5" /> },
|
||||
{ id: "wallet", label: "کیف پول", icon: <Wallet className="w-5 h-5" /> },
|
||||
{ id: "addresses", label: "آدرسها", icon: <MapPin className="w-5 h-5" /> },
|
||||
{ id: "tickets", label: "پشتیبانی و مشاوره", icon: <MessageSquare className="w-5 h-5" /> },
|
||||
@@ -377,8 +399,8 @@ export default function UserDashboard() {
|
||||
{tabs.map(tab => (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setActiveTab(tab.id as 'overview' | 'orders' | 'addresses' | 'wallet' | 'tickets')}
|
||||
className={`flex items-center justify-center gap-2 px-3 sm:px-4 py-2.5 sm:py-3 rounded-xl sm:rounded-2xl transition-all font-bold text-xs sm:text-sm ${activeTab === tab.id ? "bg-canina-blue text-white shadow-lg shadow-canina-blue/20" : "text-medical-gray-600 hover:bg-medical-gray-100 bg-medical-gray-50"}`}
|
||||
onClick={() => setActiveTab(tab.id as any)}
|
||||
className={`flex items-center justify-center gap-2 px-3 sm:px-4 py-2.5 sm:py-3 rounded-xl sm:rounded-2xl transition-all font-bold text-xs sm:text-sm cursor-pointer ${activeTab === tab.id ? "bg-canina-blue text-white shadow-lg shadow-canina-blue/20" : "text-medical-gray-600 hover:bg-medical-gray-100 bg-medical-gray-50"}`}
|
||||
>
|
||||
<div className="flex-shrink-0">{tab.icon}</div>
|
||||
<span>{tab.label}</span>
|
||||
@@ -1067,7 +1089,106 @@ export default function UserDashboard() {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
|
||||
{activeTab === "prescriptions" && (
|
||||
<div>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 mb-8">
|
||||
<div>
|
||||
<h3 className="text-2xl font-black text-medical-gray-900 italic flex items-center gap-2">
|
||||
<Stethoscope className="w-6 h-6 text-canina-blue" />
|
||||
نسخههای پزشکی من
|
||||
</h3>
|
||||
<p className="text-xs font-bold text-medical-gray-400 mt-1">
|
||||
پیگیری وضعیت نسخههای بارگذاری شده و توصیههای دارویی دامپزشک
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => router.push('/?rx=1')}
|
||||
className="px-5 py-3 bg-canina-blue text-white rounded-2xl text-xs font-black hover:bg-canina-dark transition-all flex items-center gap-2 shadow-lg shadow-canina-blue/20 cursor-pointer"
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
<span>ارسال نسخه جدید</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{isLoadingPrescriptions ? (
|
||||
<div className="py-20 text-center text-medical-gray-400 font-bold text-sm">
|
||||
در حال بارگذاری نسخهها...
|
||||
</div>
|
||||
) : prescriptions.length === 0 ? (
|
||||
<div className="py-20 text-center space-y-4">
|
||||
<div className="w-16 h-16 bg-medical-gray-50 text-medical-gray-300 rounded-full flex items-center justify-center mx-auto">
|
||||
<Stethoscope className="w-8 h-8" />
|
||||
</div>
|
||||
<p className="text-sm font-bold text-medical-gray-400">هنوز هیچ نسخهای ثبت نکردهاید.</p>
|
||||
<button
|
||||
onClick={() => router.push('/?rx=1')}
|
||||
className="px-6 py-2.5 bg-medical-gray-900 text-white rounded-xl text-xs font-bold hover:bg-canina-blue transition-all cursor-pointer"
|
||||
>
|
||||
ثبت اولین نسخه
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{prescriptions.map((rx: any) => (
|
||||
<div
|
||||
key={rx.id}
|
||||
className="p-5 sm:p-6 bg-medical-gray-50 border border-medical-gray-200 rounded-[1.5rem] sm:rounded-[2rem] space-y-3 transition-all hover:shadow-md"
|
||||
>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 pb-3 border-b border-medical-gray-200">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs font-black text-medical-gray-900">نسخه #{rx.id.slice(0, 8)}</span>
|
||||
{rx.pet && (
|
||||
<span className="px-2 py-0.5 bg-purple-50 text-purple-700 text-[10px] font-bold rounded-lg border border-purple-100">
|
||||
🐾 {rx.pet.name} ({rx.pet.breed || rx.pet.type})
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className={`px-3 py-1 text-xs font-black rounded-full ${
|
||||
rx.status === 'APPROVED' ? 'bg-green-100 text-green-700' :
|
||||
rx.status === 'REJECTED' ? 'bg-red-100 text-red-700' :
|
||||
'bg-amber-100 text-amber-700'
|
||||
}`}>
|
||||
{rx.status === 'APPROVED' ? 'تایید شده' : rx.status === 'REJECTED' ? 'عدم تایید' : 'در حال بررسی'}
|
||||
</span>
|
||||
<span className="text-[11px] text-medical-gray-400 font-bold">
|
||||
{toPersian(new Date(rx.createdAt).toLocaleDateString('fa-IR'))}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{rx.notes && (
|
||||
<p className="text-xs text-medical-gray-600">
|
||||
<strong className="text-medical-gray-800">توضیحات شما: </strong>
|
||||
{rx.notes}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{rx.adminNotes && (
|
||||
<div className="p-3.5 bg-canina-blue/5 border border-canina-blue/10 rounded-xl text-xs text-canina-blue leading-relaxed font-bold">
|
||||
<strong className="text-canina-dark block mb-1">پاسخ دامپزشک کنینا:</strong>
|
||||
{rx.adminNotes.split('__PRESCRIBED_PRODUCTS__:')[0]}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="pt-2 flex items-center justify-end gap-2">
|
||||
<a
|
||||
href={rx.fileUrl.startsWith('http') ? rx.fileUrl : `${BASE_DOMAIN}${rx.fileUrl}`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="px-4 py-2 bg-white border border-medical-gray-200 text-medical-gray-700 hover:text-canina-blue hover:border-canina-blue rounded-xl text-xs font-bold transition-all"
|
||||
>
|
||||
مشاهده تصویر نسخه
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
</div>
|
||||
|
||||
{/* Sidebar Widgets (Wallet & Charity) */}
|
||||
|
||||
Reference in new issue
Block a user