PageSourceSearch

https://vatdi.com/build/assets/AffiliateDetail-DGPmYBgl.js

js vatdi.com collected 2026-10-02 06:28:27 UTC 12,807 bytes, 1 lines download raw bytes

1import{f as ne,u as de,r as l,j as e}from"./react-CgBY0Ze-.js";import{P as oe}from"./PageHeader-B2uLUomX.js";import{S as y}from"./StatCard-C17Z0tP5.js";import{S as h}from"./StatusBadge-BLFaUmng.js";import{b as xe,d as me,O as n,L as ye,o as g,f as w,C as f}from"./main-Cyy5nyiT.js";import{T as pe}from"./Tabs-CPvoRfOZ.js";import{P as S}from"./Pagination-DV0ATNcS.js";import{u as ge}from"./useImpersonation-DOM4oDbi.js";import{u as fe}from"./useTabState-MSn4TtuU.js";import{W as ue,bo as he}from"./vendor-NlgW4Nml.js";import"./renderIcon-CWUPWWi0.js";import"./http-BCn5QfZZ.js";const Re=()=>{var F,L,$,I,M,B,O,H,U;const{id:c}=ne(),q=de(),i=xe(t=>t.showToast),u=me(),[a,C]=l.useState(null),[x,z]=l.useState(null),[j,_]=l.useState([]),[v,P]=l.useState([]),[N,T]=l.useState([]),[R,b]=l.useState({referrals:1,commissions:1,payouts:1}),[d,G]=l.useState({}),[J,D]=l.useState(!0),[K,k]=l.useState(!1),[E,A]=l.useState(""),[o,Q]=fe("overview"),V=ge();l.useEffect(()=>{m()},[c]),l.useEffect(()=>{if(!["referrals","commissions","payouts"].includes(o))return;const t={referrals:[n.getAffiliateReferrals,_],commissions:[n.getAffiliateCommissions,P],payouts:[n.getAffiliatePayouts,T]},[s,r]=t[o];s(c,{page:R[o],per_page:20}).then(W=>{var Y;const p=((Y=W.data)==null?void 0:Y.data)||W.data||{};r(Array.isArray(p.data)?p.data:[]),G(ce=>({...ce,[o]:{current_page:p.current_page||1,last_page:p.last_page||1,total:p.total??null}}))}).catch(()=>{})},[o,R,c]);const m=async()=>{var t;try{D(!0);const s=await n.affiliates.get(c),r=((t=s.data)==null?void 0:t.data)||s.data;r.affiliate?(C(r.affiliate),z(r.stats||null),_(Array.isArray(r.referrals)?r.referrals:[]),P(Array.isArray(r.commissions)?r.commissions:[]),T(Array.isArray(r.payouts)?r.payouts:[]),A(r.affiliate.commission_rate||"")):(C(r),A(r.commission_rate||""))}catch(s){i("Failed to load affiliate details","error"),console.error(s)}finally{D(!1)}},X=async()=>{if(await u({title:"Approve Affiliate",message:"Are you sure you want to approve this affiliate?",confirmText:"Approve",variant:"primary"}))try{await n.affiliates.approve(c),i("Affiliate approved successfully","success"),m()}catch{i("Failed to approve affiliate","error")}},Z=async()=>{if(await u({title:"Reject Affiliate",message:"Are you sure you want to reject this affiliate?",confirmText:"Reject",variant:"danger"}))try{await n.affiliates.reject(c),i("Affiliate rejected","success"),m()}catch{i("Failed to reject affiliate","error")}},ee=async()=>{if(await u({title:"Suspend Affiliate",message:"Are you sure you want to suspend this affiliate?",confirmText:"Suspend",variant:"danger"}))try{await n.affiliates.suspend(c),i("Affiliate suspended","success"),m()}catch{i("Failed to suspend affiliate","error")}},te=async()=>{try{await n.affiliates.activate(c),i("Affiliate activated","success"),m()}catch{i("Failed to activate affiliate","error")}},ae=async()=>{if(await u({title:"Delete Affiliate",message:"This will permanently delete the affiliate and all associated referrals, commissions, and payouts. This action cannot be undone.",confirmText:"Delete",variant:"danger"}))try{await n.affiliates.delete(c),i("Affiliate deleted successfully","success"),q("/admin/affiliates")}catch{i("Failed to delete affiliate","error")}},se=async()=>{try{await n.affiliates.updateRate(c,parseFloat(E)),i("Commission rate updated","success"),k(!1),m()}catch{i("Failed to update commission rate","error")}},re=async()=>{await V("affiliate",c,{name:a==null?void 0:a.name,email:a==null?void 0:a.email})};if(J)return e.jsx(ye,{});if(!a)return e.jsx("div",{className:"text-center py-12",children:e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:"Affiliate not found"})});const ie=[{key:"overview",label:"Overview"},{key:"referrals",label:`Referrals (${((F=d.referrals)==null?void 0:F.total)??j.length})`},{key:"commissions",label:`Commissions (${((L=d.commissions)==null?void 0:L.total)??v.length})`},{key:"payouts",label:`Payouts (${(($=d.payouts)==null?void 0:$.total)??N.length})`}],le=[...a.status==="pending"?[{label:"Approve",onClick:X,variant:"primary"},{label:"Reject",onClick:Z,variant:"danger"}]:[],...a.status==="active"?[{label:"Suspend",onClick:ee,variant:"danger"}]:[],...a.status==="suspended"?[{label:"Activate",onClick:te,variant:"primary"}]:[],{label:"Login as Affiliate",onClick:re,variant:"secondary"},{label:"Delete",onClick:ae,variant:"danger"}];return e.jsxs("div",{className:"space-y-6",children:[e.jsx(oe,{title:a.name,description:`Affiliate ID: ${a.id}`,icon:e.jsx(ue,{className:"w-5 h-5"}),iconAccent:"emerald",backLink:"/admin/affiliates",actions:le}),e.jsx("div",{className:"card p-6",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:"Email"}),e.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-gray-100",children:a.email})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:"Phone"}),e.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-gray-100",children:a.phone||"-"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:"Referral Code"}),e.jsx("p",{className:"mt-1 text-sm font-mono text-gray-900 bg-gray-50 px-2 py-1 rounded inline-block dark:text-gray-100 dark:bg-gray-800/50",children:a.referral_code})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:"Status"}),e.jsx("div",{className:"mt-1",children:e.jsx(h,{status:a.status})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:"Commission Rate"}),K?e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsx("input",{type:"number",step:"0.01",value:E,onChange:t=>A(t.target.value),className:"input w-24"}),e.jsx("button",{onClick:()=>k(!1),className:"btn-ghost btn-sm",children:"Cancel"}),e.jsx("button",{onClick:se,className:"btn-primary-sm",children:"Save"})]}):e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsxs("p",{className:"text-sm text-gray-900 dark:text-gray-100",children:[a.commission_rate,"%"]}),e.jsx("button",{onClick:()=>k(!0),className:"btn-icon-primary",title:"Edit commission rate",children:e.jsx(he,{className:"w-3.5 h-3.5"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:"Approved At"}),e.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-gray-100",children:a.approved_at?g(a.approved_at):"-"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-gray-500 dark:text-gray-400",children:"Created"}),e.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-gray-100",children:g(a.created_at)})]})]})}),x&&e.jsxs("div",{className:"grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-6",children:[e.jsx(y,{title:"Total Referrals",value:w(x.total_referrals||0),icon:"users",color:"blue"}),e.jsx(y,{title:"Converted",value:w(x.converted_referrals||0),icon:"check-circle",color:"green"}),e.jsx(y,{title:"Total Earnings",value:f(x.total_earnings||0),icon:"currency-dollar",color:"purple"}),e.jsx(y,{title:"Total Paid",value:f(x.total_paid||0),icon:"cash",color:"green"}),e.jsx(y,{title:"Pending Balance",value:f(x.pending_balance||0),icon:"clock",color:"yellow"}
1),e.jsx(y,{title:"Pending Commissions",value:w(x.pending_commissions||0),icon:"document-text",color:"amber"})]}),e.jsx(pe,{tabs:ie,active:o,onChange:Q}),o==="referrals"&&e.jsxs("div",{className:"card overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-800/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Email"}),e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Status"}),e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Converted"}),e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Date"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200 dark:divide-gray-700 dark:bg-gray-800",children:j.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-6 py-8 text-center text-sm text-gray-500 dark:text-gray-400",children:"No referrals yet"})}):j.map(t=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-4 py-2 text-sm text-gray-900 dark:text-gray-100",children:t.email}),e.jsx("td",{className:"px-4 py-2",children:e.jsx(h,{status:t.status})}),e.jsx("td",{className:"px-4 py-2 text-sm",children:t.converted_at?"Yes":"No"}),e.jsx("td",{className:"px-4 py-2 text-sm text-gray-500 dark:text-gray-400",children:g(t.created_at)})]},t.id))})]})}),e.jsx("div",{className:"pb-4",children:e.jsx(S,{currentPage:((I=d.referrals)==null?void 0:I.current_page)||1,lastPage:((M=d.referrals)==null?void 0:M.last_page)||1,onPageChange:t=>b(s=>({...s,referrals:t}))})})]}),o==="commissions"&&e.jsxs("div",{className:"card overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-800/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Store"}),e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Amount"}),e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Status"}),e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Date"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200 dark:divide-gray-700 dark:bg-gray-800",children:v.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-6 py-8 text-center text-sm text-gray-500 dark:text-gray-400",children:"No commissions yet"})}):v.map(t=>{var s;return e.jsxs("tr",{children:[e.jsx("td",{className:"px-4 py-2 text-sm text-gray-900 dark:text-gray-100",children:((s=t.store)==null?void 0:s.name)||"-"}),e.jsx("td",{className:"px-4 py-2 text-sm text-gray-900 dark:text-gray-100",children:f(t.amount)}),e.jsx("td",{className:"px-4 py-2",children:e.jsx(h,{status:t.status})}),e.jsx("td",{className:"px-4 py-2 text-sm text-gray-500 dark:text-gray-400",children:g(t.created_at)})]},t.id)})})]})}),e.jsx("div",{className:"pb-4",children:e.jsx(S,{currentPage:((B=d.commissions)==null?void 0:B.current_page)||1,lastPage:((O=d.commissions)==null?void 0:O.last_page)||1,onPageChange:t=>b(s=>({...s,commissions:t}))})})]}),o==="payouts"&&e.jsxs("div",{className:"card overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-800/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Amount"}),e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Method"}),e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Status"}),e.jsx("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase dark:text-gray-400",children:"Date"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200 dark:divide-gray-700 dark:bg-gray-800",children:N.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-6 py-8 text-center text-sm text-gray-500 dark:text-gray-400",children:"No payouts yet"})}):N.map(t=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-4 py-2 text-sm text-gray-900 dark:text-gray-100",children:f(t.amount)}),e.jsx("td",{className:"px-4 py-2 text-sm text-gray-900 dark:text-gray-100",children:t.payment_method}),e.jsx("td",{className:"px-4 py-2",children:e.jsx(h,{status:t.status})}),e.jsx("td",{className:"px-4 py-2 text-sm text-gray-500 dark:text-gray-400",children:g(t.created_at)})]},t.id))})]})}),e.jsx("div",{className:"pb-4",children:e.jsx(S,{currentPage:((H=d.payouts)==null?void 0:H.current_page)||1,lastPage:((U=d.payouts)==null?void 0:U.last_page)||1,onPageChange:t=>b(s=>({...s,payouts:t}))})})]})]})};export{Re as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.