summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-08 11:37:58 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-08 11:37:58 +0700
commitbad8abd263bd43c59dad8e61e2f5f35bfe5b7746 (patch)
tree14d92d40644cec6e885f47c3932666b5e7abfc22
parent86c880442fc0abbc4c356da4fa8a20bc5759aff3 (diff)
<iman> update quotation pop up
-rw-r--r--src-migrate/modules/product-detail/components/AddToCart.tsx1
-rw-r--r--src/lib/quotation/components/Quotation.jsx7
-rw-r--r--src/lib/quotation/components/Quotationheader.jsx38
3 files changed, 39 insertions, 7 deletions
diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx
index bebc793f..2f87311f 100644
--- a/src-migrate/modules/product-detail/components/AddToCart.tsx
+++ b/src-migrate/modules/product-detail/components/AddToCart.tsx
@@ -65,7 +65,6 @@ const AddToCart = ({
) return;
setRefreshCart(true);
- // console.log('Refresh cart triggered');
setAddCartAlert(true);
toast.promise(
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>
</>