summaryrefslogtreecommitdiff
path: root/src/lib/checkout/components
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-05-31 21:39:53 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-05-31 21:39:53 +0700
commit77f976d3bd09d9e00d4d55bbd40579b439405d96 (patch)
treea8959bba3d8a51570c439789f92653409a0065ae /src/lib/checkout/components
parentca05a70e98e9066882de6394ffbd89db7af2cb9d (diff)
parent2a1dea70b8f0062fe8eebeb7139a7b77a24e220b (diff)
Merge branch 'new-release' of https://bitbucket.org/altafixco/next-indoteknik into biteship-merge
# Conflicts: # src/lib/checkout/components/Checkout.jsx # src/lib/transaction/components/Transaction.jsx
Diffstat (limited to 'src/lib/checkout/components')
-rw-r--r--src/lib/checkout/components/Checkout.jsx275
-rw-r--r--src/lib/checkout/components/CheckoutSection.jsx2
-rw-r--r--src/lib/checkout/components/FinishCheckout.jsx9
3 files changed, 250 insertions, 36 deletions
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 637706a2..0b386c30 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -31,12 +31,12 @@ 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 { getVoucher } from '../api/getVoucher';
+import { findVoucher, getVoucher, getVoucherNew } 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;
const { checkoutApi } = require('../api/checkoutApi');
@@ -55,7 +55,9 @@ function convertToInternational(number) {
}
const Checkout = () => {
- const PPN = process.env.NEXT_PUBLIC_PPN ? parseFloat(process.env.NEXT_PUBLIC_PPN) : 0;
+ const PPN = process.env.NEXT_PUBLIC_PPN
+ ? parseFloat(process.env.NEXT_PUBLIC_PPN)
+ : 0;
const router = useRouter();
const query = router.query.source ?? null;
const qVoucher = router.query.voucher ?? null;
@@ -72,11 +74,18 @@ const Checkout = () => {
voucher: activeVoucher,
voucher_shipping: activeVoucherShipping,
}),
+ //biteship
{
keepPreviousData: true, // Menjaga data sebelumnya sampai data baru tersedia
}
);
+ // const [selectedAddress, setSelectedAddress] = useState({
+ // shipping: null,
+ // invoicing: null,
+ // });
+ // const [addresses, setAddresses] = useState(null);
+
const {
selectedAddress,
setSelectedAddress,
@@ -131,12 +140,17 @@ const Checkout = () => {
}
}, [addresses]);
+ // const [products, setProducts] = useState(null);
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);
+ //new release
+ // 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);
@@ -151,9 +165,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,
@@ -174,23 +190,37 @@ const Checkout = () => {
setExpedisi,
productSla
} = useCheckout();
-
const expedisiValidation = useRef(null);
const voucher = async () => {
if (!listVouchers) {
try {
setLoadingVoucher(true);
+ const productCategories = products
+ ?.reduce((categories, product) => {
+ if (product.categories && Array.isArray(product.categories)) {
+ product.categories.forEach((category) => {
+ if (category.id && !categories.includes(category.id)) {
+ categories.push(category.id);
+ }
+ });
+ }
+ return categories;
+ }, [])
+ .join(',');
+
let dataVoucher = await getVoucher(auth?.id, {
source: query,
type: 'all,brand',
- partner_id : auth?.partnerId,
+ partner_id: auth?.partnerId,
+ voucher_category: productCategories, // Add the product categories
});
SetListVoucher(dataVoucher);
let dataVoucherShipping = await getVoucher(auth?.id, {
source: query,
type: 'shipping',
+ voucher_category: productCategories, // Add the product categories
});
SetListVoucherShipping(dataVoucherShipping);
} finally {
@@ -200,16 +230,28 @@ const Checkout = () => {
};
const VoucherCode = async (code) => {
- // let dataVoucher = await findVoucher(code, auth.id, query);
+ const productCategories = products
+ ?.reduce((categories, product) => {
+ if (product.categories && Array.isArray(product.categories)) {
+ product.categories.forEach((category) => {
+ if (category.id && !categories.includes(category.id)) {
+ categories.push(category.id);
+ }
+ });
+ }
+ return categories;
+ }, [])
+ .join(',');
+
let dataVoucher = await getVoucher(auth?.id, {
source: query,
code: code,
+ voucher_category: productCategories, // Add the product categories
});
if (dataVoucher.length <= 0) {
SetFindVoucher(1);
return;
}
-
dataVoucher.forEach((addNewLine) => {
if (addNewLine.applyType !== 'shipping') {
@@ -320,6 +362,58 @@ 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;
@@ -337,6 +431,72 @@ 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]);
+ //
+
const poNumber = useRef(null);
const poFile = useRef(null);
@@ -374,10 +534,15 @@ const Checkout = () => {
}
return;
}
- if (!selectedService) {
- toast.error('Harap pilih tipe layanan pengiriman');
- return;
- }
+ //new release
+ // if (selectedCarrier != 1 && biayaKirim == 0) {
+ // toast.error('Maaf, layanan tidak tersedia. Mohon pilih expedisi lain.');
+ // return;
+ // }
+ // 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;
@@ -404,11 +569,16 @@ const Checkout = () => {
estimated_arrival_days_start : parseInt(eta_courier_start) + parseInt(productSla),
estimated_arrival_days: parseInt(eta_courier) + parseInt(productSla),
delivery_service_type: selectedService?.service_type,
+ // New release
+ // carrier_id: selectedCarrierId,
+ // estimated_arrival_days: splitDuration(etd),
+ // delivery_service_type: selectedExpedisiService,
flash_sale: hasFlashSale, // dibuat negasi untuk ngetest kebalikan nilai false
voucher: activeVoucher,
voucher_shipping: activeVoucherShipping,
type: 'sale_order',
};
+
if (query) {
data.source = 'buy';
}
@@ -469,6 +639,24 @@ 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 () => {
@@ -642,6 +830,19 @@ const Checkout = () => {
)}
<hr className='mt-8 mb-4 border-gray_r-8' />
+ {/* {!loadingVoucher &&
+ listVouchers?.length === 1 &&
+ listVoucherShippings?.length === 1}
+ {
+ <div className='flex items-center justify-center mt-4 mb-4'>
+ <div className='text-center'>
+ <h1 className='font-bold mb-4'>Tidak ada voucher tersedia</h1>
+ <p className='text-gray-500'>
+ Maaf, saat ini tidak ada voucher yang tersedia.
+ </p>
+ </div>
+ </div>
+ } */}
{listVoucherShippings && listVoucherShippings?.length > 0 && (
<div>
@@ -1027,21 +1228,22 @@ const Checkout = () => {
</Skeleton>
)}
<Divider />
- <SectionValidation address={selectedAddress.invoicing} />
- {/* <SectionExpedisi
- address={selectedAddress.shipping}
- listExpedisi={listExpedisi}
- setSelectedExpedisi={setSelectedExpedisi}
- checkWeigth={checkWeigth}
- checkoutValidation={checkoutValidation}
- expedisiValidation={expedisiValidation}
- loadingRajaOngkir={loadingRajaOngkir}
- />
- <Divider />
- <SectionListService
- listserviceExpedisi={listserviceExpedisi}
- setSelectedServiceType={setSelectedServiceType}
- /> */}
+ <SectionValidation address={selectedAddress.shipping} />
+ {/*new-relase*/}
+ {/*<SectionExpedisi*/}
+ {/* address={selectedAddress.shipping}*/}
+ {/* listExpedisi={listExpedisi}*/}
+ {/* setSelectedExpedisi={setSelectedExpedisi}*/}
+ {/* checkWeigth={checkWeigth}*/}
+ {/* checkoutValidation={checkoutValidation}*/}
+ {/* expedisiValidation={expedisiValidation}*/}
+ {/* loadingRajaOngkir={loadingRajaOngkir}*/}
+ {/* />*/}
+ {/* <Divider />*/}
+ {/* <SectionListService*/}
+ {/* listserviceExpedisi={listserviceExpedisi}*/}
+ {/* setSelectedServiceType={setSelectedServiceType}*/}
+ {/* />*/}
<div className='p-4 flex flex-col gap-y-4'>
{!!products &&
@@ -1123,7 +1325,9 @@ const Checkout = () => {
<div>{currencyFormat(cartCheckout?.subtotal)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
- <div className='text-gray_r-11'>PPN {((PPN - 1) * 100).toFixed(0)}%</div>
+ <div className='text-gray_r-11'>
+ PPN {((PPN - 1) * 100).toFixed(0)}%
+ </div>
<div>{currencyFormat(cartCheckout?.tax)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
@@ -1255,6 +1459,8 @@ const Checkout = () => {
className='flex-1 btn-yellow'
onClick={checkout}
disabled={
+ //new release
+ // isLoading ||
!products ||
products?.length == 0 ||
priceCheck ||
@@ -1328,7 +1534,7 @@ const Checkout = () => {
)}
{products && <SectionExpedition products={products} />}
<Divider />
- <SectionValidation address={selectedAddress.invoicing} />
+ <SectionValidation address={selectedAddress.shipping} />
{/* <SectionExpedisi
address={selectedAddress.shipping}
listExpedisi={listExpedisi}
@@ -1430,7 +1636,9 @@ const Checkout = () => {
<div>{currencyFormat(cartCheckout?.subtotal)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
- <div className='text-gray_r-11'>PPN {((PPN - 1) * 100).toFixed(0)}%</div>
+ <div className='text-gray_r-11'>
+ PPN {((PPN - 1) * 100).toFixed(0)}%
+ </div>
<div>{currencyFormat(cartCheckout?.tax)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
@@ -1560,6 +1768,8 @@ const Checkout = () => {
className='w-full btn-yellow mt-4'
onClick={checkout}
disabled={
+ // new-relase
+ // isLoading ||
!products ||
products?.length == 0 ||
priceCheck ||
@@ -1630,6 +1840,9 @@ const SectionAddress = ({ address, label, url }) => (
);
const SectionValidation = ({ address }) =>
+ //new release
+ // address?.stateId == 0 ||
+ // (address?.rajaongkirCityId == 0 && (
address?.stateId == 0 && (
<BottomPopup active={true} title='Update Alamat'>
<div className='leading-7 text-gray_r-12/80'>
@@ -1644,7 +1857,9 @@ const SectionValidation = ({ address }) =>
</Link>
</div>
</BottomPopup>
- );
+ )
+// )
+;
const SectionExpedisi = ({
address,
diff --git a/src/lib/checkout/components/CheckoutSection.jsx b/src/lib/checkout/components/CheckoutSection.jsx
index c82e15c7..c6be9056 100644
--- a/src/lib/checkout/components/CheckoutSection.jsx
+++ b/src/lib/checkout/components/CheckoutSection.jsx
@@ -33,7 +33,7 @@ export const SectionAddress = ({ address, label, url }) => {
};
export const SectionValidation = ({ address }) =>
- address?.stateId == 0 && (
+ address?.stateId == 0 || address?.rajaongkirCityId == 0 && (
<BottomPopup active={true} title='Update Alamat'>
<div className='leading-7 text-gray_r-12/80'>
Mohon untuk memperbarui alamat Anda dengan mengklik tombol di bawah ini.{' '}
diff --git a/src/lib/checkout/components/FinishCheckout.jsx b/src/lib/checkout/components/FinishCheckout.jsx
index 4a67b252..d533325e 100644
--- a/src/lib/checkout/components/FinishCheckout.jsx
+++ b/src/lib/checkout/components/FinishCheckout.jsx
@@ -53,13 +53,12 @@ const FinishCheckout = ({ query }) => {
height={isMobile ? 300 : 450}
/>
<div className='text-title-sm md:text-title-lg text-center font-semibold'>
- Terima Kasih atas Pembelian Kamu
+ Terima Kasih atas Pembelian di Indoteknik.com
</div>
+ <p className='text-title-sm md:text-title-lg font-semibold my-2'>No. Transaksi: <span className='text-red-500'>{query?.order_id?.replaceAll('-', '/')}</span></p>
<div className='flex flex-col justify-center items-center text-body-2 md:text-body-1 text-center mt-3 px-24 md:px-36 py-4 border-2 gap-y-2 rounded'>
- <p className='font-bold'>No. Transaksi</p>
- <p className='mb-2 font-medium text-red-500 text-xl'>
- {query?.order_id?.replaceAll('-', '/')}
- </p>
+ <p className="text-title-sm md:text-title-xl text-gray-500 mt-1">Estimasi Barang Siap pada Tanggal</p>
+ <p className="text-title-sm md:text-title-xl text-red-500 font-semibold my-2">{data?.expectedReadyToShip}</p>
<Link
href={`/my/quotations/${data?.id}`}
className='btn-solid-red rounded-md text-base'