removed stok quantity, added hide/show function to brand field

This commit is contained in:
Jelaletdin12
2026-02-01 21:50:41 +05:00
parent a143c2e18b
commit fcb016589b
3 changed files with 19 additions and 25 deletions

View File

@@ -100,7 +100,7 @@ const Footer = () => {
</div> </div>
</div> </div>
<div className={styles.bottom}> <div className={styles.bottom}>
<p> © 2019-2025 mm.com.tm {t("footer.copyright")}</p> <p> © 2019-2026 mm.com.tm {t("footer.copyright")}</p>
</div> </div>
</footer> </footer>
<FooterBar /> <FooterBar />

View File

@@ -198,7 +198,6 @@ const CartPage = () => {
const item = cartItems.find((item) => item.product.id === productId); const item = cartItems.find((item) => item.product.id === productId);
if (!item) return; if (!item) return;
// ✅ Stock kontrolü
if (localQuantities[productId] >= item.product.stock) { if (localQuantities[productId] >= item.product.stock) {
return; return;
} }
@@ -222,7 +221,6 @@ const CartPage = () => {
const currentQuantity = localQuantities[productId] || 0; const currentQuantity = localQuantities[productId] || 0;
// ✅ 1'den azsa modal göster
if (currentQuantity <= 1) { if (currentQuantity <= 1) {
showDeleteConfirm(productId); showDeleteConfirm(productId);
return; return;
@@ -267,7 +265,6 @@ const CartPage = () => {
if (checkoutStores[storeId] && checkoutRefs.current[storeId]) { if (checkoutStores[storeId] && checkoutRefs.current[storeId]) {
const success = await checkoutRefs.current[storeId](); const success = await checkoutRefs.current[storeId]();
if (success) { if (success) {
// ✅ RTK Query otomatik güncelleyecek, refetch'e gerek yok
setCheckoutStores(prev => ({ ...prev, [storeId]: false })); setCheckoutStores(prev => ({ ...prev, [storeId]: false }));
} }
} else { } else {
@@ -295,9 +292,7 @@ const CartPage = () => {
if (itemToDelete) { if (itemToDelete) {
try { try {
await removeFromCart({ productId: itemToDelete }).unwrap(); await removeFromCart({ productId: itemToDelete }).unwrap();
// ✅ RTK Query otomatik cache'i güncelleyecek
// ✅ Local state'i de temizle
setLocalQuantities((prev) => { setLocalQuantities((prev) => {
const newState = { ...prev }; const newState = { ...prev };
delete newState[itemToDelete]; delete newState[itemToDelete];

View File

@@ -58,7 +58,7 @@ const ProductPage = ({
const { data: favoriteProducts = [], refetch } = useGetFavoritesQuery(); const { data: favoriteProducts = [], refetch } = useGetFavoritesQuery();
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [localIsFavorite, setLocalIsFavorite] = useState( const [localIsFavorite, setLocalIsFavorite] = useState(
favoriteProducts.some((fav) => fav.product?.id === product?.id) favoriteProducts.some((fav) => fav.product?.id === product?.id),
); );
const { data: cartData } = useGetCartQuery(undefined, { const { data: cartData } = useGetCartQuery(undefined, {
selectFromResult: (result) => ({ selectFromResult: (result) => ({
@@ -78,7 +78,7 @@ const ProductPage = ({
return allCartItems.find( return allCartItems.find(
(item) => (item) =>
item.product?.id === product?.id || item.product_id === product?.id item.product?.id === product?.id || item.product_id === product?.id,
); );
}; };
@@ -98,7 +98,7 @@ const ProductPage = ({
useEffect(() => { useEffect(() => {
if (Array.isArray(favoriteProducts)) { if (Array.isArray(favoriteProducts)) {
const isFav = favoriteProducts.some( const isFav = favoriteProducts.some(
(fav) => fav.product?.id === product?.id (fav) => fav.product?.id === product?.id,
); );
setLocalIsFavorite(isFav); setLocalIsFavorite(isFav);
} }
@@ -141,16 +141,15 @@ const ProductPage = ({
return; return;
} }
// Badge sayısını anında güncelle
setLocalQuantity((prev) => prev + 1); setLocalQuantity((prev) => prev + 1);
setPendingQuantity((prev) => prev + 1); // Hemen güncelle setPendingQuantity((prev) => prev + 1);
try { try {
await addToCart({ productId: product.id, quantity: 1 }).unwrap(); await addToCart({ productId: product.id, quantity: 1 }).unwrap();
} catch (error) { } catch (error) {
console.error("Failed to add to cart:", error); console.error("Failed to add to cart:", error);
setLocalQuantity((prev) => prev - 1); // Başarısız olursa geri al setLocalQuantity((prev) => prev - 1);
setPendingQuantity((prev) => prev - 1); // Başarısız olursa geri al setPendingQuantity((prev) => prev - 1);
} }
}; };
@@ -300,18 +299,18 @@ const ProductPage = ({
</span> </span>
<span className={styles.metaValue}>{product.id}</span> <span className={styles.metaValue}>{product.id}</span>
</div> </div>
<div className={styles.metaItem}> {product.barcode && (
<span className={styles.metaLabel}>{t("product.barCode")}</span> <div className={styles.metaItem}>
<span className={styles.metaValue}>{product.barcode}</span> <span className={styles.metaLabel}>{t("product.barCode")}</span>
</div> <span className={styles.metaValue}>{product.barcode}</span>
<div className={styles.metaItem}> </div>
<span className={styles.metaLabel}>Brand</span> )}
<span className={styles.metaValue}>{product.brand.name}</span> {product.brand?.name && (
</div> <div className={styles.metaItem}>
<div className={styles.metaItem}> <span className={styles.metaLabel}>{t("order.brand")}</span>
<span className={styles.metaLabel}>Stokta</span> <span className={styles.metaValue}>{product.brand.name}</span>
<span className={styles.metaValue}>{product.stock}</span> </div>
</div> )}
</div> </div>
<div className={styles.productActions}> <div className={styles.productActions}>
<div className={styles.priceContainer}> <div className={styles.priceContainer}>