From ed0adaad2125b46a6c039ce89b38b3cbb8379342 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Fri, 1 Nov 2024 13:42:10 +0700
Subject: add label pinpoint di pagecheckout
---
src/lib/checkout/components/Checkout.jsx | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
(limited to 'src/lib/checkout/components')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 0e180d9c..97254ec0 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -1,4 +1,4 @@
-import { Skeleton, Spinner } from '@chakra-ui/react';
+import { Button, Skeleton, Spinner } from '@chakra-ui/react';
import {
BanknotesIcon,
ChevronLeftIcon,
@@ -31,6 +31,7 @@ import addressesApi from '@/lib/address/api/addressesApi';
import CartItem from '~/modules/cart/components/Item.tsx';
import ExpedisiList from '../api/ExpedisiList';
import { findVoucher, getVoucher, getVoucherNew } from '../api/getVoucher';
+import { MapPinIcon } from 'lucide-react';
const SELF_PICKUP_ID = 32;
@@ -413,7 +414,12 @@ const Checkout = () => {
Math.round(parseInt(finalShippingAmt * 1.1) / 1000) * 1000;
const finalGT = GT < 0 ? 0 : GT;
setGrandTotal(finalGT);
- }, [biayaKirim, cartCheckout?.grandTotal, activeVoucher, activeVoucherShipping]);
+ }, [
+ biayaKirim,
+ cartCheckout?.grandTotal,
+ activeVoucher,
+ activeVoucherShipping,
+ ]);
const checkout = async () => {
const file = poFile.current.files[0];
@@ -500,7 +506,7 @@ const Checkout = () => {
}
}
- /* const midtrans = async () => {
+ /* const midtrans = async () => {
for (const product of products) deleteItemCart({ productId: product.id });
if (grandTotal > 0) {
const payment = await axios.post(
@@ -1192,7 +1198,11 @@ const Checkout = () => {
- {currencyFormat(Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000)}
+
+ {currencyFormat(
+ Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000
+ )}
+
{activeVoucherShipping && voucherShippingAmt && (
@@ -1493,7 +1503,11 @@ const Checkout = () => {
Biaya Kirim
{etdFix}
- {currencyFormat(Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000) }
+
+ {currencyFormat(
+ Math.round(parseInt(biayaKirim * 1.1) / 1000) * 1000
+ )}
+
{activeVoucherShipping && voucherShippingAmt && (
@@ -1658,9 +1672,13 @@ const SectionAddress = ({ address, label, url }) => (
{address.street}, {address?.city?.name}
+
+
+ {address.addressMap ? Sudah Pinpoint : Belum Pinpoint }
+
)}
-
+
);
const SectionValidation = ({ address }) =>
--
cgit v1.2.3
From ebba81f144b860eaf3bd7a9ef2b1c63a2ff021e0 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Thu, 7 Nov 2024 12:59:56 +0700
Subject: get couries biteship
---
src/lib/checkout/components/Checkout.jsx | 58 +++--------------------
src/lib/checkout/components/SectionExpedition.tsx | 12 +++++
2 files changed, 18 insertions(+), 52 deletions(-)
create mode 100644 src/lib/checkout/components/SectionExpedition.tsx
(limited to 'src/lib/checkout/components')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 97254ec0..6da27745 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -269,58 +269,6 @@ const Checkout = () => {
};
}, []);
- const hitungDiscountVoucher = (code, source) => {
- let countDiscount = 0;
- if (source === 'voucher') {
- let dataVoucherIndex = listVouchers.findIndex(
- (voucher) => voucher.code == code
- );
- let dataActiveVoucher = listVouchers[dataVoucherIndex];
-
- countDiscount = dataActiveVoucher.discountVoucher;
- } else {
- let dataVoucherIndex = listVoucherShippings.findIndex(
- (voucher) => voucher.code == code
- );
- let dataActiveVoucher = listVoucherShippings[dataVoucherIndex];
-
- countDiscount = dataActiveVoucher.discountVoucher;
- }
-
- /*if (dataActiveVoucher.discountType === 'percentage') {
- countDiscount = cartCheckout?.subtotal * (dataActiveVoucher.discountAmount / 100)
- if (
- dataActiveVoucher.maxDiscountAmount > 0 &&
- countDiscount > dataActiveVoucher.maxDiscountAmount
- ) {
- countDiscount = dataActiveVoucher.maxDiscountAmount
- }
- } else {
- countDiscount = dataActiveVoucher.discountAmount
- }*/
-
- return countDiscount;
- };
-
- // useEffect(() => {
- // if (!listVouchers) return;
- // if (!activeVoucher) return;
-
- // console.log('voucher')
- // const countDiscount = hitungDiscountVoucher(activeVoucher, 'voucher');
-
- // SetDiscountVoucher(countDiscount);
- // }, [activeVoucher, listVouchers]);
-
- // useEffect(() => {
- // if (!listVoucherShippings) return;
- // if (!activeVoucherShipping) return;
-
- // const countDiscount = hitungDiscountVoucher(activeVoucherShipping, 'voucher_shipping');
-
- // SetDiscountVoucherOngkir(countDiscount);
- // }, [activeVoucherShipping, listVoucherShippings]);
-
useEffect(() => {
if (qVoucher === 'PASTIHEMAT' && listVouchers) {
let code = qVoucher;
@@ -1698,6 +1646,12 @@ const SectionValidation = ({ address }) =>
);
+const SectionExpedisiBiteship = ({ listExpedisi, setSelectedExpedisi }) => (
+ <>
+ >
+);
+
+
const SectionExpedisi = ({
address,
listExpedisi,
diff --git a/src/lib/checkout/components/SectionExpedition.tsx b/src/lib/checkout/components/SectionExpedition.tsx
new file mode 100644
index 00000000..d2dd5763
--- /dev/null
+++ b/src/lib/checkout/components/SectionExpedition.tsx
@@ -0,0 +1,12 @@
+import React from 'react';
+import { GetRatesCourierBiteship } from '../api/ExpedisiList';
+import { useQuery } from 'react-query';
+
+export default function SectionExpedition() {
+ let destination = {}
+ let items = {}
+ const fetchExpedition = async () => await GetRatesCourierBiteship({destination, items});
+ const {data : coursers, isLoading} = useQuery('expedition-'+destination, fetchExpedition)
+
+ return SectionExpedition
;
+}
\ No newline at end of file
--
cgit v1.2.3
From 7966f67569d01c25f7a337962d7d0bb1a0c57808 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Wed, 13 Nov 2024 14:46:59 +0700
Subject: get couries, mapping couries and service
---
src/lib/checkout/components/Checkout.jsx | 53 +++--
src/lib/checkout/components/SectionExpedition.tsx | 256 +++++++++++++++++++++-
2 files changed, 285 insertions(+), 24 deletions(-)
(limited to 'src/lib/checkout/components')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 6da27745..b4c311a9 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -1,4 +1,4 @@
-import { Button, Skeleton, Spinner } from '@chakra-ui/react';
+import { Skeleton, Spinner } from '@chakra-ui/react';
import {
BanknotesIcon,
ChevronLeftIcon,
@@ -28,10 +28,12 @@ import getFileBase64 from '@/core/utils/getFileBase64';
import { gtagPurchase } from '@/core/utils/googleTag';
import whatsappUrl from '@/core/utils/whatsappUrl';
import addressesApi from '@/lib/address/api/addressesApi';
+import { MapPinIcon } from 'lucide-react';
import CartItem from '~/modules/cart/components/Item.tsx';
import ExpedisiList from '../api/ExpedisiList';
-import { findVoucher, getVoucher, getVoucherNew } from '../api/getVoucher';
-import { MapPinIcon } from 'lucide-react';
+import { getVoucher } from '../api/getVoucher';
+import { useAddress } from '../stores/useAdress';
+import SectionExpedition from './SectionExpedition';
const SELF_PICKUP_ID = 32;
@@ -57,11 +59,15 @@ const Checkout = () => {
})
);
- const [selectedAddress, setSelectedAddress] = useState({
- shipping: null,
- invoicing: null,
- });
- const [addresses, setAddresses] = useState(null);
+ const {
+ selectedAddress,
+ setSelectedAddress,
+ addresses,
+ setAddresses,
+ setAddressMaps,
+ setCoordinate,
+ setPostalCode,
+ } = useAddress();
useEffect(() => {
if (!auth) return;
@@ -91,10 +97,20 @@ const Checkout = () => {
return addresses[0];
};
+ let ship = matchAddress('shipping');
+
setSelectedAddress({
shipping: matchAddress('shipping'),
invoicing: matchAddress('invoicing'),
});
+ setPostalCode(ship?.zip);
+ if (ship?.addressMap) {
+ setAddressMaps(ship?.addressMap);
+ setCoordinate({
+ destination_latitude: ship?.latitude,
+ destination_longitude: ship?.longtitude,
+ });
+ }
}, [addresses]);
const [products, setProducts] = useState(null);
@@ -1340,6 +1356,7 @@ const Checkout = () => {
/>
)}
+ {products && }
(
{address.street}, {address?.city?.name}
-
- {address.addressMap ? Sudah Pinpoint : Belum Pinpoint }
+
+ {address.addressMap ? (
+ Sudah Pinpoint
+ ) : (
+ Belum Pinpoint
+ )}
)}
-
+
);
const SectionValidation = ({ address }) =>
@@ -1647,11 +1674,9 @@ const SectionValidation = ({ address }) =>
);
const SectionExpedisiBiteship = ({ listExpedisi, setSelectedExpedisi }) => (
- <>
- >
+ <>>
);
-
const SectionExpedisi = ({
address,
listExpedisi,
diff --git a/src/lib/checkout/components/SectionExpedition.tsx b/src/lib/checkout/components/SectionExpedition.tsx
index d2dd5763..a6e05893 100644
--- a/src/lib/checkout/components/SectionExpedition.tsx
+++ b/src/lib/checkout/components/SectionExpedition.tsx
@@ -1,12 +1,248 @@
-import React from 'react';
-import { GetRatesCourierBiteship } from '../api/ExpedisiList';
+import React, { useEffect, useState } from 'react';
import { useQuery } from 'react-query';
+import GetRatesCourierBiteship from '../api/getRatesCourier';
+import { useAddress } from '../stores/useAdress';
+import axios, { AxiosResponse } from 'axios';
+import { useForm, Controller } from 'react-hook-form';
+import { AnimatePresence, motion } from 'framer-motion';
+import { Spinner } from '@chakra-ui/react';
-export default function SectionExpedition() {
- let destination = {}
- let items = {}
- const fetchExpedition = async () => await GetRatesCourierBiteship({destination, items});
- const {data : coursers, isLoading} = useQuery('expedition-'+destination, fetchExpedition)
-
- return SectionExpedition
;
-}
\ No newline at end of file
+function mappingItems(products) {
+ return products?.map((item) => ({
+ name: item.parent.name,
+ description: `${item.code} - ${item.name}`,
+ value: item.price.priceDiscount,
+ weight: item.weight,
+ quantity: item.quantity,
+ }));
+}
+
+function mappingCourier(couriers) {
+ return couriers?.reduce((result, item) => {
+ const { courier_code, courier_service_code } = item;
+
+ // Jika courier_code belum ada di result, buat objek baru untuknya
+ if (!result[courier_code]) {
+ result[courier_code] = {
+ courier_name: item.courier_name,
+ courier_code: courier_code,
+ service_type: {
+ [courier_service_code]: {
+ service_name: item.courier_service_name,
+ duration: item.duration,
+ shipment_duration: item.duration,
+ price: item.price,
+ service_type: item.service_type,
+ description: item.description,
+ },
+ },
+ };
+ } else {
+ result[courier_code].service_type[courier_service_code] = {
+ service_name: item.courier_service_name,
+ duration: item.duration,
+ shipment_duration: item.duration,
+ price: item.price,
+ service_type: item.service_type,
+ description: item.description,
+ };
+ }
+
+ return result;
+ }, {});
+}
+
+interface CourierService {
+ courier_name: string;
+ courier_code: string;
+ service_type: {
+ [key: string]: {
+ service_name: string;
+ duration: number;
+ shipment_duration: number;
+ price: number;
+ service_type: string;
+ description: string;
+ };
+ };
+}
+
+export default function SectionExpedition({ products }) {
+ const { addressMaps, coordinate, postalCode } = useAddress();
+ const { control, handleSubmit } = useForm();
+ const [selectedCourier, setSelectedCourier] = useState('');
+ const [serviceOptions, setServiceOptions] = useState([]);
+
+ let destination = {};
+ let items = mappingItems(products);
+ if (addressMaps) {
+ destination = {
+ origin_latitude: -6.3031123,
+ origin_longitude: 106.7794934999,
+ ...coordinate,
+ };
+ } else if (postalCode) {
+ destination = {
+ origin_postal_code: 12440,
+ destination_postal_code: postalCode,
+ };
+ }
+
+ const fetchExpedition = async () => {
+ let body = {
+ ...destination,
+ couriers:
+ 'gojek, grab, deliveree, lalamove, jne, tiki, ninja, lion, rara, sicepat, jnt, pos, idexpress, rpx, wahana, jdl, pos, anteraja, sap, paxel, borzo',
+ items: items,
+ };
+ try {
+ const response = await axios.get(`/api/biteship-service`, {
+ params: { body: JSON.stringify(body) },
+ });
+ return response;
+ } catch (error) {
+ console.error('Failed to fetch expedition rates:', error);
+ }
+ };
+
+ // const fetchExpedition = async () => await GetRatesCourierBiteship({ destination, items });
+ const { data, isLoading } = useQuery(
+ ['expedition', JSON.stringify(destination), JSON.stringify(items)],
+ fetchExpedition,
+ {
+ enabled: Boolean(Object.keys(destination).length) && items?.length > 0,
+ staleTime: Infinity,
+ cacheTime: Infinity,
+ }
+ );
+
+ const couriers: CourierService = mappingCourier(data?.data?.pricing);
+
+ console.log('couriers', couriers);
+
+ const onCourierChange = (e) => {
+ const courier = e.target.value;
+ console.log('courier', courier);
+ setSelectedCourier(courier);
+ // Menentukan layanan berdasarkan pengiriman yang dipilih
+ if (courier && couriers[courier]) {
+ setServiceOptions(Object.values(couriers[courier]?.service_type));
+ } else {
+ setServiceOptions([]);
+ }
+ };
+
+ console.log(
+ 'serviceOptions',
+ couriers[selectedCourier]?.service_type,
+ selectedCourier
+ );
+ const onSubmit = (data) => {
+ console.log(data);
+ };
+
+ return (
+
+ );
+}
--
cgit v1.2.3
From b18d45c560d57c788d3646cf6be0beb6381ec0f7 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Thu, 14 Nov 2024 10:53:54 +0700
Subject: biteship
---
src/lib/checkout/components/Checkout.jsx | 4 -
src/lib/checkout/components/SectionExpedition.jsx | 304 ++++++++++++++++++++++
src/lib/checkout/components/SectionExpedition.tsx | 248 ------------------
3 files changed, 304 insertions(+), 252 deletions(-)
create mode 100644 src/lib/checkout/components/SectionExpedition.jsx
delete mode 100644 src/lib/checkout/components/SectionExpedition.tsx
(limited to 'src/lib/checkout/components')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index b0f8f884..152b84ed 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -1674,10 +1674,6 @@ const SectionValidation = ({ address }) =>
);
-const SectionExpedisiBiteship = ({ listExpedisi, setSelectedExpedisi }) => (
- <>>
-);
-
const SectionExpedisi = ({
address,
listExpedisi,
diff --git a/src/lib/checkout/components/SectionExpedition.jsx b/src/lib/checkout/components/SectionExpedition.jsx
new file mode 100644
index 00000000..ead65a6f
--- /dev/null
+++ b/src/lib/checkout/components/SectionExpedition.jsx
@@ -0,0 +1,304 @@
+import React, { useEffect, useState } from 'react';
+import { useQuery } from 'react-query';
+import GetRatesCourierBiteship from '../api/getRatesCourier';
+import { useAddress } from '../stores/useAdress';
+import axios, { AxiosResponse } from 'axios';
+import { useForm, Controller } from 'react-hook-form';
+import { AnimatePresence, motion } from 'framer-motion';
+import { Spinner } from '@chakra-ui/react';
+
+import currencyFormat from '@/core/utils/currencyFormat';
+
+function mappingItems(products) {
+ return products?.map((item) => ({
+ name: item.parent.name,
+ description: `${item.code} - ${item.name}`,
+ value: item.price.priceDiscount,
+ weight: item.weight,
+ quantity: item.quantity,
+ }));
+}
+
+function mappingCourier(couriers) {
+ return couriers?.reduce((result, item) => {
+ const { courier_code, courier_service_code } = item;
+
+ // Jika courier_code belum ada di result, buat objek baru untuknya
+ if (!result[courier_code]) {
+ result[courier_code] = {
+ courier_name: item.courier_name,
+ courier_code: courier_code,
+ service_type: {
+ [courier_service_code]: {
+ service_name: item.courier_service_name,
+ duration: item.duration,
+ shipment_duration: item.duration,
+ price: item.price,
+ service_type: item.service_type,
+ description: item.description,
+ },
+ },
+ };
+ } else {
+ result[courier_code].service_type[courier_service_code] = {
+ service_name: item.courier_service_name,
+ duration: item.duration,
+ shipment_duration: item.duration,
+ price: item.price,
+ service_type: item.service_type,
+ description: item.description,
+ };
+ }
+
+ return result;
+ }, {});
+}
+
+// interface CourierService {
+// courier_name: string;
+// courier_code: string;
+// service_type: {
+// [key: string]: {
+// service_name: string;
+// duration: number;
+// shipment_duration: number;
+// price: number;
+// service_type: string;
+// description: string;
+// };
+// };
+// }
+
+// interface ServiceOption {
+// service_name: string;
+// duration: number;
+// shipment_duration: number;
+// price: number;
+// service_type: string;
+// description: string;
+// }
+
+export default function SectionExpedition({ products }) {
+ const { addressMaps, coordinate, postalCode } = useAddress();
+ const { control, handleSubmit } = useForm();
+ const [selectedCourier, setSelectedCourier] = useState('');
+ const [serviceOptions, setServiceOptions] = useState([]);
+ const [selectedService, setSelectedService] = useState(null);
+ const [isOpen, setIsOpen] = useState(false);
+
+ let destination = {};
+ let items = mappingItems(products);
+ if (addressMaps) {
+ destination = {
+ origin_latitude: -6.3031123,
+ origin_longitude: 106.7794934999,
+ ...coordinate,
+ };
+ } else if (postalCode) {
+ destination = {
+ origin_postal_code: 12440,
+ destination_postal_code: postalCode,
+ };
+ }
+
+ const fetchExpedition = async () => {
+ let body = {
+ ...destination,
+ couriers:
+ 'gojek,grab,deliveree,lalamove,jne,tiki,ninja,lion,rara,sicepat,jnt,pos,idexpress,rpx,wahana,jdl,pos,anteraja,sap,paxel,borzo',
+ items: items,
+ };
+ try {
+ const response = await axios.get(`/api/biteship-service`, {
+ params: { body: JSON.stringify(body) },
+ });
+ return response;
+ } catch (error) {
+ console.error('Failed to fetch expedition rates:', error);
+ }
+ };
+
+ // const fetchExpedition = async () => await GetRatesCourierBiteship({ destination, items });
+ const { data, isLoading } = useQuery(
+ ['expedition', JSON.stringify(destination), JSON.stringify(items)],
+ fetchExpedition,
+ {
+ enabled: Boolean(Object.keys(destination).length) && items?.length > 0,
+ staleTime: Infinity,
+ cacheTime: Infinity,
+ }
+ );
+
+ const couriers = mappingCourier(data?.data?.pricing);
+
+ console.log('couriers', couriers);
+
+ const onCourierChange = (e) => {
+ const courier = e.target.value;
+ console.log('courier', courier);
+ setSelectedCourier(courier);
+ // Menentukan layanan berdasarkan pengiriman yang dipilih
+ if (courier && couriers[courier]) {
+ setServiceOptions(Object.values(couriers[courier]?.service_type));
+ } else {
+ setServiceOptions([]);
+ }
+ };
+
+ const onSubmit = (data) => {
+ console.log(data);
+ };
+
+ const handleSelect = (service) => {
+ setSelectedService(service);
+ setIsOpen(false);
+ };
+
+ return (
+
+ );
+}
diff --git a/src/lib/checkout/components/SectionExpedition.tsx b/src/lib/checkout/components/SectionExpedition.tsx
deleted file mode 100644
index a6e05893..00000000
--- a/src/lib/checkout/components/SectionExpedition.tsx
+++ /dev/null
@@ -1,248 +0,0 @@
-import React, { useEffect, useState } from 'react';
-import { useQuery } from 'react-query';
-import GetRatesCourierBiteship from '../api/getRatesCourier';
-import { useAddress } from '../stores/useAdress';
-import axios, { AxiosResponse } from 'axios';
-import { useForm, Controller } from 'react-hook-form';
-import { AnimatePresence, motion } from 'framer-motion';
-import { Spinner } from '@chakra-ui/react';
-
-function mappingItems(products) {
- return products?.map((item) => ({
- name: item.parent.name,
- description: `${item.code} - ${item.name}`,
- value: item.price.priceDiscount,
- weight: item.weight,
- quantity: item.quantity,
- }));
-}
-
-function mappingCourier(couriers) {
- return couriers?.reduce((result, item) => {
- const { courier_code, courier_service_code } = item;
-
- // Jika courier_code belum ada di result, buat objek baru untuknya
- if (!result[courier_code]) {
- result[courier_code] = {
- courier_name: item.courier_name,
- courier_code: courier_code,
- service_type: {
- [courier_service_code]: {
- service_name: item.courier_service_name,
- duration: item.duration,
- shipment_duration: item.duration,
- price: item.price,
- service_type: item.service_type,
- description: item.description,
- },
- },
- };
- } else {
- result[courier_code].service_type[courier_service_code] = {
- service_name: item.courier_service_name,
- duration: item.duration,
- shipment_duration: item.duration,
- price: item.price,
- service_type: item.service_type,
- description: item.description,
- };
- }
-
- return result;
- }, {});
-}
-
-interface CourierService {
- courier_name: string;
- courier_code: string;
- service_type: {
- [key: string]: {
- service_name: string;
- duration: number;
- shipment_duration: number;
- price: number;
- service_type: string;
- description: string;
- };
- };
-}
-
-export default function SectionExpedition({ products }) {
- const { addressMaps, coordinate, postalCode } = useAddress();
- const { control, handleSubmit } = useForm();
- const [selectedCourier, setSelectedCourier] = useState('');
- const [serviceOptions, setServiceOptions] = useState([]);
-
- let destination = {};
- let items = mappingItems(products);
- if (addressMaps) {
- destination = {
- origin_latitude: -6.3031123,
- origin_longitude: 106.7794934999,
- ...coordinate,
- };
- } else if (postalCode) {
- destination = {
- origin_postal_code: 12440,
- destination_postal_code: postalCode,
- };
- }
-
- const fetchExpedition = async () => {
- let body = {
- ...destination,
- couriers:
- 'gojek, grab, deliveree, lalamove, jne, tiki, ninja, lion, rara, sicepat, jnt, pos, idexpress, rpx, wahana, jdl, pos, anteraja, sap, paxel, borzo',
- items: items,
- };
- try {
- const response = await axios.get(`/api/biteship-service`, {
- params: { body: JSON.stringify(body) },
- });
- return response;
- } catch (error) {
- console.error('Failed to fetch expedition rates:', error);
- }
- };
-
- // const fetchExpedition = async () => await GetRatesCourierBiteship({ destination, items });
- const { data, isLoading } = useQuery(
- ['expedition', JSON.stringify(destination), JSON.stringify(items)],
- fetchExpedition,
- {
- enabled: Boolean(Object.keys(destination).length) && items?.length > 0,
- staleTime: Infinity,
- cacheTime: Infinity,
- }
- );
-
- const couriers: CourierService = mappingCourier(data?.data?.pricing);
-
- console.log('couriers', couriers);
-
- const onCourierChange = (e) => {
- const courier = e.target.value;
- console.log('courier', courier);
- setSelectedCourier(courier);
- // Menentukan layanan berdasarkan pengiriman yang dipilih
- if (courier && couriers[courier]) {
- setServiceOptions(Object.values(couriers[courier]?.service_type));
- } else {
- setServiceOptions([]);
- }
- };
-
- console.log(
- 'serviceOptions',
- couriers[selectedCourier]?.service_type,
- selectedCourier
- );
- const onSubmit = (data) => {
- console.log(data);
- };
-
- return (
-
- );
-}
--
cgit v1.2.3
From 0d4278bd482d2ec2563b29cb3597eb8c7227a2d7 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Fri, 15 Nov 2024 13:32:26 +0700
Subject: add hook state
---
src/lib/checkout/components/Checkout.jsx | 13 -------------
1 file changed, 13 deletions(-)
(limited to 'src/lib/checkout/components')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 152b84ed..4dd715d7 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -662,19 +662,6 @@ const Checkout = () => {
)}
- {/* {!loadingVoucher &&
- listVouchers?.length === 1 &&
- listVoucherShippings?.length === 1}
- {
-
-
-
Tidak ada voucher tersedia
-
- Maaf, saat ini tidak ada voucher yang tersedia.
-
-
-
- } */}
{listVoucherShippings && listVoucherShippings?.length > 0 && (
--
cgit v1.2.3
From d078c6adfd896b59f14e2a5116ecb977256674fa Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Tue, 19 Nov 2024 16:51:54 +0700
Subject: biteships
---
src/lib/checkout/components/Checkout.jsx | 11 +-
src/lib/checkout/components/SectionExpedition.jsx | 216 +++++++++++-----------
2 files changed, 114 insertions(+), 113 deletions(-)
(limited to 'src/lib/checkout/components')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 33cfaa87..92a94834 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -34,6 +34,7 @@ import ExpedisiList from '../api/ExpedisiList';
import { getVoucher } from '../api/getVoucher';
import { useAddress } from '../stores/useAdress';
import SectionExpedition from './SectionExpedition';
+import { useCheckout } from '../stores/stateCheckout';
const SELF_PICKUP_ID = 32;
@@ -125,7 +126,6 @@ const Checkout = () => {
}
}, [addresses]);
- const [products, setProducts] = useState(null);
const [totalWeight, setTotalWeight] = useState(0);
const [priceCheck, setPriceCheck] = useState(false);
const [listExpedisi, setExpedisi] = useState([]);
@@ -133,8 +133,6 @@ const Checkout = () => {
const [selectedExpedisi, setSelectedExpedisi] = useState(0);
const [selectedCarrierId, setselectedCarrierId] = useState(0);
const [selectedCarrier, setselectedCarrier] = useState(0);
- const [biayaKirim, setBiayaKirim] = useState(0);
- const [checkWeigth, setCheckWeight] = useState(false);
const [selectedServiceType, setSelectedServiceType] = useState(null);
const [selectedExpedisiService, setselectedExpedisiService] = useState(null);
const [etd, setEtd] = useState(null);
@@ -149,11 +147,11 @@ const Checkout = () => {
const [findCodeVoucher, SetFindVoucher] = useState(null);
const [selisihHargaCode, SetSelisihHargaCode] = useState(null);
const [buttonTerapkan, SetButtonTerapkan] = useState(false);
- const [checkoutValidation, setCheckoutValidation] = useState(false);
const [loadingVoucher, setLoadingVoucher] = useState(true);
const [loadingRajaOngkir, setLoadingRajaOngkir] = useState(false);
const [grandTotal, setGrandTotal] = useState(0);
- const [hasFlashSale, setHasFlashSale] = useState(false);
+
+ const {checkWeigth, setCheckWeight, hasFlashSale, setHasFlashSale, checkoutValidation, setCheckoutValidation, biayaKirim, setBiayaKirim, products, setProducts} = useCheckout();
const expedisiValidation = useRef(null);
@@ -571,6 +569,9 @@ const Checkout = () => {
cartCheckout?.discountVoucher +
(cartCheckout?.discountVoucherShipping || 0);
+
+ console.log('etd', etd, calculateEstimatedArrival(etd), splitDuration(etd));
+
return (
<>
({
name: item.parent.name,
description: `${item.code} - ${item.name}`,
value: item.price.priceDiscount,
- weight: item.weight,
+ weight: item.weight * 1000 * item.quantity,
quantity: item.quantity,
+ canInstant: item.availableQuantity > item.quantity ? true : false,
}));
}
-function mappingCourier(couriers) {
+function mappingCourier(couriers, notIncludeInstant = false) {
return couriers?.reduce((result, item) => {
const { courier_code, courier_service_code } = item;
+ if (
+ notIncludeInstant &&
+ ['hours'].includes(item.shipment_duration_unit.toLowerCase())
+ ) {
+ return result;
+ }
// Jika courier_code belum ada di result, buat objek baru untuknya
if (!result[courier_code]) {
@@ -54,6 +61,10 @@ function mappingCourier(couriers) {
}, {});
}
+function hasCanInstantFalse(items) {
+ return items.some((item) => item.canInstant === false);
+}
+
// interface CourierService {
// courier_name: string;
// courier_code: string;
@@ -86,8 +97,13 @@ export default function SectionExpedition({ products }) {
const [selectedService, setSelectedService] = useState(null);
const [isOpen, setIsOpen] = useState(false);
+ const { checkWeigth, checkoutValidation } = useCheckout();
+
let destination = {};
let items = mappingItems(products);
+
+ let notIncludeInstant = hasCanInstantFalse(items);
+ console.log('instanCourier', items);
if (addressMaps) {
destination = {
origin_latitude: -6.3031123,
@@ -118,27 +134,31 @@ export default function SectionExpedition({ products }) {
}
};
- // const fetchExpedition = async () => await GetRatesCourierBiteship({ destination, items });
const { data, isLoading } = useQuery(
['expedition', JSON.stringify(destination), JSON.stringify(items)],
fetchExpedition,
{
- enabled: Boolean(Object.keys(destination).length) && items?.length > 0,
+ enabled:
+ Boolean(Object.keys(destination).length) &&
+ items?.length > 0 &&
+ !checkWeigth,
staleTime: Infinity,
cacheTime: Infinity,
}
);
- const couriers = mappingCourier(data?.data?.pricing);
+ console.log('data', data);
- console.log('couriers', couriers);
+ const couriers = mappingCourier(data?.data?.pricing, true) || null;
const onCourierChange = (e) => {
+ setIsOpen(false);
const courier = e.target.value;
- console.log('courier', courier);
+ setSelectedService(null);
setSelectedCourier(courier);
+ console.log('courier', courier);
// Menentukan layanan berdasarkan pengiriman yang dipilih
- if (courier && couriers[courier]) {
+ if (courier && courier !== '0' && courier !== '32' && couriers[courier]) {
setServiceOptions(Object.values(couriers[courier]?.service_type));
} else {
setServiceOptions([]);
@@ -156,7 +176,6 @@ export default function SectionExpedition({ products }) {
return (
- {/* {checkWeigth == true && (
-
- Mohon maaf, pengiriman hanya tersedia untuk self pickup karena
- terdapat barang yang belum diatur beratnya. Mohon atur berat barang
- dengan menghubungi admin melalui{' '}
-
- tautan ini
-
-
- )} */}
+ {checkWeigth == true && (
+
+ Mohon maaf, pengiriman hanya tersedia untuk self pickup karena
+ terdapat barang yang belum diatur beratnya. Mohon atur berat barang
+ dengan menghubungi admin melalui{' '}
+
+ tautan ini
+
+
+ )}
- {selectedCourier && (
-
-
-
Tipe Layanan Ekspedisi:
-
-
- {/* Custom Select Input Field */}
-
setIsOpen(!isOpen)}
- >
- {selectedService ? (
-
-
{selectedService.service_name}
-
- {currencyFormat(selectedService.price)}
+ {selectedCourier &&
+ selectedCourier !== '32' &&
+ selectedCourier !== '0' && (
+
+
+
Tipe Layanan Ekspedisi:
+
+
+ {/* Custom Select Input Field */}
+
setIsOpen(!isOpen)}
+ >
+ {selectedService ? (
+
+ {selectedService.service_name}
+
+ {currencyFormat(selectedService.price)}
+
+
+ ) : (
+
+ Pilih layanan pengiriman
+ )}
+
+
+ {/* Dropdown Options */}
+ {isOpen && (
+
+ {serviceOptions.map((service) => (
+
handleSelect(service)}
+ className='flex justify-between p-2 items-center hover:bg-gray-100 cursor-pointer'
+ >
+
+
+ {service.service_name}
+
+
+ Estimasi Tiba {service.duration}
+
+
+
+ {currencyFormat(service.price)}
+
+
+ ))}
- ) : (
-
- Pilih layanan pengiriman
-
)}
-
- {/* Dropdown Options */}
- {isOpen && (
-
- {serviceOptions.map((service) => (
-
handleSelect(service)}
- className='flex justify-between p-2 items-center hover:bg-gray-100 cursor-pointer'
- >
-
-
- {service.service_name}
-
-
- Estimasi Tiba {service.duration}
-
-
-
{currencyFormat(service.price)}
-
- ))}
-
- )}
- {/*
setSelectedServiceType(e.target.value)}
- >
- {serviceOptions.map(
- (service: { service_name: string; service_type: string; duration: string, price: number }) => (
-
-
-
- {service?.service_name}
- Estimasi Tiba {service?.duration}
-
-
- {service.price}
-
-
-
- )
- )}
- */}
-
- )}
+ )}
);
}
--
cgit v1.2.3
From 821d218ff687a585c99937948989408541b596e4 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Tue, 26 Nov 2024 09:46:07 +0700
Subject: filter biteship courier sesuikan dengan courier dari odoo
---
src/lib/checkout/components/Checkout.jsx | 185 ++++++++++------------
src/lib/checkout/components/SectionExpedition.jsx | 118 +++++++++-----
2 files changed, 159 insertions(+), 144 deletions(-)
(limited to 'src/lib/checkout/components')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 92a94834..38e11038 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -35,6 +35,7 @@ import { getVoucher } from '../api/getVoucher';
import { useAddress } from '../stores/useAdress';
import SectionExpedition from './SectionExpedition';
import { useCheckout } from '../stores/stateCheckout';
+import { formatShipmentRange, getToDate } from '../utils/functionCheckouit';
const SELF_PICKUP_ID = 32;
@@ -128,15 +129,14 @@ const Checkout = () => {
const [totalWeight, setTotalWeight] = useState(0);
const [priceCheck, setPriceCheck] = useState(false);
- const [listExpedisi, setExpedisi] = useState([]);
const [listserviceExpedisi, setListServiceExpedisi] = useState([]);
const [selectedExpedisi, setSelectedExpedisi] = useState(0);
const [selectedCarrierId, setselectedCarrierId] = useState(0);
const [selectedCarrier, setselectedCarrier] = useState(0);
const [selectedServiceType, setSelectedServiceType] = useState(null);
const [selectedExpedisiService, setselectedExpedisiService] = useState(null);
- const [etd, setEtd] = useState(null);
- const [etdFix, setEtdFix] = useState(null);
+ // const [etd, setEtd] = useState(null);
+ // const [etdFix, setEtdFix] = useState(null);
const [bottomPopup, SetBottomPopup] = useState(null);
const [bottomPopupTnC, SetBottomPopupTnC] = useState(null);
const [itemTnC, setItemTnC] = useState(null);
@@ -151,7 +151,7 @@ const Checkout = () => {
const [loadingRajaOngkir, setLoadingRajaOngkir] = useState(false);
const [grandTotal, setGrandTotal] = useState(0);
- const {checkWeigth, setCheckWeight, hasFlashSale, setHasFlashSale, checkoutValidation, setCheckoutValidation, biayaKirim, setBiayaKirim, products, setProducts} = useCheckout();
+ const {checkWeigth, setCheckWeight, hasFlashSale, setHasFlashSale, checkoutValidation, setCheckoutValidation, biayaKirim, products, setProducts, etd, unit, selectedCourier, selectedService, listExpedisi, setExpedisi} = useCheckout();
const expedisiValidation = useRef(null);
@@ -290,6 +290,7 @@ const Checkout = () => {
window.onpopstate = handlePopState;
+
return () => {
window.onpopstate = null;
};
@@ -312,70 +313,70 @@ const Checkout = () => {
setHasFlashSale(hasFlashSale);
}, [cartCheckout]);
- useEffect(() => {
- setCheckoutValidation(false);
- const loadServiceRajaOngkir = async () => {
- setLoadingRajaOngkir(true);
- const body = {
- origin: 2127,
- destination: selectedAddress.shipping.rajaongkirCityId,
- weight: totalWeight,
- courier: selectedCarrier,
- originType: 'subdistrict',
- destinationType: 'subdistrict',
- };
- setBiayaKirim(0);
- const dataService = await axios(
- '/api/rajaongkir-service?body=' + JSON.stringify(body)
- );
- setLoadingRajaOngkir(false);
- setListServiceExpedisi(dataService.data[0].costs);
- if (dataService.data[0].costs[0]) {
- setBiayaKirim(dataService.data[0].costs[0]?.cost[0].value);
- setselectedExpedisiService(
- dataService.data[0].costs[0]?.description +
- '-' +
- dataService.data[0].costs[0]?.service
- );
- setEtd(dataService.data[0].costs[0]?.cost[0].etd);
- toast.success('Harap pilih tipe layanan pengiriman');
- } else {
- toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
- }
- };
- if (selectedCarrier != 0 && selectedCarrier != 1 && totalWeight > 0) {
- loadServiceRajaOngkir();
- } else {
- setListServiceExpedisi();
- setBiayaKirim(0);
- setselectedExpedisiService();
- setEtd();
- }
- }, [selectedCarrier, selectedAddress, totalWeight]);
-
- useEffect(() => {
- if (selectedServiceType) {
- let serviceType = selectedServiceType.split(',');
- setBiayaKirim(serviceType[0]);
- setselectedExpedisiService(serviceType[1]);
- setEtd(serviceType[2]);
- }
- }, [selectedServiceType]);
-
- useEffect(() => {
- if (etd) setEtdFix(calculateEstimatedArrival(etd));
- }, [etd]);
-
- useEffect(() => {
- if (selectedExpedisi) {
- let serviceType = selectedExpedisi.split(',');
- if (serviceType[0] === 0) return;
-
- setselectedCarrier(serviceType[0]);
- setselectedCarrierId(serviceType[1]);
- setListServiceExpedisi([]);
- }
- }, [selectedExpedisi]);
+ // useEffect(() => {
+ // setCheckoutValidation(false);
+ // const loadServiceRajaOngkir = async () => {
+ // setLoadingRajaOngkir(true);
+ // const body = {
+ // origin: 2127,
+ // destination: selectedAddress.shipping.rajaongkirCityId,
+ // weight: totalWeight,
+ // courier: selectedCarrier,
+ // originType: 'subdistrict',
+ // destinationType: 'subdistrict',
+ // };
+ // setBiayaKirim(0);
+ // const dataService = await axios(
+ // '/api/rajaongkir-service?body=' + JSON.stringify(body)
+ // );
+ // setLoadingRajaOngkir(false);
+ // setListServiceExpedisi(dataService.data[0].costs);
+ // if (dataService.data[0].costs[0]) {
+ // setBiayaKirim(dataService.data[0].costs[0]?.cost[0].value);
+ // setselectedExpedisiService(
+ // dataService.data[0].costs[0]?.description +
+ // '-' +
+ // dataService.data[0].costs[0]?.service
+ // );
+ // setEtd(dataService.data[0].costs[0]?.cost[0].etd);
+ // toast.success('Harap pilih tipe layanan pengiriman');
+ // } else {
+ // toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
+ // }
+ // };
+ // if (selectedCarrier != 0 && selectedCarrier != 1 && totalWeight > 0) {
+ // loadServiceRajaOngkir();
+ // } else {
+ // setListServiceExpedisi();
+ // setBiayaKirim(0);
+ // setselectedExpedisiService();
+ // setEtd();
+ // }
+ // }, [selectedCarrier, selectedAddress, totalWeight]);
+
+ // useEffect(() => {
+ // if (selectedServiceType) {
+ // let serviceType = selectedServiceType.split(',');
+ // setBiayaKirim(serviceType[0]);
+ // setselectedExpedisiService(serviceType[1]);
+ // setEtd(serviceType[2]);
+ // }
+ // }, [selectedServiceType]);
+
+ // useEffect(() => {
+ // if (etd) setEtdFix(calculateEstimatedArrival(etd));
+ // }, [etd]);
+
+ // useEffect(() => {
+ // if (selectedExpedisi) {
+ // let serviceType = selectedExpedisi.split(',');
+ // if (serviceType[0] === 0) return;
+
+ // setselectedCarrier(serviceType[0]);
+ // setselectedCarrierId(serviceType[1]);
+ // setListServiceExpedisi([]);
+ // }
+ // }, [selectedExpedisi]);
const poNumber = useRef(null);
const poFile = useRef(null);
@@ -403,7 +404,7 @@ const Checkout = () => {
});
return;
}
- if (selectedExpedisi === 0) {
+ if (selectedCourier === 0 || !selectedCourier) {
setCheckoutValidation(true);
if (expedisiValidation.current) {
const position = expedisiValidation.current.getBoundingClientRect();
@@ -414,7 +415,11 @@ const Checkout = () => {
}
return;
}
- if (selectedCarrier != 1 && biayaKirim == 0) {
+ if(!selectedService){
+ toast.error('Harap pilih tipe layanan pengiriman');
+ return;
+ }
+ if (selectedCourier != 1 && biayaKirim == 0) {
toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
return;
}
@@ -432,15 +437,14 @@ const Checkout = () => {
user_id: auth.id,
order_line: JSON.stringify(productOrder),
delivery_amount: biayaKirim,
- carrier_id: selectedCarrierId,
- estimated_arrival_days: splitDuration(etd),
- delivery_service_type: selectedExpedisiService,
+ carrier_id: selectedCourier,
+ estimated_arrival_days: getToDate(etd, unit),
+ delivery_service_type: selectedService?.service_type,
flash_sale: hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false
voucher: activeVoucher,
voucher_shipping: activeVoucherShipping,
type: 'sale_order',
};
-
if (query) {
data.source = 'buy';
}
@@ -487,24 +491,6 @@ const Checkout = () => {
)}`;
}
}
-
- /* const midtrans = async () => {
- for (const product of products) deleteItemCart({ productId: product.id });
- if (grandTotal > 0) {
- const payment = await axios.post(
- `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${isCheckouted.id}`
- );
- setIsLoading(false);
- window.location.href = payment.data.redirectUrl;
- } else {
- window.location.href = `${
- process.env.NEXT_PUBLIC_SELF_HOST
- }/shop/checkout/success?order_id=${isCheckouted.name.replace(
- /\//g,
- '-'
- )}`;
- }
- };*/
};
const handlingActivateCode = async () => {
@@ -569,9 +555,6 @@ const Checkout = () => {
cartCheckout?.discountVoucher +
(cartCheckout?.discountVoucherShipping || 0);
-
- console.log('etd', etd, calculateEstimatedArrival(etd), splitDuration(etd));
-
return (
<>
{
)}
- {
+ /> */}
{!!products &&
@@ -1168,7 +1151,7 @@ const Checkout = () => {
- Biaya Kirim
{etdFix}
+ Biaya Kirim
{formatShipmentRange(etd, unit)}
{currencyFormat(
@@ -1367,7 +1350,7 @@ const Checkout = () => {
{products &&
}
-
{
+ /> */}
Detail Pesanan
@@ -1474,7 +1457,7 @@ const Checkout = () => {
Biaya Kirim
-
{etdFix}
+
{formatShipmentRange(etd, unit)}
{currencyFormat(
diff --git a/src/lib/checkout/components/SectionExpedition.jsx b/src/lib/checkout/components/SectionExpedition.jsx
index 27224e5b..be40a577 100644
--- a/src/lib/checkout/components/SectionExpedition.jsx
+++ b/src/lib/checkout/components/SectionExpedition.jsx
@@ -1,4 +1,4 @@
-import { Spinner } from '@chakra-ui/react';
+import { Skeleton, Spinner } from '@chakra-ui/react';
import axios from 'axios';
import { AnimatePresence, motion } from 'framer-motion';
import React, { useState } from 'react';
@@ -14,15 +14,25 @@ function mappingItems(products) {
name: item.parent.name,
description: `${item.code} - ${item.name}`,
value: item.price.priceDiscount,
- weight: item.weight * 1000 * item.quantity,
+ weight: item.weight * 1000,
quantity: item.quantity,
canInstant: item.availableQuantity > item.quantity ? true : false,
}));
}
-function mappingCourier(couriers, notIncludeInstant = false) {
+function mappingCourier(couriersOdoo, couriers, notIncludeInstant = false) {
+ const validCourierMap = couriersOdoo.reduce((acc, courier) => {
+ acc[courier.label.toLowerCase()] = courier.carrierId;
+ return acc;
+ }, {});
+
return couriers?.reduce((result, item) => {
- const { courier_code, courier_service_code } = item;
+ const { courier_name, courier_code, courier_service_code } = item;
+ if (!validCourierMap[courier_name.toLowerCase()]) {
+ return result; // Jika tidak ada, lewati item ini
+ }
+
+
if (
notIncludeInstant &&
['hours'].includes(item.shipment_duration_unit.toLowerCase())
@@ -30,16 +40,20 @@ function mappingCourier(couriers, notIncludeInstant = false) {
return result;
}
+ const carrierId = validCourierMap[courier_name];
+
// Jika courier_code belum ada di result, buat objek baru untuknya
if (!result[courier_code]) {
result[courier_code] = {
courier_name: item.courier_name,
courier_code: courier_code,
+ courier_id_odoo : carrierId,
service_type: {
[courier_service_code]: {
service_name: item.courier_service_name,
duration: item.duration,
- shipment_duration: item.duration,
+ shipment_range: item.shipment_duration_range,
+ shipment_unit: item.shipment_duration_unit,
price: item.price,
service_type: item.service_type,
description: item.description,
@@ -50,6 +64,8 @@ function mappingCourier(couriers, notIncludeInstant = false) {
result[courier_code].service_type[courier_service_code] = {
service_name: item.courier_service_name,
duration: item.duration,
+ shipment_range: item.shipment_duration_range,
+ shipment_unit: item.shipment_duration_unit,
shipment_duration: item.duration,
price: item.price,
service_type: item.service_type,
@@ -92,18 +108,27 @@ function hasCanInstantFalse(items) {
export default function SectionExpedition({ products }) {
const { addressMaps, coordinate, postalCode } = useAddress();
const { control, handleSubmit } = useForm();
- const [selectedCourier, setSelectedCourier] = useState('');
const [serviceOptions, setServiceOptions] = useState([]);
- const [selectedService, setSelectedService] = useState(null);
const [isOpen, setIsOpen] = useState(false);
+ const [onFocusSelectedCourier, setOnFocuseSelectedCourier] = useState(false);
- const { checkWeigth, checkoutValidation } = useCheckout();
+ const {
+ checkWeigth,
+ checkoutValidation,
+ setBiayaKirim,
+ setUnit,
+ setEtd,
+ selectedCourier,
+ setSelectedCourier,
+ selectedService,
+ setSelectedService,
+ listExpedisi,
+ } = useCheckout();
let destination = {};
let items = mappingItems(products);
let notIncludeInstant = hasCanInstantFalse(items);
- console.log('instanCourier', items);
if (addressMaps) {
destination = {
origin_latitude: -6.3031123,
@@ -112,7 +137,7 @@ export default function SectionExpedition({ products }) {
};
} else if (postalCode) {
destination = {
- origin_postal_code: 12440,
+ origin_postal_code: 14440,
destination_postal_code: postalCode,
};
}
@@ -141,23 +166,26 @@ export default function SectionExpedition({ products }) {
enabled:
Boolean(Object.keys(destination).length) &&
items?.length > 0 &&
- !checkWeigth,
+ !checkWeigth &&
+ onFocusSelectedCourier,
staleTime: Infinity,
cacheTime: Infinity,
}
);
- console.log('data', data);
+ const couriers =
+ mappingCourier(listExpedisi, data?.data?.pricing, notIncludeInstant) ||
+ null;
- const couriers = mappingCourier(data?.data?.pricing, true) || null;
+ console.log('ini scourier', data?.data?.pricing)
const onCourierChange = (e) => {
setIsOpen(false);
const courier = e.target.value;
setSelectedService(null);
setSelectedCourier(courier);
- console.log('courier', courier);
- // Menentukan layanan berdasarkan pengiriman yang dipilih
+ // setSelectedCourierId(Object.values(couriers[courier]?.courier_id_odoo);
+ setBiayaKirim(0);
if (courier && courier !== '0' && courier !== '32' && couriers[courier]) {
setServiceOptions(Object.values(couriers[courier]?.service_type));
} else {
@@ -165,12 +193,15 @@ export default function SectionExpedition({ products }) {
}
};
- const onSubmit = (data) => {
+ const onSubmit = (data) => {1
console.log(data);
};
const handleSelect = (service) => {
setSelectedService(service);
+ setBiayaKirim(service?.price);
+ setEtd(service?.shipment_range);
+ setUnit(service?.shipment_unit);
setIsOpen(false);
};
@@ -184,37 +215,38 @@ export default function SectionExpedition({ products }) {
setOnFocuseSelectedCourier(true)}
required
>
- Pilih Pengiriman
- SELF PICKUP
- {couriers &&
- Object.values(couriers)?.map((expedisi) => (
-
- {' '}
- {expedisi.courier_name}
+ {!isLoading ? (
+ <>
+ Pilih Pengiriman
+ SELF PICKUP
+ {couriers &&
+ Object.values(couriers)?.map((expedisi) => (
+
+ {' '}
+ {expedisi.courier_name}
+
+ ))}
+ >
+ ) : (
+ <>
+
+
- ))}
-
-
-
- {isLoading && (
-
-
-
+
+
+
+
+
+
+ >
)}
-
+
{checkoutValidation && (
--
cgit v1.2.3
From d1592286eef165533c21d52aec70dbb703cdcfd3 Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Wed, 18 Dec 2024 15:03:52 +0700
Subject: feedback uat
---
src/lib/checkout/components/Checkout.jsx | 2 +-
src/lib/checkout/components/SectionExpedition.jsx | 24 ++++++++++++++++-------
2 files changed, 18 insertions(+), 8 deletions(-)
(limited to 'src/lib/checkout/components')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 38e11038..0471dc6c 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -430,7 +430,7 @@ const Checkout = () => {
available_quantity: product?.availableQuantity,
}));
let data = {
- // partner_shipping_id: auth.partnerId,
+ // partner_shipping_id: auth.partnerId,,
// partner_invoice_id: auth.partnerId,
partner_shipping_id: selectedAddress?.shipping?.id || auth.partnerId,
partner_invoice_id: selectedAddress?.invoicing?.id || auth.partnerId,
diff --git a/src/lib/checkout/components/SectionExpedition.jsx b/src/lib/checkout/components/SectionExpedition.jsx
index be40a577..2098d5b5 100644
--- a/src/lib/checkout/components/SectionExpedition.jsx
+++ b/src/lib/checkout/components/SectionExpedition.jsx
@@ -8,6 +8,7 @@ import { useAddress } from '../stores/useAdress';
import currencyFormat from '@/core/utils/currencyFormat';
import { useCheckout } from '../stores/stateCheckout';
+import { formatShipmentRange } from '../utils/functionCheckouit';
function mappingItems(products) {
return products?.map((item) => ({
@@ -32,7 +33,6 @@ function mappingCourier(couriersOdoo, couriers, notIncludeInstant = false) {
return result; // Jika tidak ada, lewati item ini
}
-
if (
notIncludeInstant &&
['hours'].includes(item.shipment_duration_unit.toLowerCase())
@@ -47,7 +47,7 @@ function mappingCourier(couriersOdoo, couriers, notIncludeInstant = false) {
result[courier_code] = {
courier_name: item.courier_name,
courier_code: courier_code,
- courier_id_odoo : carrierId,
+ courier_id_odoo: carrierId,
service_type: {
[courier_service_code]: {
service_name: item.courier_service_name,
@@ -177,7 +177,7 @@ export default function SectionExpedition({ products }) {
mappingCourier(listExpedisi, data?.data?.pricing, notIncludeInstant) ||
null;
- console.log('ini scourier', data?.data?.pricing)
+ console.log('ini scourier', data?.data?.pricing);
const onCourierChange = (e) => {
setIsOpen(false);
@@ -193,7 +193,8 @@ export default function SectionExpedition({ products }) {
}
};
- const onSubmit = (data) => {1
+ const onSubmit = (data) => {
+ 1;
console.log(data);
};
@@ -292,7 +293,10 @@ export default function SectionExpedition({ products }) {
{selectedService.service_name}
- {currencyFormat(selectedService.price)}
+ {currencyFormat(
+ Math.round(parseInt(selectedService?.price * 1.1) / 1000) *
+ 1000
+ )}
) : (
@@ -316,11 +320,17 @@ export default function SectionExpedition({ products }) {
{service.service_name}
- Estimasi Tiba {service.duration}
+ {formatShipmentRange(
+ service.shipment_range,
+ service.shipment_unit
+ )}
- {currencyFormat(service.price)}
+ {currencyFormat(
+ Math.round(parseInt(service?.price * 1.1) / 1000) *
+ 1000
+ )}
))}
--
cgit v1.2.3
From 5559770e0b0e94b68de1e31bf2be5c978362821d Mon Sep 17 00:00:00 2001
From: trisusilo48
Date: Tue, 31 Dec 2024 09:01:10 +0700
Subject: logo and mapping courier
---
src/lib/checkout/components/Checkout.jsx | 1 +
src/lib/checkout/components/SectionExpedition.jsx | 214 ++++++++++++++++------
2 files changed, 158 insertions(+), 57 deletions(-)
(limited to 'src/lib/checkout/components')
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 0471dc6c..99c7b40a 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -279,6 +279,7 @@ const Checkout = () => {
value: expedisi.id,
label: expedisi.name,
carrierId: expedisi.deliveryCarrierId,
+ logo : expedisi.image,
}));
setExpedisi(dataExpedisi);
};
diff --git a/src/lib/checkout/components/SectionExpedition.jsx b/src/lib/checkout/components/SectionExpedition.jsx
index 2098d5b5..8b59d210 100644
--- a/src/lib/checkout/components/SectionExpedition.jsx
+++ b/src/lib/checkout/components/SectionExpedition.jsx
@@ -1,7 +1,7 @@
import { Skeleton, Spinner } from '@chakra-ui/react';
import axios from 'axios';
import { AnimatePresence, motion } from 'framer-motion';
-import React, { useState } from 'react';
+import React, { useEffect, useRef, useState } from 'react';
import { useForm } from 'react-hook-form';
import { useQuery } from 'react-query';
import { useAddress } from '../stores/useAdress';
@@ -9,6 +9,8 @@ import { useAddress } from '../stores/useAdress';
import currencyFormat from '@/core/utils/currencyFormat';
import { useCheckout } from '../stores/stateCheckout';
import { formatShipmentRange } from '../utils/functionCheckouit';
+import Image from 'next/image';
+import toast from 'react-hot-toast';
function mappingItems(products) {
return products?.map((item) => ({
@@ -21,6 +23,57 @@ function mappingItems(products) {
}));
}
+function reverseMappingCourier(couriersOdoo, couriers) {
+ // Buat peta courier berdasarkan nama courier dari couriers
+ const courierMap = couriers.reduce((acc, item) => {
+ const { courier_name, courier_code, courier_service_code } = item;
+ const key = courier_name.toLowerCase();
+
+ if (!acc[key]) {
+ acc[key] = {
+ courier_name: item.courier_name,
+ courier_code: courier_code,
+ service_type: {},
+ };
+ }
+
+ acc[key].service_type[courier_service_code] = {
+ service_name: item.courier_service_name,
+ duration: item.duration,
+ shipment_range: item.shipment_duration_range,
+ shipment_unit: item.shipment_duration_unit,
+ price: item.price,
+ service_type: item.service_type,
+ description: item.description,
+ };
+
+ return acc;
+ }, {});
+
+ // Iterasi berdasarkan couriersOdoo
+ return couriersOdoo.map((courierOdoo) => {
+ const courierNameKey = courierOdoo.label.toLowerCase();
+ const carrierId = courierOdoo.carrierId;
+
+ const mappedCourier = courierMap[courierNameKey] || false;
+
+ if (!mappedCourier) {
+ return {
+ ...courierOdoo,
+ courier: false,
+ };
+ }
+
+ return {
+ ...courierOdoo,
+ courier: {
+ ...mappedCourier,
+ courier_id_odoo: carrierId,
+ },
+ };
+ });
+}
+
function mappingCourier(couriersOdoo, couriers, notIncludeInstant = false) {
const validCourierMap = couriersOdoo.reduce((acc, courier) => {
acc[courier.label.toLowerCase()] = courier.carrierId;
@@ -110,7 +163,9 @@ export default function SectionExpedition({ products }) {
const { control, handleSubmit } = useForm();
const [serviceOptions, setServiceOptions] = useState([]);
const [isOpen, setIsOpen] = useState(false);
+ const [selectedE, setIsOpenCourier] = useState(false);
const [onFocusSelectedCourier, setOnFocuseSelectedCourier] = useState(false);
+ const [couriers, setCouriers] = useState(null);
const {
checkWeigth,
@@ -173,22 +228,31 @@ export default function SectionExpedition({ products }) {
}
);
- const couriers =
- mappingCourier(listExpedisi, data?.data?.pricing, notIncludeInstant) ||
- null;
+ console.log('ini response', data);
- console.log('ini scourier', data?.data?.pricing);
+ useEffect(() => {
+ if (data) {
+ const couriers = reverseMappingCourier(listExpedisi, data?.data?.pricing);
+ setCouriers(couriers);
+ console.log('ini scourier', couriers);
+ }
+ }, [data]);
- const onCourierChange = (e) => {
+ const onCourierChange = (code) => {
setIsOpen(false);
- const courier = e.target.value;
+ setOnFocuseSelectedCourier(false);
+ const courier = code;
setSelectedService(null);
- setSelectedCourier(courier);
- // setSelectedCourierId(Object.values(couriers[courier]?.courier_id_odoo);
setBiayaKirim(0);
- if (courier && courier !== '0' && courier !== '32' && couriers[courier]) {
- setServiceOptions(Object.values(couriers[courier]?.service_type));
+ if (courier !== 0 && courier !== 32) {
+ if (courier.courier) {
+ setSelectedCourier(courier.courier.courier_code);
+ setServiceOptions(Object.values(courier.courier.service_type));
+ } else {
+ toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
+ }
} else {
+ setSelectedCourier(courier === 32 ? 'SELF PICKUP' : null);
setServiceOptions([]);
}
};
@@ -198,6 +262,11 @@ export default function SectionExpedition({ products }) {
console.log(data);
};
+ const handleOnFocuse = (value) => {
+ setOnFocuseSelectedCourier(!value);
+ setIsOpen(false);
+ };
+
const handleSelect = (service) => {
setSelectedService(service);
setBiayaKirim(service?.price);
@@ -206,48 +275,79 @@ export default function SectionExpedition({ products }) {
setIsOpen(false);
};
+ console.log('ini selectedCourier', selectedCourier);
+
return (