diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/quotation/components/Quotation.jsx | 7 | ||||
| -rw-r--r-- | src/lib/quotation/components/Quotationheader.jsx | 38 |
2 files changed, 39 insertions, 6 deletions
diff --git a/src/lib/quotation/components/Quotation.jsx b/src/lib/quotation/components/Quotation.jsx index df234dc2..3fac6f29 100644 --- a/src/lib/quotation/components/Quotation.jsx +++ b/src/lib/quotation/components/Quotation.jsx @@ -9,6 +9,7 @@ import _ from 'lodash'; import { deleteItemCart, getCart, getItemCart } from '@/core/utils/cart'; import currencyFormat from '@/core/utils/currencyFormat'; import { toast } from 'react-hot-toast'; +import { useProductCartContext } from '@/contexts/ProductCartContext'; // import checkoutApi from '@/lib/checkout/api/checkoutApi' import { useRouter } from 'next/router'; import VariantGroupCard from '@/lib/variant/components/VariantGroupCard'; @@ -38,11 +39,12 @@ const { getProductsCheckout } = require('@/lib/checkout/api/checkoutApi'); const Quotation = () => { const router = useRouter(); const auth = useAuth(); - + const { data: cartCheckout } = useQuery('cartCheckout', () => getProductsCheckout() - ); +); +const { setRefreshQuotation } = useProductCartContext(); const SELF_PICKUP_ID = 32; const [products, setProducts] = useState(null); @@ -293,6 +295,7 @@ const Quotation = () => { if (isSuccess?.id) { for (const product of products) deleteItemCart({ productId: product.id }); router.push(`/shop/quotation/finish?id=${isSuccess.id}`); + setRefreshQuotation(true); return; } diff --git a/src/lib/quotation/components/Quotationheader.jsx b/src/lib/quotation/components/Quotationheader.jsx index 79011682..14743fd6 100644 --- a/src/lib/quotation/components/Quotationheader.jsx +++ b/src/lib/quotation/components/Quotationheader.jsx @@ -30,6 +30,7 @@ const Quotationheader = (quotationCount) => { const [isHovered, setIsHovered] = useState(false); const [isTop, setIsTop] = useState(true); + const qotation = useMemo(() => { return productQuotation || []; }, [productQuotation]); @@ -49,6 +50,7 @@ const Quotationheader = (quotationCount) => { } }; let { transactions } = useTransactions({ query }); + const refreshCartf = useCallback(async () => { setIsloading(true); let pendingTransactions = transactions?.data?.saleOrders.filter(transaction => transaction.status === 'draft'); @@ -58,6 +60,18 @@ const Quotationheader = (quotationCount) => { }, [setProductQuotation, setIsloading]); useEffect(() => { + if (!qotation) return + + let calculateTotalDiscountAmount = 0 + for (const product of qotation) { + // if (qotation.quantity == '') continue + calculateTotalDiscountAmount += product.amountUntaxed + } + let subTotal = calculateTotalDiscountAmount + setSubTotal(subTotal) + }, [qotation]) + + useEffect(() => { if (refreshQuotation) { refreshCartf(); } @@ -84,8 +98,6 @@ const Quotationheader = (quotationCount) => { router.push('/shop/quotation'); }; - console.log("quotation",qotation) - return ( <div className='relative group'> <div> @@ -211,8 +223,8 @@ const Quotationheader = (quotationCount) => { </div> <div className='my-0.5 h-0.5 bg-gray-200'></div> <div className='bagian bawah flex justify-between mt-2'> - <p className='font-semibold text-base'>Total</p> - <p className='font-semibold text-base'>{currencyFormat(product.amountTotal)}</p> + <p className='font-semibold text-sm'>Total</p> + <p className='font-semibold text-sm'>{currencyFormat(product.amountUntaxed)}</p> </div> </Link> </div> @@ -224,6 +236,24 @@ const Quotationheader = (quotationCount) => { </> )} </div> + {auth && qotation.length > 0 && !isLoading && ( + <> + <div className='mt-3'> + <span className='text-gray-400 text-caption-2'>Subtotal Sebelum PPN : </span> + <span className='font-semibold text-red-600'>{currencyFormat(subTotal)}</span> + </div> + <div className='mt-5 mb-2'> + <button + type='button' + className='btn-yellow rounded-lg w-full' + onClick={handleCheckout} + disabled={buttonLoading} + > + {buttonLoading ? 'Loading...' : 'Buat Quotation'} + </button> + </div> + </> + )} </motion.div> </motion.div> </> |
