PageSourceSearch

https://tastescore.ai/assets/AdminFinance-BvY7r8-N.js

js tastescore.ai collected 2026-10-05 14:45:30 UTC 14,612 bytes, 6 lines download raw bytes

1import{M as R,a as D,r as C,N as p,c as g,ai as _,aj as U,O as z,j as e,C as m,d as x,g as u,e as y,B as N,W as h,k as v,q as r}from"./index-CbnhyKOh.js";import{a as w,b as S}from"./index-DoA8qsSD.js";import{W as O,A as W}from"./AdminLayout-CY5bmHbu.js";import{T as V}from"./trending-up-CXdPq8n0.js";import{L as M}from"./loader-circle-DmhNe36P.js";import{T as H}from"./trash-2-C6gO8tOr.js";import{f as b}from"./format-cwXK75ha.js";import"./award-CsUCfvGm.js";/**
2 * @license lucide-react v0.453.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const G=R("PiggyBank",[["path",{d:"M19 5c-1.5 0-2.8 1.4-3 2-3.5-1.5-11-.3-11 5 0 1.8 0 3 2 4.5V20h4v-2h3v2h4v-4c1-.5 1.7-1 2-2h2v-4h-2c0-1-.5-1.5-1-2V5z",key:"1ivx2i"}],["path",{d:"M2 9v1c0 1.1.9 2 2 2h1",key:"nm575m"}],["path",{d:"M16 11h.01",key:"xkw8gn"}]]);function de(){const{toast:d}=D(),[P,f]=C.useState(null),[$,j]=C.useState(null),{data:s,isLoading:I}=p({queryKey:["/api/admin/finance/metrics"]}),{data:l,isLoading:F}=p({queryKey:["/api/admin/finance/transactions"]}),{data:o,isLoading:q}=p({queryKey:["/api/admin/finance/payouts"]}),{data:c,isLoading:L}=p({queryKey:["/api/admin/finance/artists-ready-for-payout"]}),T=g({mutationFn:async({artistId:t,amount:a,payoutMethod:n})=>(await v("/api/admin/finance/process-payout","POST",{artistId:t,amount:a,payoutMethod:n})).json(),onSuccess:(t,a)=>{t.payoutMethod==="paypal"?d({title:"PayPal Payout Ready",description:`Please send $${a.amount.toFixed(2)} to ${t.paypalEmail} via PayPal, then click "Confirm Paid" in the Recent Payouts table.`}):d({title:"Stripe Payout Successful",description:`$${a.amount.toFixed(2)} has been sent to the artist via Stripe.`}),r.invalidateQueries({queryKey:["/api/admin/finance/metrics"]}),r.invalidateQueries({queryKey:["/api/admin/finance/payouts"]}),r.invalidateQueries({queryKey:["/api/admin/finance/artists-ready-for-payout"]}),f(null)},onError:t=>{d({title:"Payout Failed",description:t.message||"Failed to process payout",variant:"destructive"}),f(null)}}),E=g({mutationFn:async({payoutId:t})=>(await v("/api/admin/finance/confirm-paypal-payout","POST",{payoutId:t})).json(),onSuccess:()=>{d({title:"Payout Confirmed",description:"PayPal payout has been marked as completed."}),r.invalidateQueries({queryKey:["/api/admin/finance/metrics"]}),r.invalidateQueries({queryKey:["/api/admin/finance/payouts"]}),r.invalidateQueries({queryKey:["/api/admin/finance/artists-ready-for-payout"]}),j(null)},onError:t=>{d({title:"Confirmation Failed",description:t.message||"Failed to confirm payout",variant:"destructive"}),j(null)}}),A=g({mutationFn:async({payoutId:t})=>(await v(`/api/admin/finance/payout/${t}`,"DELETE")).json(),onSuccess:()=>{d({title:"Payout Deleted",description:"Pending payout has been removed."}),r.invalidateQueries({queryKey:["/api/admin/finance/metrics"]}),r.invalidateQueries({queryKey:["/api/admin/finance/payouts"]}),r.invalidateQueries({queryKey:["/api/admin/finance/artists-ready-for-payout"]})},onError:t=>{d({title:"Delete Failed",description:t.message||"Failed to delete payout",variant:"destructive"})}}),B=t=>{const a=t.payoutMethod||"stripe";if(a==="stripe"&&!t.stripeAccountId){d({title:"Cannot Process Payout",description:"Artist has not connected their Stripe account.",variant:"destructive"});return}if(a==="paypal"&&!t.paypalEmail){d({title:"Cannot Process Payout",description:"Artist has not provided their PayPal email.",variant:"destructive"});return}f(t.id),T.mutate({artistId:t.id,amount:t.earningsBalance,payoutMethod:a})},i=t=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(t),K=[{title:"Total Revenue",value:i((s==null?void 0:s.revenue)||0),icon:_,description:"From credit purchases",testId:"metric-revenue",color:"text-green-600"},{title:"Paid to Artists",value:i((s==null?void 0:s.paidOut)||0),icon:O,description:"Completed payouts",testId:"metric-paid-out",color:"text-blue-600"},{title:"Platform Profit",value:i((s==null?void 0:s.platformProfit)||0),icon:V,description:"Revenue minus costs",testId:"metric-platform-profit",color:s&&s.platformProfit>=0?"text-green-600":"text-red-600"},{title:"Pending Payouts",value:i((s==null?void 0:s.pendingPayouts)||0),icon:U,description:"Artists ≥ $10 balance",testId:"metric-pending-payouts",color:"text-orange-600"},{title:"Current Liability",value:i((s==null?void 0:s.currentLiability)||0),icon:z,description:"Total unpaid earnings",testId:"metric-current-liability",color:"text-purple-600"},{title:"Credit Balance",value:i((s==null?void 0:s.creditBalance)||0),icon:G,description:`${(s==null?void 0:s.totalUnusedCredits)||0} unused credits`,testId:"metric-credit-balance",color:"text-indigo-600"}],k=t=>{const n={credit_purchase:{variant:"default",label:"Purchase"},credit_refund:{variant:"destructive",label:"Refund"},admin_adjustment:{variant:"secondary",label:"Adjustment"},image_score:{variant:"outline",label:"Score"}}[t]||{variant:"outline",label:t};return e.jsx(h,{variant:n.variant,"data-testid":`badge-transaction-type-${t}`,children:n.label})},Q=t=>{const n={pending:{variant:"secondary",label:"Pending"},completed:{variant:"default",label:"Completed"},failed:{variant:"destructive",label:"Failed"}}[t]||{variant:"outline",label:t};return e.jsx(h,{variant:n.variant,"data-testid":`badge-payout-status-${t}`,children:n.label})};return e.jsx(W,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold","data-testid":"heading-finance",children:"Finance"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Platform financial overview and transactions"})]}),I?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[...Array(6)].map((t,a)=>e.jsxs(m,{children:[e.jsx(x,{className:"pb-2",children:e.jsx("div",{className:"h-4 bg-muted rounded animate-pulse"})}),e.jsxs(u,{children:[e.jsx("div",{className:"h-8 bg-muted rounded animate-pulse mb-2"}),e.jsx("div",{className:"h-3 bg-muted rounded animate-pulse w-2/3"})]})]},a))}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:K.map(t=>e.jsxs(m,{children:[e.jsxs(x,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(y,{className:"text-sm font-medium",children:t.title}),e.jsx(t.icon,{className:`h-4 w-4 ${t.color}`})]}),e.jsxs(u,{children:[e.jsx("div",{className:`text-2xl font-bold ${t.color}`,"data-testid":t.testId,children:t.value}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t.description})]})]},t.title))}),e.jsxs(m,{children:[e.jsx(x,{children:e.jsx(y,{"data-testid":"heading-recent-transactions",children:"Recent Transactions"})}),e.jsx(u,{children:F?e.jsx("div",{className:"space-y-3",children:[...Array(5)].map((t,a)=>e.jsx("div",{className:"h-12 bg-muted rounded animate-pulse"},a))}):l!=null&&l.transactions&&l.transactions.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",children:[e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Date"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"User"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Type"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Amount"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Credits"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Description"})]})}),e.jsx("tbody",{children:l.transactions.map(t=>e.jsxs("tr",{className:"border-b","data-testid":`row-transaction-${t.id}`,children:[e.jsx("td",{className:"py-3 px-4 text-sm","data-testid":`text-transaction-date-${t.id}`,children:b(new Date(t.createdAt),"MMM d, yyyy")}),e.jsx("td",{className:"py-3 px-4 text-sm","data-testid":`text-transaction-user-${t.id}`,children:t.user?`${t.user.firstName||""} ${t.user.lastName||""}`.trim()||t.user.email:"N/A"}),e.jsx("td",{className:"py-3 px-4 text-sm",children:k(t.type)}),e.jsx("td",{className:"py-3 px-4 text-sm font-medium","data-testid":`text-transaction-amount-${t.id}`,children:i(t.amount)}),e.jsx("td",{className:"py-3 px-4 text-sm","data-testid":`text-transaction-credits-${t.id}`,children:t.credits||"-"}),e.jsx("td",{className:"py-3 px-4 text-sm text-muted-foreground","data-testid":`text-transaction-description-${t.id}`,children:t.description||"-"})]},t.id))})]})}):e.jsx("p",{className:"text-muted-foreground text-center py-8","data-testid":"text-no-transactions",children:"No transactions yet"})})]}),e.jsxs(m,{children:[e.jsx(x,{children:e.jsx(y,{"data-testid":"heading-recent-payouts",children:"Recent Payouts"})}),e.jsx(u,{children:q?e.jsx("div",{className:"space-y-3",children:[...Array(5)].map((t,a)=>e.jsx("div",{className:"h-12 bg-muted rounded animate-pulse"},a))}):o!=null&&o.payouts&&o.payouts.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",children:[e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Date"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Artist"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Amount"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Status"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Completed"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Notes"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Actions"})]})}),e.jsx("tbody",{children:o.payouts.map(t=>e.jsxs("tr",{className:"border-b","data-testid":`row-payout-${t.id}`,children:[e.jsx("td",{className:"py-3 px-4 text-sm","data-testid":`text-payout-date-${t.id}`,children:b(new Date(t.createdAt),"MMM d, yyyy")}),e.jsx("td",{className:"py-3 px-4 text-sm","data-testid":`text-payout-artist-${t.id}`,children:t.artist?`${t.artist.firstName||""} ${t.artist.lastName||""}`.trim()||t.artist.email:"N/A"}),e.jsx("td",{className:"py-3 px-4 text-sm font-medium","data-testid":`text-payout-amount-${t.id}`,children:i(t.amount)}),e.jsx("td",{className:"py-3 px-4 text-sm",children:Q(t.status)}),e.jsx("td",{className:"py-3 px-4 text-sm","data-testid":`text-payout-completed-${t.id}`,children:t.completedAt?b(new Date(t.completedAt),"MMM d, yyyy"):"-"}),e.jsx("td",{className:"py-3 px-4 text-sm text-muted-foreground","data-testid":`text-payout-notes-${t.id}`,children:t.notes||"-"}),e.jsx("td",{className:"py-3 px-4 text-sm",children:t.status==="pending"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(N,{size:"sm",variant:"outline",onClick:()=>{j(t.id),E.mutate({payoutId:t.id})},disabled:$===t.id,"data-testid":`button-confirm-payout-${t.id}`,children:$===t.id?e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"mr-2 h-4 w-4 animate-spin"}),"Confirming..."]}):"Confirm Paid"}),e.jsx(N,{size:"icon",variant:"ghost",className:"text-muted-foreground",onClick:()=>A.mutate({payoutId:t.id}),disabled:A.isPending,"data-testid":`button-delete-payout-${t.id}`,children:e.jsx(H,{className:"h-4 w-4"})})]}):"-"})]},t.id))})]})}):e.jsx("p",{className:"text-muted-foreground text-center py-8","data-testid":"text-no-payouts",children:"No payouts yet"})})]}),e.jsxs(m,{children:[e.jsx(x,{children:e.jsx(y,{"data-testid":"heading-artists-ready",children:"Artists Ready for Payout"})}),e.jsx(u,{children:L?e.jsx("div",{className:"space-y-3",children:[...Array(3)].map((t,a)=>e.jsx("div",{className:"h-12 bg-muted rounded animate-pulse"},a))}):c!=null&&c.artists&&c.artists.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",children:[e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Artist"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Email"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Balance"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Payout Method"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-muted-foreground",children:"Actions"})]})}),e.jsx("tbody",{children:c.artists.map(t=>
6{const a=t.payoutMethod||"stripe",n=a==="stripe"?!!t.stripeAccountId:!!t.paypalEmail;return e.jsxs("tr",{className:"border-b","data-testid":`row-artist-${t.id}`,children:[e.jsx("td",{className:"py-3 px-4 text-sm","data-testid":`text-artist-name-${t.id}`,children:`${t.firstName||""} ${t.lastName||""}`.trim()||"N/A"}),e.jsx("td",{className:"py-3 px-4 text-sm","data-testid":`text-artist-email-${t.id}`,children:t.email}),e.jsx("td",{className:"py-3 px-4 text-sm font-medium text-green-600","data-testid":`text-artist-balance-${t.id}`,children:i(t.earningsBalance)}),e.jsx("td",{className:"py-3 px-4 text-sm",children:a==="paypal"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(h,{variant:"outline",className:"flex items-center gap-1","data-testid":`badge-paypal-${t.id}`,children:[e.jsx(w,{className:"w-3 h-3 text-[#003087]"}),"PayPal"]}),t.paypalEmail&&e.jsx("span",{className:"text-xs text-muted-foreground",children:t.paypalEmail})]}):e.jsxs(h,{variant:t.stripeAccountId?"default":"secondary",className:"flex items-center gap-1 w-fit","data-testid":`badge-stripe-${t.id}`,children:[e.jsx(S,{className:"w-3 h-3"}),t.stripeAccountId?"Stripe Connected":"Stripe Not Set"]})}),e.jsx("td",{className:"py-3 px-4 text-sm",children:e.jsx(N,{size:"sm",onClick:()=>B(t),disabled:!n||P===t.id,"data-testid":`button-payout-${t.id}`,children:P===t.id?e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"mr-2 h-4 w-4 animate-spin"}),"Processing..."]}):e.jsxs(e.Fragment,{children:[a==="paypal"?e.jsx(w,{className:"mr-1 h-3 w-3"}):e.jsx(S,{className:"mr-1 h-3 w-3"}),"Pay ",i(t.earningsBalance)]})})})]},t.id)})})]})}):e.jsx("p",{className:"text-muted-foreground text-center py-8","data-testid":"text-no-artists-ready",children:"No artists ready for payout (minimum $10 balance required)"})})]})]})})}export{de 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.