diff --git a/src/App.css b/src/App.css index 74b5e05..5a88201 100644 --- a/src/App.css +++ b/src/App.css @@ -1,5 +1,15 @@ .App { text-align: center; + + height: 100vh; + width: 100vw; + position: absolute; + top: 0; + overflow: hidden; + display: flex; + align-items: center; + justify-content: center; + background-color: #dfdfdf; } .App-logo { diff --git a/src/Checkout.css b/src/Checkout.css deleted file mode 100644 index 09f3bd8..0000000 --- a/src/Checkout.css +++ /dev/null @@ -1,327 +0,0 @@ -.checkout-container { - display: flex; - flex-direction: row; - border-radius: 12px; - overflow: hidden; - box-shadow: 0 0 20px rgba(0,0,0,0.2); - max-width: 900px; - margin: 40px auto; - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, - Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif; -} - -.left-panel { - background-color: #2e2a4a; - color: white; - flex: 1; - padding: 40px 30px; - display: flex; - flex-direction: column; - gap: 20px; - position: relative; -} - -.back-arrow { - font-size: 20px; - cursor: pointer; - margin-bottom: 10px; - user-select: none; -} - -.brand-name { - font-weight: 600; - font-size: 14px; - opacity: 0.8; -} - -.product-name { - font-weight: 600; - font-size: 24px; -} - -.product-price { - font-weight: 600; - font-size: 32px; - margin-bottom: 20px; -} - -.product-image-container { - background-color: #b7c4f9; - border-radius: 8px; - padding: 20px; - display: flex; - justify-content: center; - align-items: center; - max-width: 300px; - max-height: 300px; -} - -.product-image-container img { - max-width: 100%; - max-height: 100%; - object-fit: contain; -} - -.right-panel { - background-color: white; - flex: 1; - padding: 40px 30px; - display: flex; - flex-direction: column; - gap: 20px; - color: #222; -} - -.apple-pay-button { - background-color: black; - color: white; - font-weight: 600; - font-size: 18px; - padding: 15px 0; - border: none; - border-radius: 6px; - cursor: pointer; - box-shadow: 0 4px 8px rgba(0,0,0,0.3); -} - -.separator { - display: flex; - align-items: center; - gap: 10px; - color: #999; - font-size: 14px; -} - -.separator .line { - flex: 1; - border: none; - border-top: 1px solid #ddd; -} - -.shipping-info h3, -.payment-methods h3 { - font-weight: 600; - margin-bottom: 10px; - font-size: 16px; -} - -.shipping-info input, -.shipping-info select { - width: 100%; - margin: 8px 0; - padding: 10px 12px; - border: 1px solid #ccc; - border-radius: 6px; - font-size: 14px; - color: #333; -} - -.manual-address { - font-size: 12px; - color: #666; - text-decoration: underline; - cursor: pointer; - margin-top: 4px; - display: inline-block; -} - -.payment-methods label { - display: flex; - align-items: center; - gap: 10px; - padding: 10px 12px; - border: 1px solid #ddd; - border-radius: 6px; - margin-bottom: 8px; - cursor: pointer; - font-size: 14px; - user-select: none; -} - -.payment-methods input[type="radio"] { - cursor: pointer; -} - -.payment-methods .icon { - display: inline-flex; - justify-content: center; - align-items: center; - width: 20px; - height: 20px; - font-weight: 700; - font-size: 14px; - border-radius: 4px; - background-color: #eee; - color: #555; -} - -.payment-methods .klarna { - background-color: #ff4f8b; - color: white; - font-weight: 700; - font-size: 14px; - padding: 0 4px; - border-radius: 4px; -} - -.payment-methods .ideal { - background-color: #f9a825; - color: white; - font-weight: 700; - font-size: 14px; - padding: 0 4px; - border-radius: 4px; -} - -.klarna-subtext { - font-size: 12px; - color: #999; - margin-left: 30px; - margin-top: -6px; -} - -.pay-button { - background-color: black; - color: white; - font-weight: 600; - font-size: 16px; - padding: 15px 0; - border: none; - border-radius: 6px; - cursor: pointer; - margin-top: 10px; -} - -.pay-button:hover { - background-color: #222; -} - -.footer { - font-size: 12px; - color: #999; - text-align: center; - margin-top: auto; - padding-top: 20px; - user-select: none; -} -/* Responsive styles */ -@media (max-width: 900px) { - .checkout-container { - flex-direction: column; - max-width: 100vw; - min-height: 100vh; - border-radius: 0; - box-shadow: none; - } - .left-panel, .right-panel { - padding: 32px 16px; - min-width: 0; - max-width: 100vw; - } - .left-panel { - border-radius: 0 0 12px 12px; - align-items: center; - text-align: center; - } - .right-panel { - border-radius: 12px 12px 0 0; - } - .product-image-container { - max-width: 220px; - max-height: 220px; - margin: 0 auto; - } -} - -@media (max-width: 600px) { - .checkout-container { - padding: 0; - } - .left-panel, .right-panel { - padding: 20px 6vw; - gap: 14px; - } - .product-name { - font-size: 18px; - } - .product-price { - font-size: 22px; - } - .apple-pay-button, .pay-button { - font-size: 15px; - padding: 12px 0; - } - .shipping-info input, - .shipping-info select { - font-size: 13px; - padding: 8px 10px; - } - .payment-methods label { - font-size: 13px; - padding: 8px 8px; - } - .footer { - font-size: 10px; - padding-top: 10px; - } -} -.checkmark-container { - display: flex; - flex-direction: column; - align-items: center; - animation: fadeIn 0.5s ease-in; -} - -.checkmark { - width: 100px; - height: 100px; - stroke-width: 2; - stroke: #4CAF50; - stroke-miterlimit: 10; - animation: scaleIn 0.3s ease-in-out; -} - -.checkmark-circle { - stroke-dasharray: 166; - stroke-dashoffset: 166; - stroke-width: 2; - stroke: #4CAF50; - fill: none; - animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards; -} - -.checkmark-check { - transform-origin: 50% 50%; - stroke-dasharray: 48; - stroke-dashoffset: 48; - stroke: #4CAF50; - stroke-linecap: round; - stroke-linejoin: round; - animation: stroke 0.3s 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards; -} - -@keyframes stroke { - to { - stroke-dashoffset: 0; - } -} - -@keyframes scaleIn { - 0% { - transform: scale(0); - } - 100% { - transform: scale(1); - } -} - -@keyframes fadeIn { - from { - opacity: 0; - transform: translateY(10px); - } - to { - opacity: 1; - transform: translateY(0); - } -} diff --git a/src/Checkout.js b/src/Checkout.js index 4a7fd22..e640288 100644 --- a/src/Checkout.js +++ b/src/Checkout.js @@ -1,252 +1,77 @@ -import React, { useState, useEffect } from 'react'; -import './Checkout.css'; -import { QRCodeCanvas } from 'qrcode.react'; +import React from 'react'; +import styles from './Checkout.module.css'; -const Checkout = ({ socketId, transactionSuccess }) => { - const [qrisData, setQrisData] = useState(null); // QRIS string - const [value, setValue] = useState(null); // QRIS value (optional) - const [products, setProducts] = useState([]); // Produk dari itemsId - const [loadingProducts, setLoadingProducts] = useState(false); - - // Helper get cookie value - const getCookie = (name) => { - const value = `; ${document.cookie}`; - const parts = value.split(`; ${name}=`); - if (parts.length === 2) return parts.pop().split(';').shift(); - return null; - }; - - useEffect(() => { - // document.cookie = "token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInVzZXJuYW1lIjoia2VkaXJpdGVjaG5vcGFyayIsImVtYWlsIjoiIiwicHJvZmlsZV9kYXRhIjp7fSwic3Vic2NyaXB0aW9ucyI6e30sImlhdCI6MTc1MzU4MDQ2N30.9TjxL5bV5i3zTAU_Rl7_p5cd76Fn6-O0elRtJw570jY; path=/; max-age=${7 * 24 * 60 * 60}"; - // document.cookie = "itemsId=" + JSON.stringify([1, 2]) + "; path=/; max-age=${7 * 24 * 60 * 60}"; - - - const fetchUserData = async () => { - const token = getCookie('token'); - - if (token) { - try { - const userDataResponse = await fetch('https://bot.kediritechnopark.com/webhook/user-dev/data', { - headers: { - 'Authorization': `Bearer ${token}`, - }, - }); - if (userDataResponse.ok) { - const userData = await userDataResponse.json(); - document.cookie = `token=${userData[0]?.token}; path=/; max-age=${7 * 24 * 60 * 60}`; - console.log('User data:', userData); - // Store user data in state or context if needed - } else { - console.error('Failed to fetch user data:', userDataResponse.status); - // Handle error fetching user data, e.g., logout - document.cookie = 'token=; path=/; max-age=0'; - } - } catch (error) { - console.error('Error fetching user data:', error); - // Handle network or other errors, e.g., logout - document.cookie = 'token=; path=/; max-age=0'; - } - } - }; - - - const fetchProducts = async () => { - const itemsIdRaw = getCookie('itemsId'); - if (!itemsIdRaw) return; - - let itemsId = []; - try { - itemsId = JSON.parse(itemsIdRaw); - } catch (e) { - console.error('Gagal parse itemsId dari cookie:', e); - return; - } - - if (itemsId.length === 0) return; - - setLoadingProducts(true); - - try { - const token = getCookie('token'); - if (!token) { - console.warn('Token tidak ditemukan'); - return; - } - - const params = new URLSearchParams(); - itemsId.forEach(id => params.append('itemsId', id)); - - const res = await fetch(`https://bot.kediritechnopark.com/webhook/store-dev/products`, { - method: 'POST', - headers: { - 'Authorization': `Bearer ${token}`, - 'Content-Type': 'application/x-www-form-urlencoded', - }, - body: params.toString(), - }); - - if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`); - - const data = await res.json(); - setProducts(data); - } catch (error) { - console.error('Error fetching products:', error); - } finally { - setLoadingProducts(false); - } - }; - - fetchProducts(); - fetchUserData(); - - }, []); - - - const handlePay = async (e) => { - e.preventDefault(); - - let itemsIdRaw = getCookie('itemsId'); - let token = getCookie('token'); - - if (!itemsIdRaw || !token) { - alert("Token atau itemsId tidak ditemukan di cookies."); - return; - } - - let itemsId = []; - try { - itemsId = JSON.parse(itemsIdRaw); - } catch (e) { - alert("Gagal parsing itemsId."); - return; - } - - try { - const params = new URLSearchParams(); - itemsId.forEach(id => params.append('itemsId', id)); - params.append('socketId', socketId); - - - const response = await fetch('https://bot.kediritechnopark.com/webhook/store-dev/pay', { - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Authorization': `Bearer ${token}` - }, - body: params.toString() - }); - - - const result = await response.json(); - - if (response.ok && result.qris_dynamic) { - setQrisData(result.qris_dynamic); - setValue(result.total_price); - } else { - alert(`Gagal mendapatkan QRIS: ${result?.error || 'Unknown error'}`); - } - - } catch (error) { - console.error('Network error:', error); - alert("Terjadi kesalahan jaringan."); - } - }; - - return ( -
+const Checkout = () => {
+ return (
+ Pure Kit
+$65.00
Loading products...
- ) : products.length === 0 ? ( -No products found
- ) : ( -{qrisData}
-Energy Drink
+$25.00