feat(inventory): implement numeric stock inventory across fullstack and improve prescription UX handoff
Deploy Canina / deploy (push) Failing after 2m31s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s

This commit is contained in:
devops committed 2026-10-12 19:29:48 +00:00
1 parent e9582430e6
commit 741365f04c
13 files changed
+177 -47

No files matched your search

+7 -1
View File
@@ -231,7 +231,13 @@ export default function ClientLayout({ children }: { children: React.ReactNode }
onClose={() => setIsPrescriptionModalOpen(false)}
/>
<MobileBottomNav
onPrescriptionOpen={() => setIsPrescriptionModalOpen(true)}
onPrescriptionOpen={() => {
if (!isLoggedIn) {
setAuthModalOpen(true);
} else {
setIsPrescriptionModalOpen(true);
}
}}
/>
<Toaster position="top-center" expand={true} richColors closeButton />
</>
@@ -122,10 +122,10 @@ export default async function ShopProductPage({ params }: { params: Promise<{ sl
const productUrl = `${siteUrl}/shop/${resolvedParams.slug}`;
const priceInRial = product.priceValue * 10;
// Map stock status and packageSize to Schema.org availability
// Map stock status and stock quantity to Schema.org availability
const isOutOfStock =
product.stockStatus === 'OUT_OF_STOCK' ||
(typeof product.packageSize === 'number' && product.packageSize <= 0);
(typeof product.stock === 'number' && product.stock <= 0);
let availabilityUrl = 'https://schema.org/InStock';
if (product.stockStatus === 'DISCONTINUED') {
+12 -2
View File
@@ -250,7 +250,13 @@ export default function Header({
{/* Prescription Upload Button (Desktop & Mobile) */}
{isPrescriptionEnabled && (
<button
onClick={() => setIsPrescriptionModalOpen(true)}
onClick={() => {
if (!isLoggedIn) {
setIsAuthModalOpen(true);
} else {
setIsPrescriptionModalOpen(true);
}
}}
className="flex items-center gap-1.5 px-2.5 sm:px-3 py-2 bg-emerald-50 text-emerald-700 border border-emerald-200 hover:bg-emerald-100 rounded-xl text-[11px] sm:text-xs font-black transition-all shadow-xs cursor-pointer"
title="ثبت نسخه دامپزشک"
>
@@ -545,7 +551,11 @@ export default function Header({
type="button"
onClick={() => {
setIsMobileMenuOpen(false);
setIsPrescriptionModalOpen(true);
if (!isLoggedIn) {
setIsAuthModalOpen(true);
} else {
setIsPrescriptionModalOpen(true);
}
}}
className="w-full flex items-center justify-between p-3.5 bg-gradient-to-r from-emerald-500 to-teal-600 text-white rounded-2xl font-black text-xs shadow-md shadow-emerald-500/20 hover:brightness-105 transition-all cursor-pointer font-vazir"
>
@@ -348,17 +348,17 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
{/* 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
readOnly={isLoggedIn && !!profile?.mobile}
placeholder="۰۹۱۲۳۴۵۶۷۸۹"
value={phone}
onChange={(e) => setPhone(e.target.value)}
className="w-full bg-white border border-medical-gray-200 rounded-xl py-2.5 pr-3 pl-11 text-xs font-mono font-bold text-medical-gray-900 focus:outline-none focus:ring-2 focus:ring-canina-blue/20"
className={`w-full border border-medical-gray-200 rounded-xl py-2.5 pr-3 pl-11 text-xs font-mono font-bold text-medical-gray-900 focus:outline-none focus:ring-2 focus:ring-canina-blue/20 ${isLoggedIn && profile?.mobile ? 'bg-medical-gray-100 text-medical-gray-600 cursor-not-allowed' : 'bg-white'}`}
/>
<Phone className="w-4 h-4 text-medical-gray-400 absolute left-3.5 top-1/2 -translate-y-1/2 pointer-events-none" />
</div>
@@ -83,6 +83,7 @@ export interface Product {
metaDescription?: string;
canonicalUrl?: string;
keywords?: string;
stock?: number;
stockStatus?: 'IN_STOCK' | 'OUT_OF_STOCK' | 'PRE_ORDER' | 'DISCONTINUED';
noIndex?: boolean;
noFollow?: boolean;
+10 -4
View File
@@ -61,23 +61,26 @@ export const useCartStore = create<CartStore>()(
orders: [],
addItem: (product, quantity, dose) => {
// Prevent adding out-of-stock products
const maxStock = typeof product.stock === 'number' ? product.stock : (product.stockStatus === 'OUT_OF_STOCK' ? 0 : 999);
const isOutOfStock =
product.stockStatus === 'OUT_OF_STOCK' ||
product.stockStatus === 'DISCONTINUED' ||
(typeof product.packageSize === 'number' && product.packageSize <= 0);
maxStock <= 0;
if (isOutOfStock || quantity <= 0) {
return;
}
const items = get().items;
const existing = items.find((i) => i.product.id === product.id);
if (existing) {
const newQty = Math.min(existing.quantity + quantity, maxStock);
set({
items: items.map((i) =>
i.product.id === product.id ? { ...i, quantity: i.quantity + quantity } : i
i.product.id === product.id ? { ...i, quantity: newQty } : i
),
});
} else {
set({ items: [...items, { product, quantity, calculatedDose: dose }] });
const initialQty = Math.min(quantity, maxStock);
set({ items: [...items, { product, quantity: initialQty, calculatedDose: dose }] });
}
},
removeItem: (productId) => {
@@ -88,9 +91,12 @@ export const useCartStore = create<CartStore>()(
get().removeItem(productId);
return;
}
const currentItem = get().items.find((i) => i.product.id === productId);
const maxStock = currentItem && typeof currentItem.product.stock === 'number' ? currentItem.product.stock : 999;
const boundedQty = Math.min(quantity, maxStock);
set({
items: get().items.map((i) =>
i.product.id === productId ? { ...i, quantity } : i
i.product.id === productId ? { ...i, quantity: boundedQty } : i
),
});
},