From bfbb750c4df5eafe2599c7a9e36c9c15558deacd Mon Sep 17 00:00:00 2001 From: Vassshhh Date: Mon, 25 Aug 2025 03:47:47 +0700 Subject: [PATCH] ok --- src/components/ProductDetailPage.js | 55 ++++- src/components/pages/ProductsPage.js | 345 ++++++++++++++++++--------- 2 files changed, 277 insertions(+), 123 deletions(-) diff --git a/src/components/ProductDetailPage.js b/src/components/ProductDetailPage.js index a83168c..aa9a0f3 100644 --- a/src/components/ProductDetailPage.js +++ b/src/components/ProductDetailPage.js @@ -38,13 +38,36 @@ const ProductDetail = ({ willDo, setWillDo, subscriptions, product, requestLogin } // Auto check saat user mengetik (debounce) useEffect(() => { - if (product.unique_name == false) return; - const name = customName.trim(); + if (!name) { setStatus('idle'); return; } + + const isNameTaken = subscriptions?.some(sub => { + const isSameProduct = sub.product_id === product.id || sub.product_parent_id === product.id; + if (!isSameProduct) return false; + + const existingName = sub.product_name?.split('%%%')[0]?.trim().toLowerCase(); + return existingName === name.toLowerCase(); + }); + + + if (subscriptions && isNameTaken) { + setStatus('unavailable'); + return; + } + else if(!product.unique_name){ + setStatus('available'); + return; + } + + if (!product.unique_name) { + console.log(subscriptions); + return; + } + let cancelled = false; setStatus('checking'); @@ -79,7 +102,7 @@ const ProductDetail = ({ willDo, setWillDo, subscriptions, product, requestLogin subscriptions.some(sub => String(sub.product_id) === String(product.id) || String(sub.product_parent_id) === String(product.id) ); - + console.log(hasMatchingSubscription) // ✅ Check subscription first if (hasMatchingSubscription) { const matching = subscriptions.filter(sub => @@ -96,7 +119,7 @@ const ProductDetail = ({ willDo, setWillDo, subscriptions, product, requestLogin return; } else { const itemsParam = JSON.stringify([product.id]); - window.location.href = `https://checkout.kediritechnopark.com/?token=${token}&itemsId=${itemsParam}&set_name=${product.name}&redirect_uri=https://kediritechnopark.com/products&redirect_failed=https://kediritechnopark.com`; + window.location.href = `https://checkout.kediritechnopark.com/?token=${token}&itemsId=${itemsParam}&set_name=${product.name}&redirect_uri=https://kediritechnopark.com/dashboard&redirect_failed=https://kediritechnopark.com`; return; } } @@ -108,7 +131,7 @@ const ProductDetail = ({ willDo, setWillDo, subscriptions, product, requestLogin // Fallback: direct checkout const itemsParam = JSON.stringify([product.id]); - window.location.href = `https://checkout.kediritechnopark.com/?token=${token}&itemsId=${itemsParam}&redirect_uri=https://kediritechnopark.com/products&redirect_failed=https://kediritechnopark.com`; + window.location.href = `https://checkout.kediritechnopark.com/?token=${token}&itemsId=${itemsParam}&redirect_uri=https://kediritechnopark.com/dashboard&redirect_failed=https://kediritechnopark.com`; }; // ✅ Confirm child selection (final step after naming) @@ -124,7 +147,7 @@ const ProductDetail = ({ willDo, setWillDo, subscriptions, product, requestLogin const encodedName = encodeURIComponent(customName.trim() || product.name); const itemsParam = JSON.stringify(selectedChildIds); - window.location.href = `https://checkout.kediritechnopark.com/?token=${token}&itemsId=${itemsParam}&new_name=${encodedName}&redirect_uri=https://kediritechnopark.com/products&redirect_failed=https://kediritechnopark.com`; + window.location.href = `https://checkout.kediritechnopark.com/?token=${token}&itemsId=${itemsParam}&new_name=${encodedName}&redirect_uri=https://kediritechnopark.com/dashboard&redirect_failed=https://kediritechnopark.com`; }; // ✅ User sets name first → then if product has children, show child selector @@ -149,7 +172,7 @@ const ProductDetail = ({ willDo, setWillDo, subscriptions, product, requestLogin const itemsParam = JSON.stringify([product.id]); const encodedName = encodeURIComponent(customName.trim()); - window.location.href = `https://checkout.kediritechnopark.com/?token=${token}&itemsId=${itemsParam}&new_name=${encodedName}&redirect_uri=https://kediritechnopark.com/products&redirect_failed=https://kediritechnopark.com`; + window.location.href = `https://checkout.kediritechnopark.com/?token=${token}&itemsId=${itemsParam}&new_name=${encodedName}&redirect_uri=https://kediritechnopark.com/dashboard&redirect_failed=https://kediritechnopark.com`; }; const onConfirmSelector = () => { @@ -171,14 +194,26 @@ const ProductDetail = ({ willDo, setWillDo, subscriptions, product, requestLogin const productName = selectedSubscription?.product_name; const encodedName = encodeURIComponent(productName); - window.location.href = `https://checkout.kediritechnopark.com/?token=${token}&itemsId=${itemsParam}&set_name=${encodedName}&redirect_uri=https://kediritechnopark.com/products&redirect_failed=https://kediritechnopark.com`; + window.location.href = `https://checkout.kediritechnopark.com/?token=${token}&itemsId=${itemsParam}&set_name=${encodedName}&redirect_uri=https://kediritechnopark.com/dashboard&redirect_failed=https://kediritechnopark.com`; } }; useEffect(() => { - if (willDo === 'checkout') { + if (!product.executeCheckout && willDo === 'checkout') { onCheckout(); } + else if (product.children && product.children.length > 0) { + setShowChildSelector(true); + } + else { + + const tokenCookie = document.cookie.split('; ').find(row => row.startsWith('token=')); + const token = tokenCookie ? tokenCookie.split('=')[1] : ''; + const encodedName = encodeURIComponent(product.name); + const itemsParam = JSON.stringify([product.id]); + + window.location.href = `https://checkout.kediritechnopark.com/?token=${token}&itemsId=${itemsParam}&set_name=${encodedName}&redirect_uri=https://kediritechnopark.com/dashboard&redirect_failed=https://kediritechnopark.com`; + } if (setWillDo) setWillDo(''); }, []); @@ -318,7 +353,7 @@ const ProductDetail = ({ willDo, setWillDo, subscriptions, product, requestLogin style={{ width: '100%', padding: '8px', marginBottom: '8px', borderRadius: '10px' }} /> - {product.unique_name && } +
- + + + + Password Baru + + handleSettingsChange("password", e.target.value) + } + /> + + + + + Ketik Ulang Password + + + + + + + + + - -

My Orders

-

Orders list will be displayed here.

+ + + Riwayat Pembelian + + {purchaseHistory.length === 0 ? ( +

Tidak ada riwayat pembelian.

+ ) : ( + + {purchaseHistory + .sort((a, b) => new Date(b.created_at) - new Date(a.created_at)) + .map((order, idx) => { + const createdAt = new Date(order.created_at); + + // Konversi status ke label yang lebih ramah pengguna + const statusLabel = { + failed: "Transaksi Dibatalkan", + pending: "Menunggu Pembayaran", + completed: "Sukses", + }[order.status] || order.status; + + // Tentukan warna/status visual + const statusVariant = { + failed: "danger", + pending: "warning", + completed: "success", + }[order.status] || "secondary"; + + return ( + + +
+
+ {order.product_name.replace(/\t/g, " ")} +
+ ID: {order.transaction_id} • {createdAt.toLocaleString("id-ID")} +
+
+
+ + {statusLabel} + +
+ Rp {order.amount.toLocaleString("id-ID")} +
+
+
+
+ + + +

Metode Pembayaran: {order.payment_method || "N/A"}

+

Status: {statusLabel}

+

Tanggal Transaksi: {createdAt.toLocaleString("id-ID")}

+ + + {order.status == 'failed' && ( +
+

+ Jika Anda sudah melakukan pembayaran, silakan konfirmasi manual. +

+ +
+ )} + +
+
+
+ ); + })} +
+ )} +
+
+ + + );