From ff73ed876e8516ed1a3cfef1d5f8381a2d9ca70e Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 28 Aug 2025 14:25:45 +0700 Subject: Show bayar sekarang in detail transaction --- src/lib/transaction/components/Transaction.jsx | 515 ++++++++----------------- 1 file changed, 165 insertions(+), 350 deletions(-) (limited to 'src/lib') diff --git a/src/lib/transaction/components/Transaction.jsx b/src/lib/transaction/components/Transaction.jsx index 77e60dc1..cc5f862c 100644 --- a/src/lib/transaction/components/Transaction.jsx +++ b/src/lib/transaction/components/Transaction.jsx @@ -43,13 +43,14 @@ import { gtagPurchase } from '@/core/utils/googleTag'; import { deleteItemCart } from '@/core/utils/cart'; import { downloadInvoice, - downloadTaxInvoice, + // downloadTaxInvoice, // (unused) } from '@/lib/invoice/utils/invoices'; import { Download } from 'lucide-react'; import axios from 'axios'; import InformationSection from '../../treckingAwb/component/InformationSection'; -import { Button } from '@chakra-ui/react'; -import { div } from 'lodash-contrib'; +// import { Button } from '@chakra-ui/react'; // (unused) +// import { div } from 'lodash-contrib'; // (unused) + const Transaction = ({ id }) => { const PPN = process.env.NEXT_PUBLIC_PPN; const router = useRouter(); @@ -73,6 +74,7 @@ const Transaction = ({ id }) => { const [toOthers, setToOthers] = useState(null); const [totalAmount, setTotalAmount] = useState(0); const [totalDiscountAmount, setTotalDiscountAmount] = useState(0); + const [contLoading, setContLoading] = useState(false); useEffect(() => { if (transaction?.data?.products) { @@ -88,6 +90,7 @@ const Transaction = ({ id }) => { setTotalDiscountAmount(calculateTotalDiscountAmount); } }, [transaction.data, transaction.isLoading]); + const submitUploadPo = async () => { const file = poFile.current.files[0]; const name = poNumber.current.value; @@ -127,10 +130,6 @@ const Transaction = ({ id }) => { } } }; - // const ContinueTransaction = () => { - // setContinueNoPo(true); - // checkoutNoPO(); - // }; const closeCancelTransaction = () => setCancelTransaction(false); const closeContinueTransaction = () => setContinueTransaction(false); @@ -138,6 +137,7 @@ const Transaction = ({ id }) => { const openRejectTransaction = () => setRejectTransaction(true); const closeRejectTransaction = () => setRejectTransaction(false); + const submitCancelTransaction = async () => { const isCancelled = await cancelTransactionApi({ transaction: transaction.data, @@ -148,6 +148,7 @@ const Transaction = ({ id }) => { } closeCancelTransaction(); }; + const checkout = async () => { if (!transaction.data?.purchaseOrderFile) { toast.error('Mohon upload dokumen PO anda sebelum melanjutkan pesanan'); @@ -194,25 +195,6 @@ const Transaction = ({ id }) => { } toast.success('Berhasil melanjutkan pesanan'); transaction.refetch(); - // console.log(transaction); - - /* 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 handleApproval = async () => { @@ -227,6 +209,36 @@ const Transaction = ({ id }) => { transaction.refetch(); }; + // ===== Bayar Sekarang (pakai link dari backend; fallback generate via Next API) ===== + const handlePayNow = async () => { + try { + setContLoading(true); + // 1) gunakan URL yang sudah dikirim backend (jika ada) + const existingUrl = + transaction?.data?.paymentSummary?.redirectUrl || + transaction?.data?.paymentLinkMidtrans || + ''; + if (existingUrl) { + window.open(existingUrl, '_blank', 'noopener,noreferrer'); + toast.success('Membuka halaman pembayaran…'); + return; + } + // 2) fallback: panggil Next API untuk generate + const res = await axios.post( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/midtrans-payment?transactionId=${transaction.data.id}` + ); + window.location.href = res.data.redirectUrl; + } catch (e) { + toast.error( + e?.response?.data?.description || + e?.message || + 'Gagal membuka pembayaran' + ); + } finally { + setContLoading(false); + } + }; + const memoizeVariantGroupCard = useMemo( () => (
@@ -314,7 +326,7 @@ const Transaction = ({ id }) => { navigator.clipboard.writeText(textToCopy); setCopied(true); toast.success('No Resi Berhasil di Copy'); - setTimeout(() => setCopied(false), 2000); // Reset copied state after 2 seconds + setTimeout(() => setCopied(false), 2000); }; const formatDate = (dateString) => { @@ -336,7 +348,7 @@ const Transaction = ({ id }) => { const [day, month, year] = dateString.split('/'); return `${day} ${months[parseInt(month, 10) - 1]} ${year}`; }; - // console.log(transaction); + return ( transaction.data?.name && ( <> @@ -366,6 +378,7 @@ const Transaction = ({ id }) => {
+ { + {/* ============ MOBILE ============ */}
- + {auth?.feature?.soApproval && (
{
-

Detail Order

+

Detail Order

{transaction.data?.name}

@@ -579,9 +594,11 @@ const Transaction = ({ id }) => {
-

Alamat Pengiriman

+

Alamat Pengiriman

-

{transaction?.data?.address?.customer?.name}

+

+ {transaction?.data?.address?.customer?.name} +

{transaction?.data?.address?.customer?.phone @@ -602,9 +619,7 @@ const Transaction = ({ id }) => {
Info Pengiriman
{transaction?.data?.pickings.length == 0 && ( -
- Belum ada pengiriman -
+
Belum ada pengiriman
)} {transaction?.data?.pickings?.map((airway) => (
{
- // ))} -
@@ -717,17 +711,20 @@ const Transaction = ({ id }) => {
Detail Produk
{transaction?.data?.products.length > 0 ? (
- +
Rincian Pembayaran

Metode Pembayaran

-

- {transaction.data?.paymentTerm || '-'} -

+

{transaction.data?.paymentTerm || '-'}

Berat Barang

-

{(transaction.data?.products?.reduce((total, item) => total + (item.weight || 0), 0)) + ' Kg'}

+

+ {transaction.data?.products?.reduce( + (total, item) => total + (item.weight || 0), + 0 + ) + ' Kg'} +


@@ -774,12 +771,7 @@ const Transaction = ({ id }) => {
)} - {/* */} - - {/* */} - - {/* */} - + {/* Tombol aksi (Mobile) */} {transaction.data?.status === 'draft' && (
{transaction.data?.status == 'draft' && - transaction?.data?.purchaseOrderFile && ( - - )} + transaction?.data?.purchaseOrderFile && ( + + )} +
+ )} + + {/* Bayar Sekarang (Mobile) — tampil jika eligible */} + {transaction.data?.eligibleContinue && ( +
+
)} + {/* ============ DESKTOP ============ */}
@@ -827,44 +834,36 @@ const Transaction = ({ id }) => { )}
- {/*new-release*/} - {/*
*/} - {/*
*/} - {/* */} - {/* {transaction?.data?.name}*/} - {/* */} - {/* */} - {/*
*/} - {/*
*/} - {/* Estimasi Barang Siap:{' '}*/} - {/* */} - {/* {transaction?.data?.expectedReadyToShip}*/} - {/* */} - {/*
*/} -
- - {transaction?.data?.name} - - - {transaction.data?.status === 'draft' && ( -
- + {/* HEADER (Desktop) — sejajarkan kiri & kanan */} +
+ {/* Kiri: SO + badge */} +
+ + {transaction?.data?.name} + + +
+ + {/* Kanan: aksi */} +
+ {transaction.data?.status === 'draft' && ( + <> + -
- {transaction.data?.status == 'draft' && - transaction?.data?.purchaseOrderFile && ( + + {transaction?.data?.purchaseOrderFile && ( )} -
-
- )} -
- {/* {transaction.data?.status === 'draft' && ( -
- - - - {transaction.data?.status == 'draft' && - transaction?.data?.purchaseOrderFile && ( - - )} + + )} + + {transaction.data?.eligibleContinue && ( + + )}
- )} */} +
@@ -967,29 +949,13 @@ const Transaction = ({ id }) => { key={index} > {invoice?.name} - {/*
-
-

{invoice?.name}

-
- {invoice.amountResidual > 0 ? ( -
Belum Lunas
- ) : ( -
Lunas
- )} -

- {currencyFormat(invoice.amountTotal)} -

-
-
- -
*/} ))}

- {/*
*/} +
@@ -1039,17 +1005,17 @@ const Transaction = ({ id }) => { ) : ( '-' )} - {transaction?.data?.carrierId !== 32 &&( - <> -
Jenis Service
-
:
-
- {' '} - {transaction?.data?.serviceType - ? transaction?.data?.serviceType - : '-'} -
- + {transaction?.data?.carrierId !== 32 && ( + <> +
Jenis Service
+
:
+
+ {' '} + {transaction?.data?.serviceType + ? transaction?.data?.serviceType + : '-'} +
+ )}
Estimasi Tanggal Kirim
@@ -1059,41 +1025,42 @@ const Transaction = ({ id }) => { ? transaction?.data?.expectedReadyToShip : '-'}
- {transaction?.data?.carrierId !== 32 &&( - <> -
Estimasi Tiba
-
:
-
- {transaction?.data?.etaDateStart && transaction?.data?.etaDateEnd ? ( - `${transaction.data.etaDateStart} - ${transaction.data.etaDateEnd}` - ) : ( - '-' - )} -
- + {transaction?.data?.carrierId !== 32 && ( + <> +
Estimasi Tiba
+
:
+
+ {transaction?.data?.etaDateStart && + transaction?.data?.etaDateEnd + ? `${transaction.data.etaDateStart} - ${transaction.data.etaDateEnd}` + : '-'} +
+ )} - {transaction?.data?.pickings[0] && transaction?.data?.carrierId !== 32 && ( -
- - )} + )}
@@ -1103,9 +1070,7 @@ const Transaction = ({ id }) => {
{transaction?.data?.pickings.length == 0 && ( -
- Belum ada pengiriman -
+
Belum ada pengiriman
)} {transaction?.data?.pickings?.map((airway) => (
{
))} - {/*
*/} -
- {/*New release*/} - {/*
*/} - {/* {transaction?.data?.pickings?.map((airway) => (*/} - {/* setIdAWB(airway?.id)}*/} - {/* >*/} - {/*
*/} - {/*

*/} - {/* {airway?.name}*/} - {/*

*/} - {/* */} - {/* No Resi : {airway?.trackingNumber || '-'}{' '}*/} - {/* */} - {/*
*/} - {/*
*/} - {/*
*/} - {/* {airway?.delivered*/} - {/* ? 'Pesanan Tiba'*/} - {/* : 'Sedang Dikirim'}*/} - {/*
*/} - {/* */} - {/*
*/} - {/* */} - {/* ))}*/} - {/*
*/} - {/*
*/}
Invoice @@ -1202,7 +1137,6 @@ const Transaction = ({ id }) => { Nama Produk - {/* Diskon */} Jumlah Harga Subtotal @@ -1280,24 +1214,13 @@ const Transaction = ({ id }) => { )}
- {/* - {product.price.discountPercentage > 0 - ? `${product.price.discountPercentage}%` - : ''} - */} {product.quantity} - {/* {product.price.discountPercentage > 0 && ( -
- {currencyFormat(product.price.price)} -
- )} */}
{currencyFormat(product.price.priceDiscount)}
{currencyFormat(product.price.subtotal)} - {/* {auth?.feature.soApproval && (auth.webRole == 2 || auth.webRole == 3) && (transaction.data.isReaject == false) && ( */} {auth?.feature.soApproval && (auth.webRole == 2 || auth.webRole == 3) && router.asPath.includes('/my/quotations/') && @@ -1354,34 +1277,6 @@ const Transaction = ({ id }) => { )} {transaction?.data?.products?.length > 0 && ( - //
- //
- //
Subtotal
- //
- // {currencyFormat(transaction.data?.amountUntaxed)} - //
- - //
- // PPN {((PPN - 1) * 100).toFixed(0)}% - //
- //
- // {currencyFormat(transaction.data?.amountTax)} - //
- - //
- // Biaya Pengiriman - //
- //
- // {currencyFormat(transaction.data?.deliveryAmount)} - //
- - //
Grand Total
- //
- // {currencyFormat(transaction.data?.amountTotal)} - //
- //
- //
-
Total Belanja
@@ -1437,7 +1332,6 @@ const Transaction = ({ id }) => { Nama Produk - {/* Diskon */} Jumlah Harga Subtotal @@ -1480,18 +1374,8 @@ const Transaction = ({ id }) => {
- {/* - {product.price.discountPercentage > 0 - ? `${product.price.discountPercentage}%` - : ''} - */} {product.quantity} - {/* {product.price.discountPercentage > 0 && ( -
- {currencyFormat(product.price.price)} -
- )} */}
{currencyFormat(product.price.priceDiscount)}
@@ -1512,58 +1396,6 @@ const Transaction = ({ id }) => {
- - {/* {queryAirwayBill.data?.airways?.map((airway) => ( - setAirwayBillPopup(null)} - > -
-
-
No Pengiriman
-
{airway?.deliveryOrder?.name}
-
-
-
Kurir
-
{airway?.deliveryOrder?.carrier}
-
-
-
No Resi
-
{airway?.waybillNumber}
-
-
- -
-
Status Pengiriman
-
    - {airway?.manifests?.map((manifest, index) => ( -
  1. -
    - -

    - {manifest.description} -

    -
  2. - ))} - {(!airway?.manifests || airway?.manifests?.length == 0) && ( -
    Belum ada pengiriman
    - )} -
-
-
- ))} */} ) ); @@ -1589,24 +1421,7 @@ const SectionAddress = ({ address }) => { {section.customer && } - {/* - - toggleSection('shipping')} - /> - - {section.shipping && } - - - - toggleSection('invoice')} - /> - {section.invoice && } */} + {/* Bagian shipping/invoice disembunyikan */} ); }; -- cgit v1.2.3