diff options
Diffstat (limited to 'src/lib/quotation/components/Quotation.jsx')
| -rw-r--r-- | src/lib/quotation/components/Quotation.jsx | 104 |
1 files changed, 57 insertions, 47 deletions
diff --git a/src/lib/quotation/components/Quotation.jsx b/src/lib/quotation/components/Quotation.jsx index df234dc2..cf0ad41f 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'; @@ -43,6 +44,7 @@ const Quotation = () => { getProductsCheckout() ); + const { setRefreshCart } = useProductCartContext(); const SELF_PICKUP_ID = 32; const [products, setProducts] = useState(null); @@ -67,18 +69,18 @@ const Quotation = () => { const [selectedExpedisiService, setselectedExpedisiService] = useState(null); const [etd, setEtd] = useState(null); const [etdFix, setEtdFix] = useState(null); - + const [isApproval, setIsApproval] = useState(false); - + const expedisiValidation = useRef(null); - + const [selectedAddress, setSelectedAddress] = useState({ shipping: null, invoicing: null, }); - + const [addresses, setAddresses] = useState(null); - + const [note_websiteText, setselectedNote_websiteText] = useState(''); useEffect(() => { @@ -97,6 +99,9 @@ const Quotation = () => { if (!addresses) return; const matchAddress = (key) => { + if (key === 'invoicing') { + key = 'invoice'; + } const addressToMatch = getItemAddress(key); const foundAddress = addresses.filter( (address) => address.id == addressToMatch @@ -269,7 +274,7 @@ const Quotation = () => { toast.error('Maaf, Note wajib dimasukkan.'); return; } - + setIsLoading(true); const productOrder = products.map((product) => ({ product_id: product.id, @@ -284,18 +289,18 @@ const Quotation = () => { carrier_id: selectedCarrierId, estimated_arrival_days: splitDuration(etd), delivery_service_type: selectedExpedisiService, - note_website : note_websiteText, + note_website: note_websiteText, }; - + const isSuccess = await checkoutApi({ data }); - ; setIsLoading(false); if (isSuccess?.id) { for (const product of products) deleteItemCart({ productId: product.id }); router.push(`/shop/quotation/finish?id=${isSuccess.id}`); + setRefreshCart(true); return; } - + toast.error('Gagal melakukan transaksi, terjadi kesalahan internal'); }; @@ -452,25 +457,26 @@ const Quotation = () => { </Link>{' '} yang berlaku </p> - <hr className='my-4 border-gray_r-6' /> - - <div className='flex gap-x-2 justify-start mb-4'> - <div className=''>Note</div> - {isApproval && ( - <div className='text-caption-1 text-red-500 items-center flex'>*harus diisi</div> - )} - </div> - <div className='text-caption-2 text-gray_r-11'> - <textarea - rows="4" - cols="50" - className={`w-full p-1 rounded border border-gray_r-6`} - onChange={(e) => setselectedNote_websiteText(e.target.value)} - /> - </div> + <hr className='my-4 border-gray_r-6' /> + + <div className='flex gap-x-2 justify-start mb-4'> + <div className=''>Note</div> + {isApproval && ( + <div className='text-caption-1 text-red-500 items-center flex'> + *harus diisi + </div> + )} + </div> + <div className='text-caption-2 text-gray_r-11'> + <textarea + rows='4' + cols='50' + className={`w-full p-1 rounded border border-gray_r-6`} + onChange={(e) => setselectedNote_websiteText(e.target.value)} + /> + </div> </div> - - + <Divider /> <div className='flex gap-x-3 p-4'> @@ -603,27 +609,31 @@ const Quotation = () => { yang berlaku </p> - <div> - <hr className='my-4 border-gray_r-6' /> - - <div className='flex gap-x-1 flex-col mb-4'> - <div className='flex flex-row gap-x-1'> - <div className=''>Note</div> - {isApproval && ( - <div className='text-caption-1 text-red-500 items-center flex'>*harus diisi</div> - )} - </div> - <div className='text-caption-2 text-gray_r-11'> - <textarea - rows="4" - cols="50" - className={`w-full p-1 rounded border border-gray_r-6`} - onChange={(e) => setselectedNote_websiteText(e.target.value)} - /> - </div> + <div> + <hr className='my-4 border-gray_r-6' /> + + <div className='flex gap-x-1 flex-col mb-4'> + <div className='flex flex-row gap-x-1'> + <div className=''>Note</div> + {isApproval && ( + <div className='text-caption-1 text-red-500 items-center flex'> + *harus diisi + </div> + )} + </div> + <div className='text-caption-2 text-gray_r-11'> + <textarea + rows='4' + cols='50' + className={`w-full p-1 rounded border border-gray_r-6`} + onChange={(e) => + setselectedNote_websiteText(e.target.value) + } + /> </div> </div> - + </div> + <hr className='my-4 border-gray_r-6' /> <button |
