diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-08-15 09:48:06 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-08-15 09:48:06 +0700 |
| commit | 9159b649258703ea0539ea958cdf8b3c5987e474 (patch) | |
| tree | 185e6f1d6c01a9f6fae97d016a28cb47b19b9d85 /src/lib/transaction | |
| parent | d90fe88740674de2a5dcc4a06a93c71884bb8262 (diff) | |
<hafid> fix alur repeat order
Diffstat (limited to 'src/lib/transaction')
| -rw-r--r-- | src/lib/transaction/components/Transactions.jsx | 39 |
1 files changed, 21 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'); } }; |
