diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-08-04 14:31:11 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-08-04 14:31:11 +0700 |
| commit | 09d0c6d00a30189530dee12a5a3c7c6b1409f6fe (patch) | |
| tree | 53bc096aca2c7fa611106ddf14e1fa5eb69c4814 /src/lib | |
| parent | 71748842100e833472c56194e57c309539478dd3 (diff) | |
| parent | f862f6426c28fb9245d13fb7386a88b209639d64 (diff) | |
Merge branch 'master' into CR/voucher
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/checkout/api/getVoucher.js | 18 | ||||
| -rw-r--r-- | src/lib/checkout/components/Checkout.jsx | 6 | ||||
| -rw-r--r-- | src/lib/product/components/Product/ProductDesktop.jsx | 16 |
3 files changed, 30 insertions, 10 deletions
diff --git a/src/lib/checkout/api/getVoucher.js b/src/lib/checkout/api/getVoucher.js index 57d8acf5..07cf376e 100644 --- a/src/lib/checkout/api/getVoucher.js +++ b/src/lib/checkout/api/getVoucher.js @@ -1,11 +1,21 @@ import odooApi from '@/core/api/odooApi' -export const getVoucher = async (id) => { - const dataVoucher = await odooApi('GET', `/api/v1/user/${id}/voucher`) +export const getVoucher = async (id, source) => { + let dataVoucher = null + if(source){ + dataVoucher = await odooApi('GET', `/api/v1/user/${id}/voucher?source=${source}`) + }else { + dataVoucher = await odooApi('GET', `/api/v1/user/${id}/voucher`) + } return dataVoucher } -export const findVoucher = async (code, id) => { - const dataVoucher = await odooApi('GET', `/api/v1/user/${id}/voucher?code=${code}`) +export const findVoucher = async (code, id, source) => { + let dataVoucher = null + if(source){ + dataVoucher = await odooApi('GET', `/api/v1/user/${id}/voucher?code=${code}&source=${source}`) + }else{ + dataVoucher = await odooApi('GET', `/api/v1/user/${id}/voucher?code=${code}`) + } return dataVoucher } diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 5265a794..cfd95a89 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -107,7 +107,7 @@ const Checkout = () => { const voucher = async () => { if (!listVouchers) { try { - let dataVoucher = await getVoucher(auth?.id) + let dataVoucher = await getVoucher(auth?.id, query) SetListVoucher(dataVoucher) } finally { setLoadingVoucher(false) @@ -115,7 +115,7 @@ const Checkout = () => { } } const VoucherCode = async (code) => { - let dataVoucher = await findVoucher(code, auth.id) + let dataVoucher = await findVoucher(code, auth.id, query) if (dataVoucher.length <= 0) { SetFindVoucher(1) return @@ -427,7 +427,7 @@ const Checkout = () => { <hr className='mt-10 my-4 border-gray_r-10' /> <div className=''> - {!loadingVoucher && listVouchers.length === 0 ? ( + {!loadingVoucher && listVouchers?.length === 0 ? ( <div className='flex items-center justify-center mt-4 mb-4'> <div className='text-center'> <h1 className='font-bold mb-4'>Tidak ada voucher tersedia</h1> diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 7e1d0d3b..372ad3ba 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -54,9 +54,10 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { const setVariantQuantityRef = (variantId) => (element) => { if (element) { let variantIndex = product.variants.findIndex((varian) => varian.id == variantId) - product.variants[variantIndex].quantity = element.value + product.variants[variantIndex].quantity = element?.value } variantQuantityRefs.current[variantId] = element + } const validQuantity = (quantity) => { @@ -106,6 +107,15 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { setAddCartAlert(true) } + const handleQuantityChange = (variantId) => (event) => { + const { value } = event.target; + const variantIndex = product.variants.findIndex((variant) => variant.id === variantId); + if (variantIndex !== -1) { + product.variants[variantIndex].quantity = parseInt(value, 10); // Pastikan untuk mengubah ke tipe number jika diperlukan + // Lakukan sesuatu jika nilai quantity diubah + } + }; + const handleBuy = (variant) => { const quantity = variantQuantityRefs.current[variant].value if (!validQuantity(quantity)) return @@ -412,7 +422,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { type='number' className='form-input w-16 py-2 text-center bg-gray_r-1' ref={setVariantQuantityRef(product.variants[0].id)} - onChange={setVariantQuantityRef(product.variants[0].id)} + onChange={handleQuantityChange(product.variants[0].id)} defaultValue={1} /> <button @@ -579,7 +589,7 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { type='number' className='form-input w-16 py-2 text-center bg-gray_r-1' ref={setVariantQuantityRef(variant.id)} - onChange={setVariantQuantityRef(variant.id)} + onChange={handleQuantityChange(variant.id)} defaultValue={1} /> </td> |
