diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2024-01-22 10:41:53 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2024-01-22 10:41:53 +0700 |
| commit | fb80b92d502437160e45b237b380071ab102c838 (patch) | |
| tree | 7af89af778f0038dbd8f984d360d009c700c6c71 | |
| parent | e49eba371229a643588d49d7ef408b6ef9469d53 (diff) | |
Update disable checkout when has product price 0 and fix filter brand
| -rw-r--r-- | src-migrate/modules/cart/components/Detail.tsx | 85 | ||||
| -rw-r--r-- | src-migrate/modules/cart/components/Item.tsx | 3 | ||||
| -rw-r--r-- | src-migrate/pages/shop/cart/index.tsx | 16 | ||||
| -rw-r--r-- | src-migrate/services/checkout.ts | 4 | ||||
| -rw-r--r-- | src/lib/checkout/components/Checkout.jsx | 22 | ||||
| -rw-r--r-- | src/pages/api/shop/brands.js | 50 |
6 files changed, 60 insertions, 120 deletions
diff --git a/src-migrate/modules/cart/components/Detail.tsx b/src-migrate/modules/cart/components/Detail.tsx deleted file mode 100644 index b1532729..00000000 --- a/src-migrate/modules/cart/components/Detail.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import style from '../styles/detail.module.css' - -import React, { useEffect, useMemo } from 'react' -import Link from 'next/link' -import { Button, Tooltip } from '@chakra-ui/react' - -import { getAuth } from '~/libs/auth' -import { useCartStore } from '../stores/useCartStore' - -import CartItem from './Item' -import CartSummary from './Summary' - -const CartDetail = () => { - const auth = getAuth() - - const { loadCart, cart, summary } = useCartStore() - - useEffect(() => { - if (typeof auth === 'object' && !cart) loadCart(auth.id) - }, [auth, loadCart, cart]) - - const hasSelectedPromo = useMemo(() => { - if (!cart) return false - for (const item of cart.products) { - if (item.cart_type === 'promotion' && item.selected) return true - } - return false - }, [cart]) - - const hasSelected = useMemo(() => { - if (!cart) return false - for (const item of cart.products) { - if (item.selected) return true - } - return false - }, [cart]) - - return ( - <div className={style.wrapper}> - <div className='w-full md:w-3/4'> - <div className=''> - <div className='text-h-lg font-semibold mb-6'>Keranjang Belanja</div> - <div className='grid grid-cols-1 gap-y-4'> - {!cart && <CartItem.Skeleton count={5} height='120px' />} - </div> - <div className='flex flex-col gap-y-8 border-t border-gray-300 pt-8'> - {cart?.products.map((item) => <CartItem key={item.id} item={item} />)} - </div> - </div> - </div> - - <div className='w-full md:w-1/4 md:pl-6 mt-6 md:mt-0'> - <div className='border border-gray-300 p-4 rounded-md sticky top-[180px]'> - <CartSummary {...summary} isLoaded={!!cart} /> - <div className='grid grid-cols-2 gap-x-3 mt-6'> - <Tooltip label={hasSelectedPromo ? 'Barang promo tidak dapat dibuat quotation' : ''}> - <Button - colorScheme='yellow' - w='full' - isDisabled={hasSelectedPromo || !hasSelected} - as={Link} - href='/shop/quotation' - > - Quotation - </Button> - </Tooltip> - <Tooltip label={hasSelected ? '' : 'Tidak ada item yang dipilih'}> - <Button - colorScheme='red' - w='full' - isDisabled={!hasSelected} - as={Link} - href='/shop/checkout' - > - Checkout - </Button> - </Tooltip> - </div> - </div> - </div> - </div> - ) -} - -export default CartDetail
\ No newline at end of file diff --git a/src-migrate/modules/cart/components/Item.tsx b/src-migrate/modules/cart/components/Item.tsx index 08823d19..48e568e0 100644 --- a/src-migrate/modules/cart/components/Item.tsx +++ b/src-migrate/modules/cart/components/Item.tsx @@ -70,7 +70,8 @@ const CartItem = ({ item, editable = true }: Props) => { {item.cart_type === 'product' && ( <> <div className={style.price}> - Rp {formatCurrency(item.price.price)} + {item.price.price > 0 && `Rp ${formatCurrency(item.price.price)}`} + {item.price.price === 0 && '-'} </div> <div>{item.code}</div> </> diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index 397852f9..9ec58a48 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -9,6 +9,7 @@ import { useCartStore } from '~/modules/cart/stores/useCartStore' import CartItem from '~/modules/cart/components/Item' import CartSummary from '~/modules/cart/components/Summary' +import clsxm from '~/libs/clsxm' const CartPage = () => { const auth = getAuth() @@ -35,6 +36,14 @@ const CartPage = () => { return false }, [cart]) + const hasSelectNoPrice = useMemo(() => { + if (!cart) return false + for (const item of cart.products) { + if (item.selected && item.price.price_discount == 0) return true + } + return false + }, [cart]) + return ( <> <div className={style['title']}> @@ -71,11 +80,14 @@ const CartPage = () => { </Button> </Tooltip> - <Tooltip label={!hasSelected && 'Tidak ada item yang dipilih'}> + <Tooltip label={clsxm({ + 'Tidak ada item yang dipilih': !hasSelected, + 'Terdapat item yang tidak ada harga': hasSelectNoPrice + })}> <Button colorScheme='red' w='full' - isDisabled={!hasSelected} + isDisabled={!hasSelected || hasSelectNoPrice} as={Link} href='/shop/checkout' > diff --git a/src-migrate/services/checkout.ts b/src-migrate/services/checkout.ts index 3eff95a8..e6642ccb 100644 --- a/src-migrate/services/checkout.ts +++ b/src-migrate/services/checkout.ts @@ -2,6 +2,4 @@ import odooApi from '~/libs/odooApi'; export const getUserCheckout = async (userId: number) => { return await odooApi('GET', `/api/v1/user/${userId}/sale_order/checkout`); -}; - -// /api/v1/user/${id}/sale_order/checkout?voucher=${voucher}
\ No newline at end of file +};
\ No newline at end of file diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index eb31b9dc..85eda80b 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -10,7 +10,7 @@ import { ClockIcon, ExclamationCircleIcon, } from '@heroicons/react/24/outline'; -import React, { useEffect, useRef, useState } from 'react'; +import React, { useEffect, useMemo, useRef, useState } from 'react'; import _ from 'lodash'; import { deleteItemCart } from '@/core/utils/cart'; import currencyFormat from '@/core/utils/currencyFormat'; @@ -411,6 +411,14 @@ const Checkout = () => { }; // const taxTotal = (totalAmount - totalDiscountAmount - discountVoucher) * 0.11 + const hasNoPrice = useMemo(() => { + if (!products) return false; + for (const item of products) { + if (item.price.priceDiscount == 0) return true; + } + return false; + }, [products]); + return ( <> <BottomPopup @@ -995,7 +1003,11 @@ const Checkout = () => { className='flex-1 btn-yellow' onClick={checkout} disabled={ - isLoading || !products || products?.length == 0 || priceCheck + isLoading || + !products || + products?.length == 0 || + priceCheck || + hasNoPrice } > {isLoading ? 'Loading...' : 'Lanjut Pembayaran'} @@ -1090,8 +1102,7 @@ const Checkout = () => { <div className='flex justify-between items-center'> <div className='font-medium'>Ringkasan Pesanan</div> <div className='text-gray_r-11 text-caption-1'> - {cartCheckout?.totalWeight.kg}{' '} - Kg + {cartCheckout?.totalWeight.kg} Kg </div> </div> @@ -1283,7 +1294,8 @@ const Checkout = () => { isLoading || !products || products?.length == 0 || - priceCheck + priceCheck || + hasNoPrice } > {isLoading ? 'Loading...' : 'Lanjut Pembayaran'} diff --git a/src/pages/api/shop/brands.js b/src/pages/api/shop/brands.js index dbbfcfe3..1217aa48 100644 --- a/src/pages/api/shop/brands.js +++ b/src/pages/api/shop/brands.js @@ -1,36 +1,38 @@ -import axios from 'axios' +import axios from 'axios'; + +const SOLR_HOST = process.env.SOLR_HOST; export default async function handler(req, res) { try { - let params = '*:*' - let sort = 'sort=if(exists(sequence_i),0,1) asc,sequence_i asc, if(exists(image_s),0,1) asc ' - let rows = 2000 + let params = '*:*'; + let sort = + 'sort=if(exists(sequence_i),0,1) asc,sequence_i asc, if(exists(image_s),0,1) asc '; + let rows = 2000; if (req.query.params) { - rows = 100 + rows = 100; switch (req?.query?.params) { case 'level_s': - params = 'level_s:prioritas' - break + params = 'level_s:prioritas'; + break; case 'search': - params = `name_s:${req?.query?.q.toLowerCase()}` - sort = '' - rows = 1 + params = `name_s:${req?.query?.q.toLowerCase()}`; + sort = ''; + rows = 1; break; default: - params = `name_s:${req.query.params}` + params = `name_s:${req.query.params}`.toLowerCase(); } } - let brands = await axios( - process.env.SOLR_HOST + - `/solr/brands/select?q=${params}&q.op=OR&indent=true&rows=${rows}&${sort}` - ) - let dataBrands = responseMap(brands.data.response.docs) + const url = `${SOLR_HOST}/solr/brands/select?q=${params}&q.op=OR&indent=true&rows=${rows}&${sort}`; + console.log(url); + let brands = await axios(url); + let dataBrands = responseMap(brands.data.response.docs); - res.status(200).json(dataBrands) + res.status(200).json(dataBrands); } catch (error) { - console.error('Error fetching data from Solr:', error) - res.status(500).json({ error: 'Internal Server Error' }) + console.error('Error fetching data from Solr:', error); + res.status(500).json({ error: 'Internal Server Error' }); } } @@ -40,9 +42,9 @@ const responseMap = (brands) => { id: brand.id, name: brand.display_name_s, logo: brand.image_s || '', - sequance: brand.sequence_i || '' - } + sequance: brand.sequence_i || '', + }; - return brandMapping - }) -} + return brandMapping; + }); +}; |
