%PDF- %PDF-
| Direktori : /home2/rezakur1/ai.rezakurnia.com/assets/ |
| Current File : //home2/rezakur1/ai.rezakurnia.com/assets/AdminTopupPage-l-w2QR4y.js |
import{f as B,r as a,c as h,j as e}from"./index-DUZ8nGC1.js";import{B as c}from"./Button-DiZn_29O.js";import{C as _,d as I,e as O,b as $}from"./format-GCYE-pqZ.js";import{B as i}from"./Badge-BUuDueTl.js";import{M as A}from"./Modal-C6fq5ZqD.js";import"./index-U8INd_G2.js";function N(n){return n.toLocaleString("id-ID",{style:"currency",currency:"IDR",maximumFractionDigits:0})}function H(n){return n.status==="pending"&&new Date(n.expires_at)<new Date}const K=[{value:"pending",label:"Menunggu"},{value:"paid",label:"Terbayar"},{value:"expired",label:"Kedaluwarsa"},{value:"",label:"Semua"}];function z(){const{count:n,requestNotify:v}=B(),[f,w]=a.useState([]),[u,k]=a.useState("pending"),[S,g]=a.useState(!0),[D,b]=a.useState(null),[j,x]=a.useState(null),[r,d]=a.useState(null),[m,y]=a.useState(!1),[p,l]=a.useState("prompt"),o=a.useCallback(async(t=!1)=>{t||g(!0);try{const s=await h(`/admin/topup${u?`?status=${u}`:""}`);w(s.orders),x(null)}catch(s){x(s instanceof Error?s.message:"Gagal memuat order")}finally{t||g(!1)}},[u]);a.useEffect(()=>{o();const t=setInterval(()=>o(!0),5e3);return()=>clearInterval(t)},[o]),a.useEffect(()=>{typeof Notification>"u"?l("unsupported"):Notification.permission==="granted"?l("granted"):Notification.permission==="denied"?l("denied"):l("prompt")},[]);const E=async()=>{const t=await v();l(t==="granted"?"granted":t==="denied"?"denied":"prompt")},C=async t=>{b(t);try{await h(`/admin/topup/${t}/verify`,{method:"POST",body:{note:"Verifikasi manual oleh admin"}}),await o()}catch(s){x(s instanceof Error?s.message:"Gagal verifikasi")}finally{b(null)}},T=async()=>{if(r){y(!0);try{await h(`/admin/topup/${r.id}`,{method:"DELETE"}),d(null),await o()}catch(t){x(t instanceof Error?t.message:"Gagal menghapus order"),d(null)}finally{y(!1)}}};return e.jsxs("div",{className:"space-y-4",children:[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}),e.jsxs(_,{children:[e.jsx(I,{title:"Daftar Order",subtitle:"Klik verifikasi setelah pembayaran masuk",action:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[n>0&&e.jsxs(i,{tone:"warning",children:[e.jsx("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-amber-400"}),n," menunggu"]}),p==="granted"?e.jsxs(i,{tone:"success",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-emerald-400"}),"Notifikasi aktif"]}):p==="prompt"?e.jsx(c,{variant:"ghost",size:"sm",onClick:E,children:"🔔 Aktifkan notifikasi"}):p==="denied"?e.jsx(i,{tone:"default",children:"Notifikasi diblokir browser"}):null,e.jsx("div",{className:"flex items-center gap-1 rounded-xl border border-white/[0.06] bg-white/[0.03] p-1",children:K.map(t=>e.jsx("button",{onClick:()=>k(t.value),className:`rounded-lg px-3.5 py-1.5 text-xs font-medium transition-colors ${u===t.value?"bg-white/[0.08] text-white":"text-slate-500 hover:text-slate-300"}`,children:t.label},t.value||"all"))})]})}),e.jsx(O,{className:"p-0",children:S?e.jsx("div",{className:"space-y-3 p-5",children:[...Array(3)].map((t,s)=>e.jsx("div",{className:"h-14 animate-pulse rounded-xl bg-white/[0.02]"},s))}):f.length===0?e.jsx("div",{className:"px-5 py-10 text-center text-sm text-slate-500",children:"Tidak ada order dengan filter ini."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[820px] 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 font-semibold",children:"User"}),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-4 py-3 text-right font-semibold",children:"Dibuat"}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:"Aksi"})]})}),e.jsx("tbody",{children:f.map(t=>{const s=H(t);return e.jsxs("tr",{className:`border-b border-white/[0.04] transition-colors last:border-0 ${s?"opacity-45 hover:bg-transparent":"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.jsxs("td",{className:"px-4 py-3.5",children:[e.jsx("p",{className:"text-sm font-medium text-slate-200",children:t.user_name||`User #${t.user_id}`}),t.user_email&&e.jsx("p",{className:"mt-0.5 truncate text-[11px] text-slate-600",children:t.user_email})]}),e.jsx("td",{className:"px-4 py-3.5 text-right font-semibold tabular-nums text-white",children:N(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:s?e.jsx(i,{tone:"default",children:"Kadaluarsa"}):t.status==="paid"?e.jsx(i,{tone:"success",children:"Terbayar"}):t.status==="pending"?e.jsx(i,{tone:"warning",children:"Menunggu"}):t.status==="expired"?e.jsx(i,{tone:"default",children:"Kedaluwarsa"}):e.jsx(i,{tone:"danger",children:"Gagal"})}),e.jsx("td",{className:"px-4 py-3.5 text-right text-xs tabular-nums text-slate-500",children:$(t.created_at)}),e.jsx("td",{className:"px-5 py-3.5 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.status==="pending"&&!s&&e.jsx(c,{size:"sm",isLoading:D===t.id,onClick:()=>C(t.id),children:"Tandai Terbayar"}),t.status!=="paid"&&e.jsx(c,{variant:"subtle",size:"sm",title:"Hapus order (belum terbayar)",className:"text-red-400 hover:bg-red-500/10 hover:text-red-300",onClick:()=>d(t),children:"Hapus"}),t.status==="paid"&&e.jsx("span",{className:"text-xs text-slate-600",children:"—"})]})})]},t.id)})})]})})})]}),e.jsx(A,{open:!!r,onClose:()=>{m||d(null)},title:"Hapus Order Top Up?",subtitle:"Order yang belum terbayar akan dihapus permanen.",width:"max-w-sm",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3 text-xs leading-relaxed text-red-300",children:["Anda akan menghapus order"," ",e.jsxs("strong",{children:["#",String((r==null?void 0:r.id)??"").padStart(6,"0")]})," ","senilai ",e.jsx("strong",{children:N(Number((r==null?void 0:r.amount)??0))}),". Order belum terbayar, jadi saldo user tidak terpengaruh. User akan bisa membuat kode QRIS baru untuk order ini."]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c,{variant:"ghost",onClick:()=>d(null),disabled:m,children:"Batal"}),e.jsx(c,{variant:"danger",isLoading:m,onClick:T,children:"Ya, Hapus"})]})]})})]})}export{z as default};