summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-08-15 09:48:06 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-08-15 09:48:06 +0700
commit9159b649258703ea0539ea958cdf8b3c5987e474 (patch)
tree185e6f1d6c01a9f6fae97d016a28cb47b19b9d85
parentd90fe88740674de2a5dcc4a06a93c71884bb8262 (diff)
<hafid> fix alur repeat order
-rw-r--r--src/lib/transaction/components/Transactions.jsx39
-rw-r--r--src/pages/my/profile.jsx1
2 files changed, 22 insertions, 18 deletions
diff --git a/src/lib/transaction/components/Transactions.jsx b/src/lib/transaction/components/Transactions.jsx
index de93d742..2596b47f 100644
--- a/src/lib/transaction/components/Transactions.jsx
+++ b/src/lib/transaction/components/Transactions.jsx
@@ -345,8 +345,6 @@ const Transactions = ({ context = '' }) => {
}, []);
const handleBuyBack = async (products) => {
- // if (status === 'success') return;
-
try {
// setStatus('loading');
@@ -358,32 +356,37 @@ const Transactions = ({ context = '' }) => {
id: product.id,
qty: product.quantity,
selected: true,
- source: 'buy', // Tetap gunakan 'buy' agar bisa masuk ke halaman pembelian
+ source: 'buy',
qtyAppend: false,
+ }).catch(error => {
+ return { error, product };
})
)
);
- // ✅ Panggil setRefreshCart(true) setiap kali satu produk berhasil ditambahkan
+ const failedOperations = results.filter(result => result && result.error);
+
+ if (failedOperations.length > 0) {
+ console.error('Some products failed to add to cart:', failedOperations);
+ toast.error(`${failedOperations.length} produk gagal ditambahkan ke keranjang`);
+
+ // You might want to proceed with the successful ones or handle differently
+ if (failedOperations.length < products.length) {
+ toast.success(`${products.length - failedOperations.length} produk berhasil ditambahkan ke keranjang`);
+ setRefreshCart(true);
+ router.push('/shop/cart');
+ }
+ return;
+ }
+ // All operations succeeded
setRefreshCart(true);
-
- // setStatus('idle');
toast.success('Semua produk berhasil ditambahkan ke keranjang belanja');
- // Tampilkan notifikasi
- // toast({
- // title: 'Tambah ke keranjang',
- // description: 'Semua produk berhasil ditambahkan ke keranjang belanja',
- // status: 'success',
- // duration: 3000,
- // isClosable: true,
- // position: 'top',
- // });
-
- // Redirect ke halaman checkout
- router.push('/shop/checkout?source=buy');
+ router.push('/shop/cart');
+
} catch (error) {
console.error('Gagal menambahkan produk ke keranjang:', error);
+ toast.error('Terjadi kesalahan saat menambahkan produk ke keranjang');
// setStatus('error');
}
};
diff --git a/src/pages/my/profile.jsx b/src/pages/my/profile.jsx
index 859b6960..1b449e2d 100644
--- a/src/pages/my/profile.jsx
+++ b/src/pages/my/profile.jsx
@@ -41,6 +41,7 @@ export default function Profile() {
setChangeConfirmation(false);
setIsChecked(true);
};
+ console.log('auth : ', auth);
return (
<>
<BottomPopup