%PDF- %PDF-
| Direktori : /home2/rezakur1/ai.rezakurnia.com/assets/ |
| Current File : /home2/rezakur1/ai.rezakurnia.com/assets/TopupPage-BQp96A_2.js |
import{r as a,c as B,j as e}from"./index-CnB9nKbp.js";import{B as N}from"./Button-RaC0qoA7.js";import{c as F,C as I,d as R,e as _,b as G}from"./format-B8Won_Te.js";import{B as b}from"./Badge-CXRzVGa3.js";import{u as H}from"./useWallet-CPn0Ib7E.js";function J(){const[r,u]=a.useState([]),[o,c]=a.useState(!0),i=a.useCallback(async()=>{try{const n=await B("/me/topup");u(n.orders)}catch{}finally{c(!1)}},[]);a.useEffect(()=>{i()},[i]);const f=a.useCallback(async n=>{const l=await B("/me/topup",{method:"POST",body:{amount:String(n)}});return await i(),l},[i]),x=r.some(n=>n.status!=="pending"?!1:new Date(n.expires_at).getTime()>Date.now());return{orders:r,loading:o,create:f,hasPending:x,refresh:i}}function V(r,u){const[o,c]=a.useState(null),[i,f]=a.useState(null),[x,n]=a.useState(!1),l=a.useRef(u);l.current=u,a.useEffect(()=>{if(!r){n(!1);return}let y=!1,m;const j=async()=>{var h;try{const s=await B(`/me/topup/${r}`);if(y)return;if(c(s.order.status),f(s.order.expires_at),["paid","expired","failed"].includes(s.order.status)){n(!0),(h=l.current)==null||h.call(l);return}}catch{}m=setTimeout(j,5e3)};return j(),()=>{y=!0,m&&clearTimeout(m)}},[r]);const w=o!==null&&["paid","expired","failed"].includes(o);return{status:o,expiresAt:i,final:w,stopped:x}}const $=[1e4,25e3,5e4,1e5],D=1e4;function d(r){return r.toLocaleString("id-ID",{style:"currency",currency:"IDR",maximumFractionDigits:0})}function se(){const{orders:r,loading:u,create:o,hasPending:c}=J(),{data:i,refresh:f}=H(),[x,n]=a.useState($[0]),[l,w]=a.useState(""),[y,m]=a.useState(!1),[j,h]=a.useState(null),[s,T]=a.useState(null),[g,v]=a.useState(!1),[A,E]=a.useState(!1),[z,Q]=a.useState(()=>Date.now()),k=l.trim()?Number(l):x,O=async()=>{if(!Number.isFinite(k)||k<D){h(`Nominal minimal ${d(D)}.`);return}h(null),m(!0);try{const t=await o(k);if(t.qr.url)try{sessionStorage.setItem("topup_qr_url",t.qr.url)}catch{}T({id:t.order.id,amount:Number(t.order.amount),uniqueCode:t.order.unique_code,qrUrl:t.qr.url,expiresAt:t.order.expires_at}),v(!1)}catch(t){h(t instanceof Error?t.message:"Gagal membuat order")}finally{m(!1)}},{status:S,final:P}=V((s==null?void 0:s.id)??null,()=>f());a.useEffect(()=>{P&&S==="paid"&&v(!0)},[P,S]),a.useEffect(()=>{if(s||!c)return;const t=r.find(C=>C.status==="pending"&&new Date(C.expires_at).getTime()>Date.now());if(!t)return;let p=null;try{p=sessionStorage.getItem("topup_qr_url")}catch{}T({id:t.id,amount:Number(t.amount),uniqueCode:t.unique_code,qrUrl:p,expiresAt:t.expires_at}),v(!1)},[c,r,s]);const q=()=>{T(null),v(!1)},U=async()=>{if(!s)return;const t=Number(s.amount)+(s.uniqueCode??0);try{await navigator.clipboard.writeText(String(t)),E(!0),setTimeout(()=>E(!1),2e3)}catch{}};a.useEffect(()=>{if(!s)return;const t=setInterval(()=>Q(Date.now()),1e3);return()=>clearInterval(t)},[s]);const M=s?new Date(s.expiresAt).getTime()-z:0,L=!!s&&M<=0,K=(()=>{if(!s)return null;const t=Math.max(0,M),p=Math.floor(t/1e3%60),C=Math.floor(t/6e4%60),W=Math.floor(t/36e5);return`${String(W).padStart(2,"0")}:${String(C).padStart(2,"0")}:${String(p).padStart(2,"0")}`})();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold tracking-tight text-white sm:text-2xl",children:"Top Up"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Isi saldo wallet dengan pembayaran QRIS."})]}),e.jsxs("div",{className:"panel flex items-center gap-3 px-4 py-2.5",children:[e.jsx("span",{className:"text-xs text-slate-500",children:"Saldo wallet"}),e.jsx("span",{className:"text-base font-bold tabular-nums text-white",children:i?F(i.wallet.balance):"…"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-5",children:[e.jsxs(I,{className:"lg:col-span-2",children:[e.jsx(R,{title:"Pilih nominal",subtitle:"Minimal 10.000 IDR"}),e.jsx(_,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-2 gap-2",children:$.map(t=>e.jsx("button",{onClick:()=>{n(t),w("")},className:`rounded-xl border px-4 py-3 text-sm font-semibold tabular-nums transition-colors ${!l.trim()&&x===t?"border-brand-400/40 bg-brand-500/10 text-brand-200":"border-white/[0.06] bg-white/[0.02] text-slate-300 hover:bg-white/[0.04]"}`,children:d(t)},t))}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Nominal custom (IDR)"}),e.jsx("input",{type:"number",min:D,step:1e3,placeholder:"cth: 150000",value:l,onChange:t=>w(t.target.value),className:"input-solid"})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-white/[0.06] bg-white/[0.02] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-slate-400",children:"Total bayar"}),e.jsx("span",{className:"text-lg font-bold tabular-nums text-white",children:d(k)})]}),j&&e.jsx("div",{className:"rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3 text-sm text-red-300",children:j}),c&&!s&&e.jsx("div",{className:"rounded-xl border border-amber-400/25 bg-amber-500/10 px-4 py-3 text-xs leading-relaxed text-amber-200",children:"⏳ Kamu masih memiliki pembayaran yang menunggu. Selesaikan atau tunggu kedaluwarsa sebelum membuat kode QRIS baru."}),e.jsx(N,{className:"w-full",size:"lg",isLoading:y,disabled:c,onClick:O,children:c?"Menunggu pembayaran…":"Buat Kode QRIS"})]})})]}),e.jsxs(I,{className:"lg:col-span-3",children:[e.jsx(R,{title:"Pembayaran",subtitle:s?`Order #${s.id} — ${d(s.amount)}`:"Buat order untuk melihat kode QR",action:s&&!g?e.jsx(b,{tone:"warning",children:"Menunggu pembayaran"}):g?e.jsx(b,{tone:"success",children:"Pembayaran berhasil"}):void 0}),e.jsxs(_,{children:[!s&&e.jsxs("div",{className:"flex h-72 flex-col items-center justify-center gap-3 text-center",children:[e.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-2xl border border-white/[0.06] bg-white/[0.02] text-slate-500",children:e.jsx("svg",{className:"h-7 w-7",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.5,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 4.875c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5A1.125 1.125 0 013.75 9.375v-4.5zM3.75 14.625c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5a1.125 1.125 0 01-1.125-1.125v-4.5zM13.5 4.875c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5A1.125 1.125 0 0113.5 9.375v-4.5zM13.5 14.625c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5a1.125 1.125 0 01-1.125-1.125v-4.5z"})})}),e.jsxs("p",{className:"max-w-xs text-sm text-slate-500",children:["Pilih nominal di samping, lalu tekan"," ",e.jsx("span",{className:"text-slate-300",children:'"Buat Kode QRIS"'}),"."]})]}),s&&!g&&!L&&e.jsxs("div",{className:"flex flex-col items-center gap-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500",children:[e.jsx("span",{className:"h-2 w-2 animate-pulse rounded-full bg-amber-400"}),"Deteksi pembayaran otomatis — status akan ter-update sendiri."]}),e.jsx("div",{className:"rounded-2xl border border-white/[0.08] bg-white p-3 shadow-soft",children:s.qrUrl?e.jsx("img",{src:s.qrUrl,alt:"QRIS",className:"h-52 w-52 object-contain"}):e.jsx("div",{className:"flex h-52 w-52 items-center justify-center rounded-xl bg-ink-800",children:e.jsx("span",{className:"px-6 text-center text-xs text-slate-500",children:"QRIS belum dikonfigurasi (atur QRIS_IMAGE_URL di backend)"})})}),e.jsx("div",{className:"w-full rounded-2xl border border-brand-400/20 bg-brand-500/[0.06] p-4",children:s.uniqueCode!=null?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-xs font-medium text-slate-400",children:"Cara bayar"}),e.jsxs("p",{className:"mt-1.5 text-sm text-slate-300",children:["Transfer tepat"," ",e.jsx("span",{className:"font-bold tabular-nums text-white",children:d(Number(s.amount)+s.uniqueCode)})]}),e.jsxs("p",{className:"mt-1 text-xs text-slate-500",children:["(nominal ",d(s.amount)," + kode unik"," ",e.jsx("span",{className:"rounded-md border border-brand-400/25 bg-brand-500/15 px-1.5 py-0.5 font-mono font-bold tabular-nums text-brand-200",children:s.uniqueCode}),")"]}),e.jsx(N,{variant:"ghost",size:"sm",className:"mt-3",onClick:U,disabled:A,children:A?"Tersalin ✓":"Salin nominal total"})]}):e.jsxs("p",{className:"text-sm text-slate-400",children:["Transfer tepat"," ",e.jsx("span",{className:"font-bold tabular-nums text-white",children:d(Number(s.amount))})]})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-4 text-xs text-slate-500",children:[e.jsxs("span",{className:"chip",children:["Order #",e.jsx("span",{className:"tabular-nums",children:s.id})]}),e.jsxs("span",{className:"chip",children:["Kadaluwarsa:"," ",e.jsx("span",{className:`tabular-nums ${M<300*1e3?"font-semibold text-red-300":""}`,children:K})]}),S&&e.jsxs("span",{className:"chip",children:["Status: ",S]})]}),e.jsx(N,{variant:"ghost",size:"sm",onClick:q,children:"Batalkan & tutup"})]}),s&&L&&!g&&e.jsxs("div",{className:"flex h-72 flex-col items-center justify-center gap-4 text-center",children:[e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-red-500/15 text-red-300",children:e.jsx("svg",{className:"h-8 w-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:1.8,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-semibold text-white",children:"Order kedaluwarsa"}),e.jsxs("p",{className:"mx-auto mt-1 max-w-xs text-sm text-slate-500",children:["Masa pembayaran order #",e.jsx("span",{className:"tabular-nums",children:s.id})," telah berakhir. Buat order baru untuk melanjutkan top up."]})]}),e.jsx(N,{onClick:q,children:"Tutup"})]}),s&&g&&e.jsxs("div",{className:"flex h-72 flex-col items-center justify-center gap-4 text-center",children:[e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-emerald-500/15 text-emerald-300",children:e.jsx("svg",{className:"h-8 w-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.5 12.75l6 6 9-13.5"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-semibold text-white",children:"Pembayaran diterima 🎉"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-500",children:[d(s.amount)," telah masuk ke wallet Anda."]})]}),e.jsx(N,{onClick:q,children:"Selesai"})]})]})]})]}),e.jsxs(I,{children:[e.jsx(R,{title:"Riwayat Top Up",subtitle:"Order pembayaran Anda"}),e.jsx(_,{className:"p-0",children:u?e.jsx("div",{className:"space-y-3 p-5",children:[...Array(3)].map((t,p)=>e.jsx("div",{className:"h-14 animate-pulse rounded-xl bg-white/[0.02]"},p))}):r.length===0?e.jsx("div",{className:"px-5 py-10 text-center text-sm text-slate-500",children:"Belum ada riwayat top up."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[560px] text-left text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/[0.06] bg-white/[0.02] text-[11px] uppercase tracking-wider text-slate-500",children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:"Order"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Nominal"}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold",children:"Kode"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Status"}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:"Dibuat"})]})}),e.jsx("tbody",{children:r.map(t=>e.jsxs("tr",{className:"border-b border-white/[0.04] transition-colors last:border-0 hover:bg-white/[0.02]",children:[e.jsxs("td",{className:"px-5 py-3.5 font-mono text-xs text-slate-400",children:["#",String(t.id).padStart(6,"0")]}),e.jsx("td",{className:"px-4 py-3.5 text-right font-semibold tabular-nums text-white",children:d(Number(t.amount))}),e.jsx("td",{className:"px-4 py-3.5 text-right",children:t.unique_code!=null?e.jsx("span",{className:"rounded-md border border-white/[0.06] bg-white/[0.03] px-1.5 py-0.5 font-mono text-xs font-bold tabular-nums text-brand-200",children:t.unique_code}):e.jsx("span",{className:"text-xs text-slate-600",children:"—"})}),e.jsx("td",{className:"px-4 py-3.5",children:t.status==="paid"?e.jsx(b,{tone:"success",children:"Terbayar"}):t.status==="pending"?e.jsx(b,{tone:"warning",children:"Menunggu"}):t.status==="expired"?e.jsx(b,{tone:"default",children:"Kedaluwarsa"}):e.jsx(b,{tone:"danger",children:"Gagal"})}),e.jsx("td",{className:"px-5 py-3.5 text-right text-xs tabular-nums text-slate-500",children:G(t.created_at)})]},t.id))})]})})})]})]})}export{se as default};