bug fixed
This commit is contained in:
@@ -51,9 +51,7 @@ const AllProducts = () => {
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
params.set('page', newPage.toString());
|
||||
|
||||
router.push(`${pathname}?${params.toString()}`, {
|
||||
scroll: true,
|
||||
});
|
||||
router.push(`${pathname}?${params.toString()}`);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -42,8 +42,6 @@ const ProductDetail = () => {
|
||||
enabled: !!cart_id,
|
||||
});
|
||||
|
||||
/* ---------------- DERIVED DATA ---------------- */
|
||||
const price = Number(data?.prices?.[0]?.price || 0);
|
||||
const maxBalance = data?.balance ?? 0;
|
||||
|
||||
const measurement = data?.meansurement?.name?.toLowerCase() || '';
|
||||
@@ -162,7 +160,13 @@ const ProductDetail = () => {
|
||||
|
||||
/* ---------------- HANDLERS ---------------- */
|
||||
const handleAddToCart = () => {
|
||||
if (!data || !cart_id) return;
|
||||
if (!data || !cart_id) {
|
||||
toast.error(t('Tizimga kirilmagan'), {
|
||||
richColors: true,
|
||||
position: 'top-center',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedQty = clampQuantity(numericQty);
|
||||
|
||||
@@ -208,6 +212,10 @@ const ProductDetail = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const subtotal = data?.prices?.length
|
||||
? Math.min(...data.prices.map((p) => Number(p.price)))
|
||||
: 0;
|
||||
|
||||
/* ---------------- LOADING ---------------- */
|
||||
if (isLoading) {
|
||||
return (
|
||||
@@ -242,7 +250,7 @@ const ProductDetail = () => {
|
||||
|
||||
<div className="flex items-baseline gap-2 mb-4">
|
||||
<span className="text-4xl font-bold text-blue-600">
|
||||
{formatPrice(price, true)}
|
||||
{formatPrice(subtotal, true)}
|
||||
</span>
|
||||
<span className="text-xl text-gray-500">/{measurementDisplay}</span>
|
||||
</div>
|
||||
@@ -290,7 +298,7 @@ const ProductDetail = () => {
|
||||
</div>
|
||||
|
||||
<div className="mb-6 text-xl font-semibold">
|
||||
{t('Jami')}: {formatPrice(price * numericQty, true)}
|
||||
{t('Jami')}: {formatPrice(subtotal * numericQty, true)}
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3">
|
||||
|
||||
@@ -243,7 +243,7 @@ export function ProductCard({
|
||||
{product.prices.length > 0 && (
|
||||
<p className="text-lg font-bold">
|
||||
{formatPrice(
|
||||
Math.max(...product.prices.map((p) => Number(p.price))),
|
||||
Math.min(...product.prices.map((p) => Number(p.price))),
|
||||
true,
|
||||
)}
|
||||
<span className="text-sm text-slate-500 ml-1">
|
||||
|
||||
@@ -132,6 +132,7 @@ export const SearchResult = ({ query }: SearchResultProps) => {
|
||||
<p className="text-sm font-semibold text-[#57A595] mt-1">
|
||||
{formatPrice(
|
||||
Math.min(...product.prices.map((p) => Number(p.price))),
|
||||
true,
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user