bug fixed

This commit is contained in:
Samandar Turgunboyev
2026-02-25 13:20:18 +05:00
parent ed5ee752c9
commit 4d35b8f6d1
4 changed files with 16 additions and 9 deletions

View File

@@ -51,9 +51,7 @@ const AllProducts = () => {
const params = new URLSearchParams(searchParams.toString()); const params = new URLSearchParams(searchParams.toString());
params.set('page', newPage.toString()); params.set('page', newPage.toString());
router.push(`${pathname}?${params.toString()}`, { router.push(`${pathname}?${params.toString()}`);
scroll: true,
});
}; };
return ( return (

View File

@@ -42,8 +42,6 @@ const ProductDetail = () => {
enabled: !!cart_id, enabled: !!cart_id,
}); });
/* ---------------- DERIVED DATA ---------------- */
const price = Number(data?.prices?.[0]?.price || 0);
const maxBalance = data?.balance ?? 0; const maxBalance = data?.balance ?? 0;
const measurement = data?.meansurement?.name?.toLowerCase() || ''; const measurement = data?.meansurement?.name?.toLowerCase() || '';
@@ -162,7 +160,13 @@ const ProductDetail = () => {
/* ---------------- HANDLERS ---------------- */ /* ---------------- HANDLERS ---------------- */
const handleAddToCart = () => { 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); 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 ---------------- */ /* ---------------- LOADING ---------------- */
if (isLoading) { if (isLoading) {
return ( return (
@@ -242,7 +250,7 @@ const ProductDetail = () => {
<div className="flex items-baseline gap-2 mb-4"> <div className="flex items-baseline gap-2 mb-4">
<span className="text-4xl font-bold text-blue-600"> <span className="text-4xl font-bold text-blue-600">
{formatPrice(price, true)} {formatPrice(subtotal, true)}
</span> </span>
<span className="text-xl text-gray-500">/{measurementDisplay}</span> <span className="text-xl text-gray-500">/{measurementDisplay}</span>
</div> </div>
@@ -290,7 +298,7 @@ const ProductDetail = () => {
</div> </div>
<div className="mb-6 text-xl font-semibold"> <div className="mb-6 text-xl font-semibold">
{t('Jami')}: {formatPrice(price * numericQty, true)} {t('Jami')}: {formatPrice(subtotal * numericQty, true)}
</div> </div>
<div className="flex gap-3"> <div className="flex gap-3">

View File

@@ -243,7 +243,7 @@ export function ProductCard({
{product.prices.length > 0 && ( {product.prices.length > 0 && (
<p className="text-lg font-bold"> <p className="text-lg font-bold">
{formatPrice( {formatPrice(
Math.max(...product.prices.map((p) => Number(p.price))), Math.min(...product.prices.map((p) => Number(p.price))),
true, true,
)} )}
<span className="text-sm text-slate-500 ml-1"> <span className="text-sm text-slate-500 ml-1">

View File

@@ -132,6 +132,7 @@ export const SearchResult = ({ query }: SearchResultProps) => {
<p className="text-sm font-semibold text-[#57A595] mt-1"> <p className="text-sm font-semibold text-[#57A595] mt-1">
{formatPrice( {formatPrice(
Math.min(...product.prices.map((p) => Number(p.price))), Math.min(...product.prices.map((p) => Number(p.price))),
true,
)} )}
</p> </p>
)} )}