diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/api/odooApi.js | 36 | ||||
| -rw-r--r-- | src/lib/checkout/components/Checkout.jsx | 14 | ||||
| -rw-r--r-- | src/lib/checkout/components/SectionExpedition.jsx | 23 | ||||
| -rw-r--r-- | src/lib/checkout/utils/functionCheckouit.js | 4 | ||||
| -rw-r--r-- | src/lib/treckingAwb/component/Manifest.jsx | 43 |
5 files changed, 85 insertions, 35 deletions
diff --git a/src/core/api/odooApi.js b/src/core/api/odooApi.js index 504d097a..2bff42e2 100644 --- a/src/core/api/odooApi.js +++ b/src/core/api/odooApi.js @@ -42,17 +42,30 @@ const odooApi = async (method, url, data = {}, headers = {}) => { url: process.env.NEXT_PUBLIC_ODOO_API_HOST + url, headers: { Authorization: token, ...headers }, }; - if (auth) axiosParameter.headers['Token'] = auth.token; - if (method.toUpperCase() == 'POST') - axiosParameter.headers['Content-Type'] = - 'application/x-www-form-urlencoded'; - if (Object.keys(data).length > 0) - axiosParameter.data = new URLSearchParams( - Object.entries(data) - ).toString(); + + if (auth) { + axiosParameter.headers['Token'] = auth.token; + } + + // Tentukan format data berdasarkan metode dan data + if (Object.keys(data).length > 0) { + if (method.toUpperCase() === 'POST') { + // Gunakan URL-encoded untuk POST + axiosParameter.data = new URLSearchParams( + Object.entries(data) + ).toString(); + axiosParameter.headers['Content-Type'] = + 'application/x-www-form-urlencoded'; + } else { + // Gunakan JSON untuk GET/PUT atau metode lainnya + axiosParameter.data = data; + axiosParameter.headers['Content-Type'] = 'application/json'; + } + } let res = await axios(axiosParameter); - if (res.data.status.code == 401) { + + if (res.data.status.code === 401) { if (connectionAttempt < maxConnectionAttempt) { await renewToken(); return odooApi(method, url, data, headers); @@ -62,10 +75,13 @@ const odooApi = async (method, url, data = {}, headers = {}) => { return false; } } + return camelcaseObjectDeep(res.data.result) || []; } catch (error) { - // console.log(error); + console.error('API Error:', error); + throw error; // Opsional, lempar error agar bisa ditangkap di level atas } }; + export default odooApi; diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 3ad833ec..1a7fdc03 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -165,6 +165,7 @@ const Checkout = () => { etd, unit, selectedCourier, + selectedCourierId, selectedService, listExpedisi, setExpedisi, @@ -447,6 +448,10 @@ const Checkout = () => { quantity: product.quantity, available_quantity: product?.availableQuantity, })); + let estimated_courier = etd.split('-').map(Number); + let eta_courier = Math.max(...estimated_courier); + let eta_courier_start = Math.min(...estimated_courier); + let data = { // partner_shipping_id: auth.partnerId,, // partner_invoice_id: auth.partnerId, @@ -455,8 +460,9 @@ const Checkout = () => { user_id: auth.id, order_line: JSON.stringify(productOrder), delivery_amount: biayaKirim, - carrier_id: selectedCourier, - estimated_arrival_days: getToDate(etd, unit), + carrier_id: selectedCourierId, + estimated_arrival_days_start : parseInt(eta_courier_start) + parseInt(productSla), + estimated_arrival_days: parseInt(eta_courier) + parseInt(productSla), delivery_service_type: selectedService?.service_type, flash_sale: hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false voucher: activeVoucher, @@ -469,6 +475,8 @@ const Checkout = () => { if (poNumber.current.value) data.po_number = poNumber.current.value; if (typeof file !== 'undefined') data.po_file = await getFileBase64(file); + console.log('ini data', data); + const isCheckouted = await checkoutApi({ data }); if (!isCheckouted?.id) { @@ -1297,7 +1305,6 @@ const Checkout = () => { className='flex-1 btn-yellow' onClick={checkout} disabled={ - isLoading || !products || products?.length == 0 || priceCheck || @@ -1603,7 +1610,6 @@ const Checkout = () => { className='w-full btn-yellow mt-4' onClick={checkout} disabled={ - isLoading || !products || products?.length == 0 || priceCheck || diff --git a/src/lib/checkout/components/SectionExpedition.jsx b/src/lib/checkout/components/SectionExpedition.jsx index a00858e5..b261cae0 100644 --- a/src/lib/checkout/components/SectionExpedition.jsx +++ b/src/lib/checkout/components/SectionExpedition.jsx @@ -49,7 +49,7 @@ function reverseMappingCourier(couriersOdoo, couriers, includeInstant = false) { shipment_range: item.shipment_duration_range, shipment_unit: item.shipment_duration_unit, price: item.price, - service_type: item.service_type, + service_type: courier_service_code, description: item.description, }; @@ -81,13 +81,6 @@ function reverseMappingCourier(couriersOdoo, couriers, includeInstant = false) { } -function isHiloday(){ - const today = new Date(); - const day = today.getDay(); - - return day === 6 || day === 7 -} - function mappingCourier(couriersOdoo, couriers, notIncludeInstant = false) { const validCourierMap = couriersOdoo.reduce((acc, courier) => { acc[courier.label.toLowerCase()] = courier.carrierId; @@ -144,9 +137,6 @@ function mappingCourier(couriersOdoo, couriers, notIncludeInstant = false) { }, {}); } -function hasCanInstantFalse(items) { - return items.some((item) => item.canInstant === false); -} // interface CourierService { // courier_name: string; @@ -181,6 +171,7 @@ export default function SectionExpedition({ products }) { const [onFocusSelectedCourier, setOnFocuseSelectedCourier] = useState(false); const [couriers, setCouriers] = useState(null); const [slaProducts, setSlaProducts] = useState(null); + const [addHolidays, setAddHolidays] = useState(0); const { checkWeigth, @@ -194,7 +185,8 @@ export default function SectionExpedition({ products }) { setSelectedService, listExpedisi, productSla, - setProductSla + setProductSla, + setSelectedCourierId } = useCheckout(); let destination = {}; @@ -217,7 +209,6 @@ export default function SectionExpedition({ products }) { try { const ids = products.map((p) => p.id).join(',') const res = await odooApi('GET', `/api/v1/product/variants/sla?ids=${ids}`) - setSlaProducts(res); } catch (error) { console.error('Failed to fetch expedition rates:', error); @@ -230,7 +221,7 @@ export default function SectionExpedition({ products }) { useEffect(() => { if (slaProducts) { - let productSla = slaProducts?.slaDuration + let productSla = slaProducts?.slaTotal if(slaProducts.slaUnit === 'jam') { productSla = 1 } @@ -282,11 +273,13 @@ export default function SectionExpedition({ products }) { setIsOpen(false); setOnFocuseSelectedCourier(false); const courier = code; + console.log('ini courier', courier, couriers); setSelectedService(null); setBiayaKirim(0); if (courier !== 0 && courier !== 32) { if (courier.courier) { setSelectedCourier(courier.courier.courier_code); + setSelectedCourierId(courier.carrierId) setServiceOptions(Object.values(courier.courier.service_type)); } else { if ( @@ -328,8 +321,6 @@ export default function SectionExpedition({ products }) { setIsOpen(false); }; - console.log('ini selectedCourier', couriers); - return ( <form onSubmit={handleSubmit(onSubmit)}> <div className='px-4 py-2'> diff --git a/src/lib/checkout/utils/functionCheckouit.js b/src/lib/checkout/utils/functionCheckouit.js index a6e6c337..a95e6fb4 100644 --- a/src/lib/checkout/utils/functionCheckouit.js +++ b/src/lib/checkout/utils/functionCheckouit.js @@ -21,7 +21,7 @@ export function formatShipmentRange( // } } else { minRange = Number(shipmentDurationRange); // Jika angka tunggal - maxRange = Number(shipmentDurationRange) + 3; + maxRange = Number(shipmentDurationRange); } const start = new Date(); // Tanggal saat ini @@ -82,7 +82,7 @@ export function getToDate(shipmentDurationRange, shipmentDurationUnit) { throw new Error("Unsupported unit. Please use 'days' or 'hours'."); } - return formatDate(maxDate); + return maxDate.getDate(); } function formatDate(date) { diff --git a/src/lib/treckingAwb/component/Manifest.jsx b/src/lib/treckingAwb/component/Manifest.jsx index 87e01e38..a0df6ee9 100644 --- a/src/lib/treckingAwb/component/Manifest.jsx +++ b/src/lib/treckingAwb/component/Manifest.jsx @@ -7,6 +7,18 @@ import { toast } from 'react-hot-toast'; import ImageNext from 'next/image'; import { list } from 'postcss'; + +function capitalizeFirstLetter(str) { + return str.charAt(0).toUpperCase() + str.slice(1); +} + + +function capitalizeWords(str) { + return str.split(' ').map(word => capitalizeFirstLetter(word)).join(' '); +} + + + const Manifest = ({ idAWB, closePopup }) => { const [manifests, setManifests] = useState(null); const [isLoading, setIsLoading] = useState(false); @@ -101,6 +113,16 @@ const Manifest = ({ idAWB, closePopup }) => { <p className='text-yellow-600 text-sm'>Sedang Dikirim</p> </div> )} + {manifests?.status === 'cancelled' && ( + <div className='bg-red-800 p-2 rounded '> + <p className='text-white text-sm'>Di Batalkan</p> + </div> + )} + {manifests?.status === 'on_hold' && ( + <div className='bg-red-800 p-2 rounded '> + <p className='text-white text-sm'>Ditunda Sementara </p> + </div> + )} {manifests?.status === 'pending' && ( <div className='bg-red-100 p-2 rounded '> <p className='text-red-600 text-sm'>Pending</p> @@ -112,12 +134,18 @@ const Manifest = ({ idAWB, closePopup }) => { Estimasi tiba pada{' '} <span className='text-gray_r-11 text-sm'>({manifests?.eta})</span> </h1> - <h1 className='text-sm mt-2 mb-3'> + <h1 className='text-sm mt-2'> Dikirim Menggunakan{' '} <span className='text-red-500 font-semibold'> {manifests?.deliveryOrder.carrier} </span> </h1> + <h2 className='text-sm mb-3'> + Tipe Service {' '} + <span className='text-red-500 font-semibold'> + {manifests?.deliveryOrder.service} + </span> + </h2> {manifests?.waybillNumber && ( <div className='flex justify-between items-center'> <h1>No. Resi</h1> @@ -184,11 +212,20 @@ const Manifest = ({ idAWB, closePopup }) => { <time class='text-sm leading-none text-gray-400'> {formatCustomDate(manifest.datetime)} </time> - {manifests.delivered == true && index == 0 && ( + {manifests.delivered == true && + index == 0 && + manifests.isBiteship == false && ( + <p + class={`leading-6 font-semibold text-sm text-green-600 `} + > + Sudah Sampai + </p> + )} + {manifests.isBiteship == true && ( <p class={`leading-6 font-semibold text-sm text-green-600 `} > - Sudah Sampai + {capitalizeWords(manifest.status)} </p> )} <p class={`leading-6 text-[12px] text-gray_r-11`}> |
