@arcblock/payment-service 1.29.7 → 1.29.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cf.d.ts +31 -0
- package/dist/cf.js +79 -60
- package/dist/index.d.ts +17 -0
- package/dist/index.js +264 -73
- package/package.json +4 -4
- package/web/assets/{account-DETfFe4_.js → account-Clbqiiw3.js} +1 -1
- package/web/assets/{action-B_DQJlip.js → action-DENqSeOa.js} +1 -1
- package/web/assets/{actions-BtaoyTWt.js → actions-0iWP2mcx.js} +1 -1
- package/web/assets/{actions-QPa-8lfB.js → actions-BD9BAp3M.js} +1 -1
- package/web/assets/{actions-jxGAdGfb.js → actions-BJDN6Op2.js} +1 -1
- package/web/assets/{actions-DJyfN5OU.js → actions-BSNy5bOd.js} +1 -1
- package/web/assets/{actions-Bt_jST94.js → actions-CDsj5j8l.js} +1 -1
- package/web/assets/{actions-D9MHLBFH.js → actions-CSpJGOX7.js} +1 -1
- package/web/assets/{actions-BknL4OyZ.js → actions-CZL47E9r.js} +1 -1
- package/web/assets/{actions-EPYeS5p4.js → actions-D3tJgrUn.js} +1 -1
- package/web/assets/{actions-BaDh4xWX.js → actions-DGQs8fFF.js} +1 -1
- package/web/assets/{add-price-CD-utowo.js → add-price-BpnICuHO.js} +1 -1
- package/web/assets/{admin-_nEB-lHn.js → admin-CD8ViZ7D.js} +1 -1
- package/web/assets/{assign-CkV5Q2LP.js → assign-0vMUDW_C.js} +1 -1
- package/web/assets/{attempts-DySeqBYU.js → attempts-CKlxkJuE.js} +1 -1
- package/web/assets/browser-DDv4_sgY.js +1 -0
- package/web/assets/{change-payment-CPUCUEER.js → change-payment-gAlRmJpv.js} +1 -1
- package/web/assets/{change-plan-CxE-XfWc.js → change-plan-C47wfWH8.js} +1 -1
- package/web/assets/{click-boundary-y8dVA_tr.js → click-boundary-CafubiPp.js} +1 -1
- package/web/assets/{connect-CC_l_f6Q.js → connect-BHHzrwLA.js} +1 -1
- package/web/assets/{copyable-DpX04wZz.js → copyable-QrCyyiou.js} +1 -1
- package/web/assets/{create-3SsWCAOC.js → create-0PUtkJZY.js} +1 -1
- package/web/assets/{create-BkQAaSvD.js → create-BJ1asdcy.js} +1 -1
- package/web/assets/{create-kG09X9gl.js → create-Bgv5ux17.js} +1 -1
- package/web/assets/{create-BmcRybZ5.js → create-C7GOgZZM.js} +1 -1
- package/web/assets/{create-tYebjhr9.js → create-DNar5UQD.js} +1 -1
- package/web/assets/{create-Bs65p5Ne.js → create-ke4FrPx1.js} +1 -1
- package/web/assets/{credit-grant-item-list-Bk27jIc7.js → credit-grant-item-list-CeDAM3qV.js} +1 -1
- package/web/assets/{credit-overview-DmMSEs14.js → credit-overview-4zh0H02x.js} +2 -2
- package/web/assets/{currency-restrictions-DYLv4YyW.js → currency-restrictions-BcEm8W45.js} +1 -1
- package/web/assets/{currency-select-DGS-62-L.js → currency-select-B4ieQBvv.js} +1 -1
- package/web/assets/{dayjs-B9tvQIKg.js → dayjs-DUTDpcNU.js} +1 -1
- package/web/assets/{description-Ym17DL48.js → description-SnR5WxWT.js} +1 -1
- package/web/assets/detail-46aLUdJj.js +1 -0
- package/web/assets/{detail-Cr2wG4Th.js → detail-B-ceWfZr.js} +1 -1
- package/web/assets/detail-B0IHl4MI.js +1 -0
- package/web/assets/detail-B8eOBVSQ.js +15 -0
- package/web/assets/{detail-DE3OOC5M.js → detail-BO3zglCn.js} +1 -1
- package/web/assets/{detail-DG4l2CqN.js → detail-BQpDGZJQ.js} +1 -1
- package/web/assets/{detail-CxYQYu_l.js → detail-BXTsnQny.js} +1 -1
- package/web/assets/{detail-CT9Unyrf.js → detail-B_lpOomD.js} +1 -1
- package/web/assets/{detail-Do9QO5L2.js → detail-Bfnkg0A1.js} +1 -1
- package/web/assets/detail-BwH0DwAi.js +1 -0
- package/web/assets/{detail-OZeeKI69.js → detail-C1FupF1D.js} +2 -2
- package/web/assets/{detail-cwHZbY62.js → detail-CMBRd4Ct.js} +1 -1
- package/web/assets/detail-C_Zdfa0y.js +1 -0
- package/web/assets/{detail-Cb9HBSMw.js → detail-Cg505nKX.js} +1 -1
- package/web/assets/{detail-DB56SG-k.js → detail-CsGZMimg.js} +1 -1
- package/web/assets/{detail-K9EVY3r2.js → detail-Ct5QNBqu.js} +1 -1
- package/web/assets/{detail-DuO_Jn5X.js → detail-CyMhK5K_.js} +1 -1
- package/web/assets/{detail-DuWdZIyp.js → detail-DACnmls3.js} +1 -1
- package/web/assets/{detail-BJTcK7mx.js → detail-DCTb8R7F.js} +1 -1
- package/web/assets/{detail-DPCTQLOx.js → detail-DNcp_u5S.js} +1 -1
- package/web/assets/detail-DbU3p040.js +1 -0
- package/web/assets/{detail-D5KRrQDx.js → detail-Tn2R5C8i.js} +1 -1
- package/web/assets/{detail-15zxCbV9.js → detail-wU4wNf4s.js} +1 -1
- package/web/assets/{drawer-form-Cl0T1Yyt.js → drawer-form-DspWWj3x.js} +1 -1
- package/web/assets/{edit-3HUAnaXW.js → edit-Bkj-OTJh.js} +1 -1
- package/web/assets/{editor-BF5I0siU.js → editor-AmthipP2.js} +1 -1
- package/web/assets/{embed-CsNqeCd0.js → embed-rRKjDoHi.js} +1 -1
- package/web/assets/{filter-toolbar-BydfQ-79.js → filter-toolbar-DXGSTq57.js} +1 -1
- package/web/assets/{form-DSzMo9UD.js → form-B5WW-lS5.js} +1 -1
- package/web/assets/form-BmQlJZ84.js +9 -0
- package/web/assets/{form-BGm5NPDn.js → form-CAPjlw7l.js} +1 -1
- package/web/assets/{form-CKfKLGXP.js → form-DD-EiA7W.js} +3 -3
- package/web/assets/{form-P4luyUpY.js → form-cX026J4G.js} +1 -1
- package/web/assets/{gas-Qf0SSUfS.js → gas-nyR96dB0.js} +1 -1
- package/web/assets/{generateCategoricalChart-BaWwaXky.js → generateCategoricalChart-BadryV3H.js} +1 -1
- package/web/assets/{home-HbrLyxJL.js → home-_eX1aim8.js} +1 -1
- package/web/assets/index-BBHMsIxJ.js +1 -0
- package/web/assets/{index-Dr_MwbKt.js → index-BQjlhCSt.js} +1 -1
- package/web/assets/{index-DPodCQ9c.js → index-BRENdB5m.js} +1 -1
- package/web/assets/{index-9xBRL_33.js → index-BTfJ08JU.js} +1 -1
- package/web/assets/{index-DgSc1Qy8.js → index-BarN7DfU.js} +17 -17
- package/web/assets/index-BhcoukR2.js +1 -0
- package/web/assets/index-BturOfxo.js +1 -0
- package/web/assets/{index-SYTpMMMH.js → index-BzABukCz.js} +1 -1
- package/web/assets/{index-2l22EYw9.js → index-C-RT84yb.js} +1 -1
- package/web/assets/{index-C0JaS08f.js → index-C136x0O2.js} +1 -1
- package/web/assets/{index-Cw0ugaQL.js → index-CCVDDX0c.js} +1 -1
- package/web/assets/index-CDVogp6E.js +1 -0
- package/web/assets/{index-Br7_mvEw.js → index-CW8VfoJO.js} +1 -1
- package/web/assets/{index-BIoSdRvX.js → index-CbSXdD6E.js} +3 -3
- package/web/assets/{index-CdkYrABk.js → index-Cd_BD9TM.js} +1 -1
- package/web/assets/index-D-bx9Kam.js +1 -0
- package/web/assets/index-D0mynT6_.js +1 -0
- package/web/assets/index-DEiuhiEo.js +14 -0
- package/web/assets/{index-DE2KzqXl.js → index-DNGmCIRP.js} +1 -1
- package/web/assets/{index-CI_EY4YS.js → index-DSe7Dot_.js} +1 -1
- package/web/assets/{index-BFML4-2u.js → index-DcddP3R9.js} +1 -1
- package/web/assets/index-DcrGSDby.js +1 -0
- package/web/assets/{index-fByZjxLy.js → index-DeK5Pqjv.js} +1 -1
- package/web/assets/{index-Clbt8nRm.js → index-DoX0A-rP.js} +1 -1
- package/web/assets/index-Du0Ieh1F.js +49 -0
- package/web/assets/index-Dybqd298.js +1 -0
- package/web/assets/index-EXZPddtw.js +1 -0
- package/web/assets/{index-Drav4oDH.js → index-Kd_qCyRG.js} +2 -2
- package/web/assets/{index-Dc954mDP.js → index-SOzRg0yJ.js} +1 -1
- package/web/assets/{index-BMKZToMM.js → index-UYeD8rTJ.js} +2 -2
- package/web/assets/{index-DZpJPE1Z.js → index-W2uZUlFs.js} +1 -1
- package/web/assets/{index-1y9kjPIr.js → index-XaFn2ySq.js} +1 -1
- package/web/assets/{index-fswPX_qe.js → index-YG5oc8O3.js} +1 -1
- package/web/assets/{index-B1pTTyGZ.js → index-ajD9Iotk.js} +1 -1
- package/web/assets/index-brUCsnBA.js +1 -0
- package/web/assets/{index-BP53rZV9.js → index-mn5Zdrtn.js} +1 -1
- package/web/assets/index-qulrJQ4J.js +1 -0
- package/web/assets/{index.es-BWnfUzLb.js → index.es-C8dcCHdW.js} +1 -1
- package/web/assets/{info-card-C1yxhxJG.js → info-card-BvIMFQo5.js} +1 -1
- package/web/assets/{info-metric-CNse3r66.js → info-metric-Dl4ZDm0Z.js} +1 -1
- package/web/assets/{info-row-group-BeUhWnnY.js → info-row-group-CFuMWJf1.js} +1 -1
- package/web/assets/{info-row-DOK2whMn.js → info-row-jI0h_hv4.js} +1 -1
- package/web/assets/{libphonenumber-CyphiuxQ.js → libphonenumber-Qs8PCdM-.js} +1 -1
- package/web/assets/{link-3eeclTeS.js → link-CmPoIweR.js} +1 -1
- package/web/assets/{list-DnePqZ2K.js → list-BdSkPjIa.js} +1 -1
- package/web/assets/{list-jHj_5yy3.js → list-CWMEf-_C.js} +1 -1
- package/web/assets/{list-C521zE_7.js → list-CkHExntK.js} +1 -1
- package/web/assets/{list-CO0X4L3-.js → list-DLB_hd0Q.js} +1 -1
- package/web/assets/{list-D-I0msRW.js → list-DVFJwd_I.js} +2 -2
- package/web/assets/{list-D1aevUOI.js → list-DaK9287Y.js} +2 -2
- package/web/assets/{list-1OG83xc4.js → list-DghnUOc4.js} +1 -1
- package/web/assets/{list-CNmzJKIQ.js → list-eFkvVlp5.js} +1 -1
- package/web/assets/metadata-BmQTVFku.js +55 -0
- package/web/assets/{meter-event-lmNMgmIu.js → meter-event-B1JIhVpb.js} +1 -1
- package/web/assets/{metrics-C7U41HWk.js → metrics-UvxyQbUF.js} +1 -1
- package/web/assets/{overview-Cs3-8n4e.js → overview-Cxc6WKba.js} +1 -1
- package/web/assets/{overview-CH1HnSP-.js → overview-DrMaIptb.js} +1 -1
- package/web/assets/{past-due-CGGRZmXY.js → past-due-CUXkxns0.js} +1 -1
- package/web/assets/pay-omLYkqRA.js +4 -0
- package/web/assets/{payment-method-info-BsOBbA3m.js → payment-method-info-Bsf89VxV.js} +2 -2
- package/web/assets/{preview-DjYRpRA8.js → preview-BifsgUGT.js} +1 -1
- package/web/assets/{preview-CjYh9dTg.js → preview-C-H8pGVw.js} +1 -1
- package/web/assets/{pricing-table-C3Lkhq46.js → pricing-table-B3QOaAB5.js} +2 -2
- package/web/assets/{pricing-table-edE6TJGX.js → pricing-table-BUJdtkMq.js} +1 -1
- package/web/assets/{product-select-0ScZE2e8.js → product-select-ChEyoJqJ.js} +1 -1
- package/web/assets/{recharge-DcPtT8vt.js → recharge-BVT4USAO.js} +1 -1
- package/web/assets/{related-credit-grants-BygNGPfb.js → related-credit-grants-JV2ICsR5.js} +22 -22
- package/web/assets/{safe-did-address-B0fFbUph.js → safe-did-address-CiG_V6Gy.js} +1 -1
- package/web/assets/{source-data-viewer-By_Utay-.js → source-data-viewer-i1q9wNIG.js} +1 -1
- package/web/assets/{status-l6pD08fw.js → status-CUVYrUIG.js} +1 -1
- package/web/assets/subscription-BYz_k9dq.js +1 -0
- package/web/assets/{subscription-Dq22e3D1.js → subscription-DrnSPIfs.js} +1 -1
- package/web/assets/table-BrtHemkA.js +1 -0
- package/web/assets/{tax-code-select-CWhIIiXi.js → tax-code-select-TS07I0rB.js} +1 -1
- package/web/assets/{tax-utils-DqNX34-r.js → tax-utils-bPjALcVG.js} +1 -1
- package/web/assets/{uploader-DRXDz_r0.js → uploader-CsQNHG4I.js} +1 -1
- package/web/assets/{usage-records-jjJMZ6DI.js → usage-records-DAUQMJAW.js} +1 -1
- package/web/assets/{util-mDHAL0lx.js → util-DxXTXkeY.js} +1 -1
- package/web/assets/{vendor-arcblock-ChFCRdyx.js → vendor-arcblock-BTCAQSUK.js} +1 -1
- package/web/assets/{vendor-blocklet-D_i_QeSo.js → vendor-blocklet-DcLR2Cyf.js} +43 -43
- package/web/index.html +1 -1
- package/web/assets/browser-DSLTxXlL.js +0 -1
- package/web/assets/detail-ASPdMJoW.js +0 -1
- package/web/assets/detail-CIx9vkir.js +0 -1
- package/web/assets/detail-D5NbV29V.js +0 -1
- package/web/assets/detail-DVVzYhdV.js +0 -1
- package/web/assets/detail-Dqc0OfCQ.js +0 -1
- package/web/assets/detail-uhlID8jD.js +0 -15
- package/web/assets/form-BXAuSawq.js +0 -9
- package/web/assets/index-0HK7CYm4.js +0 -1
- package/web/assets/index-BJ_E6bEO.js +0 -1
- package/web/assets/index-Bnyh4rlV.js +0 -1
- package/web/assets/index-BoQ7wf3O.js +0 -1
- package/web/assets/index-C68x-aau.js +0 -1
- package/web/assets/index-C8s2QKoe.js +0 -1
- package/web/assets/index-Cn7O-OP7.js +0 -49
- package/web/assets/index-DU39aG5u.js +0 -1
- package/web/assets/index-DtbqgSK4.js +0 -1
- package/web/assets/index-DuRu9NWB.js +0 -14
- package/web/assets/index-WMKOiUez.js +0 -1
- package/web/assets/index-dmHgoplS.js +0 -1
- package/web/assets/index-txVTkoDD.js +0 -1
- package/web/assets/metadata-CMSHcSXi.js +0 -55
- package/web/assets/pay-CSpHBUh_.js +0 -4
- package/web/assets/subscription-DcwhSOpa.js +0 -1
- package/web/assets/table-BRU4Enia.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{r as m,j as e,bg as ce,a3 as u,q as f,a2 as le,B as P,A as Se,aX as Te,aZ as ee,aT as Ae,ad as Re,N as Pe,x as G,w as de,b_ as Ie,bU as qe,bL as ke,bH as ue,aN as ze,aM as X,b$ as Me,c0 as $e}from"./vendor-mui-BXZut9Pz.js";import{V as Q,X as Ne,O as H,$ as Fe,Y as q,a6 as Le,E as me,ap as te,F as ne}from"./vendor-blocklet-D_i_QeSo.js";import{f as ae,aR as Ee,aS as Be,aT as We,ay as De,a8 as Oe,aU as Ue,M as Ge,aV as re,a as Ve,W as He,h as Qe,F as Xe,S as Ze,aW as se,C as ie,a3 as pe,aX as oe,a0 as Je,e as N,k as U,i as he,a1 as Ye,l as xe,aY as Ke,aZ as et,a_ as tt,A as nt}from"./index-DgSc1Qy8.js";import{a as at,b as rt}from"./vendor-react-BPknnnEA.js";import{I as st}from"./collapse-CSrlJ0eG.js";function it({product:t,price:r,currency:i,quantity:c,onQuantityChange:o,maxQuantity:b=99,minQuantity:s=1,creditCurrency:j,exchangeRate:d=null,isDynamicPricing:A=!1,exchangeRateData:v=null,slippageConfig:w=null,slippagePercent:k=.5,onSlippageChange:z=void 0,disabled:R=!1}){const{t:S,locale:I}=Q(),[p,x]=m.useState(c),a=Number(p)||0,{paymentAmount:l,usdReferenceDisplay:y}=m.useMemo(()=>{if(!A||!d||!r?.base_amount)return{paymentAmount:ae(r,i,t?.unit_label,p,!0),usdReferenceDisplay:null};const T=Number(r.base_amount)*a,C=Number(d);if(C<=0||!Number.isFinite(T))return{paymentAmount:ae(r,i,t?.unit_label,p,!0),usdReferenceDisplay:null};const D=T/C,M=Ee(D,!0,6),$=Be(T.toString(),I);return{paymentAmount:`${M} ${i.symbol}`,usdReferenceDisplay:$?`≈ $${$}`:null}},[A,d,r,i,t?.unit_label,p,a,I]),_=T=>{if(!T){x(void 0);return}T>=s&&T<=b&&(x(T),o(T))},F=T=>{const C=parseInt(T.target.value||"0",10);Number.isNaN(C)||_(C)},L=Number(r.metadata?.credit_config?.credit_amount||0);return e.jsxs(ce,{variant:"outlined",sx:{p:2},children:[e.jsxs(u,{direction:"row",spacing:2,sx:{flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(u,{direction:"row",spacing:2,sx:{alignItems:"center",flex:1},children:e.jsx(We,{name:t?.name||"",description:S("payment.autoTopup.creditsIncluded",{num:De(Oe(L*a),j?.symbol||"",I)}),logo:t?.images?.[0],size:40})}),e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center",alignSelf:{xs:"flex-end",sm:"center"}},children:[e.jsxs(f,{variant:"body2",sx:{color:"text.secondary",minWidth:"fit-content"},children:[S("common.quantity"),":"]}),e.jsx(le,{size:"small",value:p,onChange:F,type:"number",sx:{"& .MuiInputBase-root":{height:32}},slotProps:{htmlInput:{min:0,max:b,style:{textAlign:"center",padding:"4px 8px"}}}})]})]}),e.jsxs(u,{direction:"row",sx:{justifyContent:"space-between",alignItems:"flex-start",mt:2,pt:2,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:S("payment.autoTopup.rechargeAmount")}),e.jsxs(u,{sx:{alignItems:"flex-end"},children:[e.jsx(f,{variant:"h6",sx:{fontWeight:600,color:"text.primary"},children:l}),y&&e.jsx(f,{sx:{fontSize:"0.7875rem",color:"text.lighter"},children:y}),A&&v?.rate&&e.jsx(Ue,{rateLine:S("payment.checkout.quote.rateLine",{symbol:i.symbol,rate:`$${re(v.rate)||v.rate}`}),rows:[{label:S("payment.checkout.quote.detailProvider"),value:v?.provider_display||v?.provider_name||"—"},{label:S("payment.checkout.quote.detailUpdatedAt"),value:v?.timestamp_ms?Ge(v.timestamp_ms,I):"—"},{label:S("payment.checkout.quote.detailSlippage"),value:w?.mode==="rate"&&w.min_acceptable_rate?`$${re(w.min_acceptable_rate)||w.min_acceptable_rate}`:`${w?.percent??k}%`,isSlippage:!0}],isSubscription:!0,slippageValue:w?.percent??k,slippageConfig:w||void 0,onSlippageChange:z,exchangeRate:v?.rate,baseCurrency:"USD",disabled:R})]})]})]})}const ot=async(t,r)=>{const{data:i}=await N.get(`/api/auto-recharge-configs/customer/${t}`,{params:{currency_id:r}});return i},ct=async(t,r)=>{const{data:i}=await N.get("/api/customers/payer-token",{params:{currencyId:t,payerAddress:r}});return i},B={enabled:!1,threshold:"100",quantity:1,payment_method_id:"",recharge_currency_id:"",price_id:"",daily_max_amount:0,daily_max_attempts:0},lt=async t=>{const{data:r}=await N.post("/api/exchange-rates/validate",{currency:t});return r},dt=async t=>{let r;return await Ye(async()=>{const{data:i}=await N.get(`/api/auto-recharge-configs/retrieve/${t}`);return r=i,!!r.payment_settings?.payment_method_options?.[r.paymentMethod.type]?.payer},{interval:2e3,timeout:180*1e3}),r};function ut({config:t,onChangePaymentMethod:r,paymentMethod:i,currency:c}){const{t:o}=Q(),[b,s]=m.useState(!1),j=at(),d=t?.payment_settings?.payment_method_options?.[i.type||""],{data:A,loading:v}=H(async()=>i.type==="stripe"?null:await ct(c.id,d?.payer),{refreshDeps:[c.id,d?.payer],ready:!!c.id&&!!d?.payer}),w=()=>{const R=!b;s(R),r(R)};if(!d)return null;const k=R=>{const S=me(xe(),`/customer/recharge/${c.id}?rechargeAddress=${d?.payer}`),I=Ke(S,!0);et(R,I,j)},z=()=>i.type==="stripe"?e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(qe,{fontSize:"small",color:"primary"}),e.jsxs(f,{variant:"body2",children:["**** **** **** ",d?.card_last4||"****"]}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary",textTransform:"uppercase"},children:d?.card_brand||"CARD"}),d?.exp_time&&e.jsx(f,{variant:"body2",sx:{color:"text.secondary",borderLeft:"1px solid",borderColor:"divider",pl:1},children:d?.exp_time})]}):e.jsxs(u,{spacing:1,sx:{borderRadius:1,backgroundColor:R=>R.palette.mode==="dark"?"grey.100":"grey.50",p:2},children:[e.jsx(Le,{did:d?.payer,responsive:!1,compact:!0,copyable:!1}),(A||v)&&e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[v?e.jsx(de,{size:14,sx:{mr:.5}}):e.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(ke,{fontSize:"small",sx:{color:"text.lighter"}}),e.jsxs(f,{variant:"body2",sx:{color:"text.primary"},children:[e.jsxs("strong",{children:[he(A?.token||"0",c?.decimal)," "]}),c?.symbol||""]})]}),e.jsxs(G,{size:"small",variant:"text",onClick:k,sx:{fontSize:"smaller",color:"primary.main"},children:[e.jsx(ue,{fontSize:"small"}),o("payment.autoTopup.addFunds")]})]})]});return e.jsx(P,{sx:{p:2,border:"1px solid",borderColor:b?"primary.main":"divider",borderRadius:1,bgcolor:b?"primary.50":"background.paper"},children:e.jsxs(u,{spacing:2,children:[e.jsxs(u,{sx:{flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(f,{variant:"subtitle2",sx:{display:"flex",alignItems:"center",gap:1,whiteSpace:"nowrap"},children:o("payment.autoTopup.currentPaymentMethod")}),e.jsx(G,{size:"small",startIcon:e.jsx(Ie,{}),onClick:w,variant:"text",sx:{color:"primary.main",whiteSpace:"nowrap",alignSelf:{xs:"flex-end",sm:"center"}},children:o(b?"payment.autoTopup.keepCurrent":"payment.autoTopup.changePaymentMethod")})]}),b?e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:o("payment.autoTopup.changePaymentMethodTip")}):z()]})})}function mt({open:t,onClose:r,currencyId:i,onSuccess:c=()=>{},onError:o=()=>{},defaultEnabled:b=void 0}){const{t:s,locale:j}=Q(),{session:d,connect:A,settings:v}=Ve(),[w,k]=m.useState(!1),[z,R]=m.useState(.5),[S,I]=m.useState(null),[p,x]=Ne({loading:!1,submitting:!1,authorizationRequired:!1,stripeContext:{client_secret:"",intent_type:"",status:"",public_key:"",customer:{}}}),a=He(v.paymentMethods),l=Qe({defaultValues:{enabled:b||B.enabled,threshold:B.threshold,quantity:B.quantity,payment_method_id:B.payment_method_id,recharge_currency_id:B.recharge_currency_id,price_id:B.price_id,daily_limits:{max_attempts:B.daily_max_attempts,max_amount:B.daily_max_amount}}}),{handleSubmit:y,setValue:_,watch:F}=l,L=F("enabled"),T=F("quantity"),C=F("recharge_currency_id"),D=v.paymentMethods.find(n=>n.payment_currencies.find(h=>h.id===C)),M=D?.type==="stripe",$=()=>{x({loading:!1,submitting:!1,authorizationRequired:!1}),r()},{data:g}=H(()=>ot(d?.user?.did,i),{refreshDeps:[d?.user?.did,i],ready:!!d?.user?.did&&!!i,onError:n=>{q.error(U(n))},onSuccess:n=>{_("enabled",b||n.enabled),_("threshold",n.threshold),_("quantity",n.quantity),_("payment_method_id",n.payment_method_id),_("recharge_currency_id",n.recharge_currency_id||n.price?.currency_id),_("price_id",n.price_id),_("daily_limits",{max_amount:n.daily_limits?.max_amount||0,max_attempts:n.daily_limits?.max_attempts||0}),n.slippage_config&&(I(n.slippage_config),R(n.slippage_config.percent??.5))}}),W=g?.price?.pricing_type==="dynamic",{data:V}=H(()=>lt(C),{refreshDeps:[C],ready:!!C&&W&&L&&!M,pollingInterval:3e4,pollingWhenHidden:!1,onError:n=>{console.warn("Failed to fetch exchange rate:",n.message)}}),E=m.useMemo(()=>a.filter(n=>g?.price?.currency_options?.find(h=>h.currency_id===n.id)),[a,g]),J=async()=>{try{await dt(g?.id)&&(x({submitting:!1,authorizationRequired:!1}),c?.(g),$(),q.success(s("payment.autoTopup.saveSuccess")))}catch(n){q.error(U(n))}finally{x({submitting:!1,authorizationRequired:!1})}},ge=async()=>{try{const n={...g,enabled:!1};if(!g?.enabled)return;const{data:h}=await N.post("/api/auto-recharge-configs/submit",n);c?.(h),q.success(s("payment.autoTopup.disableSuccess"))}catch(n){q.error(U(n)),o?.(n)}},fe=async n=>{_("enabled",n),n||await ge()},be=n=>{x({authorizationRequired:!0}),n.stripeContext?x({stripeContext:{client_secret:n.stripeContext.client_secret,intent_type:n.stripeContext.intent_type,status:n.stripeContext.status,public_key:n.paymentMethod.settings.stripe.publishable_key,customer:n.customer}}):n.delegation&&_e()},_e=()=>{try{x({submitting:!0}),A.open({containerEl:void 0,saveConnect:!1,locale:j,action:"auto-recharge-auth",prefix:me(xe(),"/api/did"),extraParams:{autoRechargeConfigId:g?.id},messages:{scan:s("payment.autoTopup.authTip"),title:s("payment.autoTopup.authTitle"),confirm:s("common.connect.confirm")},onSuccess:async()=>{A.close(),await J()},onClose:()=>{A.close(),x({submitting:!1,authorizationRequired:!1})},onError:n=>{x({submitting:!1,authorizationRequired:!1}),q.error(U(n))}})}catch(n){x({submitting:!1,authorizationRequired:!1}),q.error(U(n))}},je=async n=>{x({submitting:!0});try{const h={customer_id:d?.user?.did,enabled:n.enabled,threshold:n.threshold,currency_id:i,recharge_currency_id:n.recharge_currency_id,price_id:n.price_id,quantity:n.quantity,daily_limits:{max_attempts:n.daily_limits.max_attempts||0,max_amount:n.daily_limits.max_amount||"0"},change_payment_method:w};W&&S&&(h.slippage_config={...S,updated_at_ms:Date.now()});const{data:O}=await N.post("/api/auto-recharge-configs/submit",h);if(O.balanceResult&&!O.balanceResult.sufficient){await be({...O.balanceResult,paymentMethod:O.paymentMethod,customer:O.customer});return}x({submitting:!1,authorizationRequired:!1}),c?.(O),$(),q.success(s("payment.autoTopup.saveSuccess"))}catch(h){x({submitting:!1,authorizationRequired:!1}),q.error(U(h)),o?.(h)}},Y=n=>{je(n)},K=E.find(n=>n.id===C),ve=p.authorizationRequired&&M,Ce=async()=>{await J()},we=()=>{x({submitting:!1,authorizationRequired:!1})};return e.jsx(Fe,{open:t,onClose:$,maxWidth:"sm",fullWidth:!0,className:"base-dialog",title:s("payment.autoTopup.title"),actions:L?e.jsxs(u,{direction:"row",spacing:2,children:[e.jsx(G,{variant:"outlined",onClick:$,disabled:p.submitting,children:s("common.cancel")}),e.jsxs(G,{variant:"contained",onClick:()=>y(Y)(),disabled:p.loading||p.authorizationRequired||p.submitting,children:[p.submitting&&e.jsx(de,{size:20,sx:{mr:1}}),s("payment.autoTopup.saveConfiguration")]})]}):null,children:e.jsx(Xe,{...l,children:e.jsx(P,{component:"form",onSubmit:y(Y),children:e.jsxs(u,{sx:{gap:2},children:[e.jsx(Se,{severity:"info",children:s("payment.autoTopup.tip")}),e.jsxs(u,{spacing:2,direction:"row",sx:{alignItems:"center"},children:[e.jsx(f,{variant:"subtitle1",children:s("payment.autoTopup.enableLabel")}),e.jsx(Te,{control:e.jsx(Ze,{checked:L,onChange:n=>fe(n.target.checked)}),label:""})]}),L&&e.jsxs(e.Fragment,{children:[e.jsx(P,{sx:{pt:1},children:e.jsxs(u,{spacing:2.5,children:[e.jsxs(u,{sx:{gap:2,flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"},".MuiTextField-root":{width:{xs:"100%",sm:"auto"}}},children:[e.jsx(se,{boxSx:{width:"fit-content",whiteSpace:"nowrap",marginBottom:0},children:s("payment.autoTopup.triggerThreshold")}),e.jsx(ie,{name:"threshold",control:l.control,rules:{required:s("payment.checkout.required"),min:{value:0,message:s("payment.autoTopup.thresholdMinError")}},render:({field:n})=>e.jsx(le,{...n,type:"number",placeholder:s("payment.autoTopup.thresholdPlaceholder"),sx:{input:{minWidth:80}},slotProps:{input:{endAdornment:e.jsx(ee,{position:"end",children:pe("",g?.currency?.symbol)})},htmlInput:{min:0,step:.01}}})})]}),e.jsxs(u,{sx:{gap:2,flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(se,{boxSx:{width:"fit-content",whiteSpace:"nowrap",marginBottom:0},children:s("payment.autoTopup.purchaseBelow")}),e.jsx(ie,{name:"recharge_currency_id",control:l.control,render:({field:n})=>e.jsx(Ae,{...n,value:n.value,onChange:h=>n.onChange(h.target.value),size:"small",children:E.map(h=>e.jsx(Re,{value:h?.id,children:e.jsxs(u,{direction:"row",sx:{alignItems:"center",gap:1},children:[e.jsx(Pe,{src:h?.logo,sx:{width:20,height:20},alt:h?.symbol}),e.jsxs(f,{sx:{color:"text.secondary"},children:[h?.symbol," (",h?.method?.name,")"]})]})},h?.id))})})]}),g?.price?.product&&e.jsx(it,{product:g.price.product,price:g.price,creditCurrency:g.currency,currency:E.find(n=>n.id===C)||E[0],quantity:T,onQuantityChange:n=>_("quantity",n),maxQuantity:9999,minQuantity:1,exchangeRate:V?.rate,isDynamicPricing:W&&!M,exchangeRateData:V,slippageConfig:S,slippagePercent:z,onSlippageChange:n=>{I(n),n.percent!==void 0&&R(n.percent)},disabled:p.submitting}),g&&K&&e.jsx(ut,{config:g,onChangePaymentMethod:k,currency:K,paymentMethod:D}),e.jsx(st,{trigger:s("payment.autoTopup.advanced"),children:e.jsxs(u,{sx:{gap:2,pl:2,pr:1},children:[e.jsx(oe,{name:"daily_limits.max_amount",label:s("payment.autoTopup.dailyLimits.maxAmount"),type:"number",placeholder:s("payment.autoTopup.dailyLimits.maxAmountPlaceholder"),tooltip:s("payment.autoTopup.dailyLimits.maxAmountDescription"),inputProps:{min:0,step:.01},slotProps:{input:{endAdornment:e.jsx(ee,{position:"end",children:E.find(n=>n.id===C)?.symbol||""})}},sx:{maxWidth:{xs:"100%",sm:"220px"}},layout:"horizontal"}),e.jsx(oe,{name:"daily_limits.max_attempts",label:s("payment.autoTopup.dailyLimits.maxAttempts"),type:"number",placeholder:s("payment.autoTopup.dailyLimits.maxAttemptsPlaceholder"),tooltip:s("payment.autoTopup.dailyLimits.maxAttemptsDescription"),inputProps:{min:0,step:1},sx:{maxWidth:{xs:"100%",sm:"220px"}},layout:"horizontal"})]})})]})}),e.jsx(u,{spacing:2,children:ve&&e.jsx(P,{sx:{mt:2},children:p.stripeContext&&e.jsx(P,{sx:{mt:2},children:e.jsx(Je,{clientSecret:p.stripeContext.client_secret,intentType:p.stripeContext.intent_type,publicKey:p.stripeContext.public_key,customer:p.stripeContext.customer,mode:"setup",onConfirm:Ce,onCancel:we})})})})]})]})})})})}function pt(t){if(!t)return"Unknown error";if(t?.name==="ZodError")return Array.isArray(t.errors)?t.errors.map(r=>r.message).join(`
|
|
1
|
+
import{r as m,j as e,bg as ce,a3 as u,q as f,a2 as le,B as P,A as Se,aX as Te,aZ as ee,aT as Ae,ad as Re,N as Pe,x as G,w as de,b_ as Ie,bU as qe,bL as ke,bH as ue,aN as ze,aM as Z,b$ as Me,c0 as $e}from"./vendor-mui-BXZut9Pz.js";import{V as Q,Y as Ne,P as H,$ as Fe,Z as q,a7 as Le,F as me,aq as te,G as ne}from"./vendor-blocklet-DcLR2Cyf.js";import{f as ae,aR as Ee,aS as Be,aT as We,ay as De,a8 as Ue,aU as Oe,M as Ge,aV as re,a as Ve,W as He,h as Qe,F as Ze,S as Je,aW as se,C as ie,a3 as pe,aX as oe,a0 as Xe,e as N,k as O,i as he,a1 as Ye,l as xe,aY as Ke,aZ as et,a_ as tt,A as nt}from"./index-BarN7DfU.js";import{a as at,b as rt}from"./vendor-react-BPknnnEA.js";import{I as st}from"./collapse-CSrlJ0eG.js";function it({product:t,price:r,currency:i,quantity:c,onQuantityChange:o,maxQuantity:b=99,minQuantity:s=1,creditCurrency:j,exchangeRate:d=null,isDynamicPricing:A=!1,exchangeRateData:v=null,slippageConfig:w=null,slippagePercent:k=.5,onSlippageChange:z=void 0,disabled:R=!1}){const{t:S,locale:I}=Q(),[p,x]=m.useState(c),a=Number(p)||0,{paymentAmount:l,usdReferenceDisplay:y}=m.useMemo(()=>{if(!A||!d||!r?.base_amount)return{paymentAmount:ae(r,i,t?.unit_label,p,!0),usdReferenceDisplay:null};const T=Number(r.base_amount)*a,C=Number(d);if(C<=0||!Number.isFinite(T))return{paymentAmount:ae(r,i,t?.unit_label,p,!0),usdReferenceDisplay:null};const D=T/C,M=Ee(D,!0,6),$=Be(T.toString(),I);return{paymentAmount:`${M} ${i.symbol}`,usdReferenceDisplay:$?`≈ $${$}`:null}},[A,d,r,i,t?.unit_label,p,a,I]),_=T=>{if(!T){x(void 0);return}T>=s&&T<=b&&(x(T),o(T))},F=T=>{const C=parseInt(T.target.value||"0",10);Number.isNaN(C)||_(C)},L=Number(r.metadata?.credit_config?.credit_amount||0);return e.jsxs(ce,{variant:"outlined",sx:{p:2},children:[e.jsxs(u,{direction:"row",spacing:2,sx:{flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(u,{direction:"row",spacing:2,sx:{alignItems:"center",flex:1},children:e.jsx(We,{name:t?.name||"",description:S("payment.autoTopup.creditsIncluded",{num:De(Ue(L*a),j?.symbol||"",I)}),logo:t?.images?.[0],size:40})}),e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center",alignSelf:{xs:"flex-end",sm:"center"}},children:[e.jsxs(f,{variant:"body2",sx:{color:"text.secondary",minWidth:"fit-content"},children:[S("common.quantity"),":"]}),e.jsx(le,{size:"small",value:p,onChange:F,type:"number",sx:{"& .MuiInputBase-root":{height:32}},slotProps:{htmlInput:{min:0,max:b,style:{textAlign:"center",padding:"4px 8px"}}}})]})]}),e.jsxs(u,{direction:"row",sx:{justifyContent:"space-between",alignItems:"flex-start",mt:2,pt:2,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:S("payment.autoTopup.rechargeAmount")}),e.jsxs(u,{sx:{alignItems:"flex-end"},children:[e.jsx(f,{variant:"h6",sx:{fontWeight:600,color:"text.primary"},children:l}),y&&e.jsx(f,{sx:{fontSize:"0.7875rem",color:"text.lighter"},children:y}),A&&v?.rate&&e.jsx(Oe,{rateLine:S("payment.checkout.quote.rateLine",{symbol:i.symbol,rate:`$${re(v.rate)||v.rate}`}),rows:[{label:S("payment.checkout.quote.detailProvider"),value:v?.provider_display||v?.provider_name||"—"},{label:S("payment.checkout.quote.detailUpdatedAt"),value:v?.timestamp_ms?Ge(v.timestamp_ms,I):"—"},{label:S("payment.checkout.quote.detailSlippage"),value:w?.mode==="rate"&&w.min_acceptable_rate?`$${re(w.min_acceptable_rate)||w.min_acceptable_rate}`:`${w?.percent??k}%`,isSlippage:!0}],isSubscription:!0,slippageValue:w?.percent??k,slippageConfig:w||void 0,onSlippageChange:z,exchangeRate:v?.rate,baseCurrency:"USD",disabled:R})]})]})]})}const ot=async(t,r)=>{const{data:i}=await N.get(`/api/auto-recharge-configs/customer/${t}`,{params:{currency_id:r}});return i},ct=async(t,r)=>{const{data:i}=await N.get("/api/customers/payer-token",{params:{currencyId:t,payerAddress:r}});return i},B={enabled:!1,threshold:"100",quantity:1,payment_method_id:"",recharge_currency_id:"",price_id:"",daily_max_amount:0,daily_max_attempts:0},lt=async t=>{const{data:r}=await N.post("/api/exchange-rates/validate",{currency:t});return r},dt=async t=>{let r;return await Ye(async()=>{const{data:i}=await N.get(`/api/auto-recharge-configs/retrieve/${t}`);return r=i,!!r.payment_settings?.payment_method_options?.[r.paymentMethod.type]?.payer},{interval:2e3,timeout:180*1e3}),r};function ut({config:t,onChangePaymentMethod:r,paymentMethod:i,currency:c}){const{t:o}=Q(),[b,s]=m.useState(!1),j=at(),d=t?.payment_settings?.payment_method_options?.[i.type||""],{data:A,loading:v}=H(async()=>i.type==="stripe"?null:await ct(c.id,d?.payer),{refreshDeps:[c.id,d?.payer],ready:!!c.id&&!!d?.payer}),w=()=>{const R=!b;s(R),r(R)};if(!d)return null;const k=R=>{const S=me(xe(),`/customer/recharge/${c.id}?rechargeAddress=${d?.payer}`),I=Ke(S,!0);et(R,I,j)},z=()=>i.type==="stripe"?e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(qe,{fontSize:"small",color:"primary"}),e.jsxs(f,{variant:"body2",children:["**** **** **** ",d?.card_last4||"****"]}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary",textTransform:"uppercase"},children:d?.card_brand||"CARD"}),d?.exp_time&&e.jsx(f,{variant:"body2",sx:{color:"text.secondary",borderLeft:"1px solid",borderColor:"divider",pl:1},children:d?.exp_time})]}):e.jsxs(u,{spacing:1,sx:{borderRadius:1,backgroundColor:R=>R.palette.mode==="dark"?"grey.100":"grey.50",p:2},children:[e.jsx(Le,{did:d?.payer,responsive:!1,compact:!0,copyable:!1}),(A||v)&&e.jsxs(u,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[v?e.jsx(de,{size:14,sx:{mr:.5}}):e.jsxs(P,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(ke,{fontSize:"small",sx:{color:"text.lighter"}}),e.jsxs(f,{variant:"body2",sx:{color:"text.primary"},children:[e.jsxs("strong",{children:[he(A?.token||"0",c?.decimal)," "]}),c?.symbol||""]})]}),e.jsxs(G,{size:"small",variant:"text",onClick:k,sx:{fontSize:"smaller",color:"primary.main"},children:[e.jsx(ue,{fontSize:"small"}),o("payment.autoTopup.addFunds")]})]})]});return e.jsx(P,{sx:{p:2,border:"1px solid",borderColor:b?"primary.main":"divider",borderRadius:1,bgcolor:b?"primary.50":"background.paper"},children:e.jsxs(u,{spacing:2,children:[e.jsxs(u,{sx:{flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(f,{variant:"subtitle2",sx:{display:"flex",alignItems:"center",gap:1,whiteSpace:"nowrap"},children:o("payment.autoTopup.currentPaymentMethod")}),e.jsx(G,{size:"small",startIcon:e.jsx(Ie,{}),onClick:w,variant:"text",sx:{color:"primary.main",whiteSpace:"nowrap",alignSelf:{xs:"flex-end",sm:"center"}},children:o(b?"payment.autoTopup.keepCurrent":"payment.autoTopup.changePaymentMethod")})]}),b?e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:o("payment.autoTopup.changePaymentMethodTip")}):z()]})})}function mt({open:t,onClose:r,currencyId:i,onSuccess:c=()=>{},onError:o=()=>{},defaultEnabled:b=void 0}){const{t:s,locale:j}=Q(),{session:d,connect:A,settings:v}=Ve(),[w,k]=m.useState(!1),[z,R]=m.useState(.5),[S,I]=m.useState(null),[p,x]=Ne({loading:!1,submitting:!1,authorizationRequired:!1,stripeContext:{client_secret:"",intent_type:"",status:"",public_key:"",customer:{}}}),a=He(v.paymentMethods),l=Qe({defaultValues:{enabled:b||B.enabled,threshold:B.threshold,quantity:B.quantity,payment_method_id:B.payment_method_id,recharge_currency_id:B.recharge_currency_id,price_id:B.price_id,daily_limits:{max_attempts:B.daily_max_attempts,max_amount:B.daily_max_amount}}}),{handleSubmit:y,setValue:_,watch:F}=l,L=F("enabled"),T=F("quantity"),C=F("recharge_currency_id"),D=v.paymentMethods.find(n=>n.payment_currencies.find(h=>h.id===C)),M=D?.type==="stripe",$=()=>{x({loading:!1,submitting:!1,authorizationRequired:!1}),r()},{data:g}=H(()=>ot(d?.user?.did,i),{refreshDeps:[d?.user?.did,i],ready:!!d?.user?.did&&!!i,onError:n=>{q.error(O(n))},onSuccess:n=>{_("enabled",b||n.enabled),_("threshold",n.threshold),_("quantity",n.quantity),_("payment_method_id",n.payment_method_id),_("recharge_currency_id",n.recharge_currency_id||n.price?.currency_id),_("price_id",n.price_id),_("daily_limits",{max_amount:n.daily_limits?.max_amount||0,max_attempts:n.daily_limits?.max_attempts||0}),n.slippage_config&&(I(n.slippage_config),R(n.slippage_config.percent??.5))}}),W=g?.price?.pricing_type==="dynamic",{data:V}=H(()=>lt(C),{refreshDeps:[C],ready:!!C&&W&&L&&!M,pollingInterval:3e4,pollingWhenHidden:!1,onError:n=>{console.warn("Failed to fetch exchange rate:",n.message)}}),E=m.useMemo(()=>a.filter(n=>g?.price?.currency_options?.find(h=>h.currency_id===n.id)),[a,g]),X=async()=>{try{await dt(g?.id)&&(x({submitting:!1,authorizationRequired:!1}),c?.(g),$(),q.success(s("payment.autoTopup.saveSuccess")))}catch(n){q.error(O(n))}finally{x({submitting:!1,authorizationRequired:!1})}},ge=async()=>{try{const n={...g,enabled:!1};if(!g?.enabled)return;const{data:h}=await N.post("/api/auto-recharge-configs/submit",n);c?.(h),q.success(s("payment.autoTopup.disableSuccess"))}catch(n){q.error(O(n)),o?.(n)}},fe=async n=>{_("enabled",n),n||await ge()},be=n=>{x({authorizationRequired:!0}),n.stripeContext?x({stripeContext:{client_secret:n.stripeContext.client_secret,intent_type:n.stripeContext.intent_type,status:n.stripeContext.status,public_key:n.paymentMethod.settings.stripe.publishable_key,customer:n.customer}}):n.delegation&&_e()},_e=()=>{try{x({submitting:!0}),A.open({containerEl:void 0,saveConnect:!1,locale:j,action:"auto-recharge-auth",prefix:me(xe(),"/api/did"),extraParams:{autoRechargeConfigId:g?.id},messages:{scan:s("payment.autoTopup.authTip"),title:s("payment.autoTopup.authTitle"),confirm:s("common.connect.confirm")},onSuccess:async()=>{A.close(),await X()},onClose:()=>{A.close(),x({submitting:!1,authorizationRequired:!1})},onError:n=>{x({submitting:!1,authorizationRequired:!1}),q.error(O(n))}})}catch(n){x({submitting:!1,authorizationRequired:!1}),q.error(O(n))}},je=async n=>{x({submitting:!0});try{const h={customer_id:d?.user?.did,enabled:n.enabled,threshold:n.threshold,currency_id:i,recharge_currency_id:n.recharge_currency_id,price_id:n.price_id,quantity:n.quantity,daily_limits:{max_attempts:n.daily_limits.max_attempts||0,max_amount:n.daily_limits.max_amount||"0"},change_payment_method:w};W&&S&&(h.slippage_config={...S,updated_at_ms:Date.now()});const{data:U}=await N.post("/api/auto-recharge-configs/submit",h);if(U.balanceResult&&!U.balanceResult.sufficient){await be({...U.balanceResult,paymentMethod:U.paymentMethod,customer:U.customer});return}x({submitting:!1,authorizationRequired:!1}),c?.(U),$(),q.success(s("payment.autoTopup.saveSuccess"))}catch(h){x({submitting:!1,authorizationRequired:!1}),q.error(O(h)),o?.(h)}},Y=n=>{je(n)},K=E.find(n=>n.id===C),ve=p.authorizationRequired&&M,Ce=async()=>{await X()},we=()=>{x({submitting:!1,authorizationRequired:!1})};return e.jsx(Fe,{open:t,onClose:$,maxWidth:"sm",fullWidth:!0,className:"base-dialog",title:s("payment.autoTopup.title"),actions:L?e.jsxs(u,{direction:"row",spacing:2,children:[e.jsx(G,{variant:"outlined",onClick:$,disabled:p.submitting,children:s("common.cancel")}),e.jsxs(G,{variant:"contained",onClick:()=>y(Y)(),disabled:p.loading||p.authorizationRequired||p.submitting,children:[p.submitting&&e.jsx(de,{size:20,sx:{mr:1}}),s("payment.autoTopup.saveConfiguration")]})]}):null,children:e.jsx(Ze,{...l,children:e.jsx(P,{component:"form",onSubmit:y(Y),children:e.jsxs(u,{sx:{gap:2},children:[e.jsx(Se,{severity:"info",children:s("payment.autoTopup.tip")}),e.jsxs(u,{spacing:2,direction:"row",sx:{alignItems:"center"},children:[e.jsx(f,{variant:"subtitle1",children:s("payment.autoTopup.enableLabel")}),e.jsx(Te,{control:e.jsx(Je,{checked:L,onChange:n=>fe(n.target.checked)}),label:""})]}),L&&e.jsxs(e.Fragment,{children:[e.jsx(P,{sx:{pt:1},children:e.jsxs(u,{spacing:2.5,children:[e.jsxs(u,{sx:{gap:2,flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"},".MuiTextField-root":{width:{xs:"100%",sm:"auto"}}},children:[e.jsx(se,{boxSx:{width:"fit-content",whiteSpace:"nowrap",marginBottom:0},children:s("payment.autoTopup.triggerThreshold")}),e.jsx(ie,{name:"threshold",control:l.control,rules:{required:s("payment.checkout.required"),min:{value:0,message:s("payment.autoTopup.thresholdMinError")}},render:({field:n})=>e.jsx(le,{...n,type:"number",placeholder:s("payment.autoTopup.thresholdPlaceholder"),sx:{input:{minWidth:80}},slotProps:{input:{endAdornment:e.jsx(ee,{position:"end",children:pe("",g?.currency?.symbol)})},htmlInput:{min:0,step:.01}}})})]}),e.jsxs(u,{sx:{gap:2,flexDirection:{xs:"column",sm:"row"},alignItems:{xs:"flex-start",sm:"center"},justifyContent:{xs:"flex-start",sm:"space-between"}},children:[e.jsx(se,{boxSx:{width:"fit-content",whiteSpace:"nowrap",marginBottom:0},children:s("payment.autoTopup.purchaseBelow")}),e.jsx(ie,{name:"recharge_currency_id",control:l.control,render:({field:n})=>e.jsx(Ae,{...n,value:n.value,onChange:h=>n.onChange(h.target.value),size:"small",children:E.map(h=>e.jsx(Re,{value:h?.id,children:e.jsxs(u,{direction:"row",sx:{alignItems:"center",gap:1},children:[e.jsx(Pe,{src:h?.logo,sx:{width:20,height:20},alt:h?.symbol}),e.jsxs(f,{sx:{color:"text.secondary"},children:[h?.symbol," (",h?.method?.name,")"]})]})},h?.id))})})]}),g?.price?.product&&e.jsx(it,{product:g.price.product,price:g.price,creditCurrency:g.currency,currency:E.find(n=>n.id===C)||E[0],quantity:T,onQuantityChange:n=>_("quantity",n),maxQuantity:9999,minQuantity:1,exchangeRate:V?.rate,isDynamicPricing:W&&!M,exchangeRateData:V,slippageConfig:S,slippagePercent:z,onSlippageChange:n=>{I(n),n.percent!==void 0&&R(n.percent)},disabled:p.submitting}),g&&K&&e.jsx(ut,{config:g,onChangePaymentMethod:k,currency:K,paymentMethod:D}),e.jsx(st,{trigger:s("payment.autoTopup.advanced"),children:e.jsxs(u,{sx:{gap:2,pl:2,pr:1},children:[e.jsx(oe,{name:"daily_limits.max_amount",label:s("payment.autoTopup.dailyLimits.maxAmount"),type:"number",placeholder:s("payment.autoTopup.dailyLimits.maxAmountPlaceholder"),tooltip:s("payment.autoTopup.dailyLimits.maxAmountDescription"),inputProps:{min:0,step:.01},slotProps:{input:{endAdornment:e.jsx(ee,{position:"end",children:E.find(n=>n.id===C)?.symbol||""})}},sx:{maxWidth:{xs:"100%",sm:"220px"}},layout:"horizontal"}),e.jsx(oe,{name:"daily_limits.max_attempts",label:s("payment.autoTopup.dailyLimits.maxAttempts"),type:"number",placeholder:s("payment.autoTopup.dailyLimits.maxAttemptsPlaceholder"),tooltip:s("payment.autoTopup.dailyLimits.maxAttemptsDescription"),inputProps:{min:0,step:1},sx:{maxWidth:{xs:"100%",sm:"220px"}},layout:"horizontal"})]})})]})}),e.jsx(u,{spacing:2,children:ve&&e.jsx(P,{sx:{mt:2},children:p.stripeContext&&e.jsx(P,{sx:{mt:2},children:e.jsx(Xe,{clientSecret:p.stripeContext.client_secret,intentType:p.stripeContext.intent_type,publicKey:p.stripeContext.public_key,customer:p.stripeContext.customer,mode:"setup",onConfirm:Ce,onCancel:we})})})})]})]})})})})}function pt(t){if(!t)return"Unknown error";if(t?.name==="ZodError")return Array.isArray(t.errors)?t.errors.map(r=>r.message).join(`
|
|
2
2
|
`):"Validation failed";if(Array.isArray(t?.details))return`Validate failed: ${t.details.map(i=>{const c=i.message.replace(/["]/g,"'");return`${i.path.join(".")}: ${c}`}).join(";")}`;if(Array.isArray(t?.errors))return t.errors.map(r=>r.msg||r.message).join(`
|
|
3
3
|
`);if(Array.isArray(t?.constraints))return Object.values(t.constraints).join(`
|
|
4
4
|
`);if(t?.keyword==="validation")return t.message||"Validation error";if(Array.isArray(t?.errors))return t.errors.map(r=>r.message).join(`
|
|
5
|
-
`);if(t instanceof TypeError&&t.message.includes("fetch"))return"Network error: Failed to fetch";if(t?.name==="FetchError")return t.message||"Fetch error occurred";if(t?.isAxiosError){if(t.response?.data){if(t.response.data.message)return t.response.data.message;if(t.response.data.error)return t.response.data.error;const r=typeof t.response.data=="string"?t.response.data.slice(0,200):JSON.stringify(t.response.data);return`Request failed: ${t.response.status} ${t.response.statusText}: ${r}`}return t.message||"Request failed"}if(t?.response){if(t.response.error)return t.response.error;if(t.response.data?.message)return t.response.data.message;if(t.response.data?.error)return t.response.data.error;const r=typeof t.response.data=="string"?t.response.data.slice(0,200):JSON.stringify(t.response.data);return`Request failed: ${t.response.status} ${t.response.statusText}: ${r}`}return t.message||String(t)}const ye=m.createContext(null),ht=()=>m.useContext(ye);function jt({skeleton:t,children:r,skeletonComponent:i=null,onStateChange:c=()=>{}}){const[o,b]=m.useState("hidden"),s=m.useRef(null);m.useEffect(()=>{c(o)},[o]);const j=m.useCallback((A=!0)=>{s.current&&(clearTimeout(s.current),s.current=null),b(A?"none":"visible")},[]),d=m.useMemo(()=>({hideRender:j}),[j]);return m.useEffect(()=>(t||(s.current=setTimeout(()=>{b("visible"),s.current=null},3e3)),()=>{s.current&&(clearTimeout(s.current),s.current=null)}),[t]),t?i:o==="none"?null:e.jsx(ye.Provider,{value:d,children:e.jsx(P,{sx:{position:o==="hidden"?"absolute":"static",left:o==="hidden"?"-9999px":"auto",top:o==="hidden"?"-9999px":"auto",visibility:o==="hidden"?"hidden":"visible",width:o==="hidden"?"0":"auto",height:o==="hidden"?"0":"auto",overflow:"hidden"},children:r})})}var
|
|
5
|
+
`);if(t instanceof TypeError&&t.message.includes("fetch"))return"Network error: Failed to fetch";if(t?.name==="FetchError")return t.message||"Fetch error occurred";if(t?.isAxiosError){if(t.response?.data){if(t.response.data.message)return t.response.data.message;if(t.response.data.error)return t.response.data.error;const r=typeof t.response.data=="string"?t.response.data.slice(0,200):JSON.stringify(t.response.data);return`Request failed: ${t.response.status} ${t.response.statusText}: ${r}`}return t.message||"Request failed"}if(t?.response){if(t.response.error)return t.response.error;if(t.response.data?.message)return t.response.data.message;if(t.response.data?.error)return t.response.data.error;const r=typeof t.response.data=="string"?t.response.data.slice(0,200):JSON.stringify(t.response.data);return`Request failed: ${t.response.status} ${t.response.statusText}: ${r}`}return t.message||String(t)}const ye=m.createContext(null),ht=()=>m.useContext(ye);function jt({skeleton:t,children:r,skeletonComponent:i=null,onStateChange:c=()=>{}}){const[o,b]=m.useState("hidden"),s=m.useRef(null);m.useEffect(()=>{c(o)},[o]);const j=m.useCallback((A=!0)=>{s.current&&(clearTimeout(s.current),s.current=null),b(A?"none":"visible")},[]),d=m.useMemo(()=>({hideRender:j}),[j]);return m.useEffect(()=>(t||(s.current=setTimeout(()=>{b("visible"),s.current=null},3e3)),()=>{s.current&&(clearTimeout(s.current),s.current=null)}),[t]),t?i:o==="none"?null:e.jsx(ye.Provider,{value:d,children:e.jsx(P,{sx:{position:o==="hidden"?"absolute":"static",left:o==="hidden"?"-9999px":"auto",top:o==="hidden"?"-9999px":"auto",visibility:o==="hidden"?"hidden":"visible",width:o==="hidden"?"0":"auto",height:o==="hidden"?"0":"auto",overflow:"hidden"},children:r})})}var J=(t=>(t.OVERVIEW="overview",t.GRANTS="grants",t.TRANSACTIONS="transactions",t))(J||{});const xt=async t=>{try{const[r,i]=await Promise.all([N.get(`/api/credit-grants/summary?customer_id=${t}`),N.get(`/api/meter-events/pending-amount?customer_id=${t}`)]);return{grants:r.data,pendingAmount:i.data}}catch(r){return console.error("Failed to fetch credit summary:",r),{grants:null,transactions:null,pendingAmount:null}}};function vt({customerId:t,settings:r,mode:i="portal"}){const{t:c}=Q(),[o,b]=rt(),s=()=>{const a=o.get("creditTab");return a&&Object.values(J).includes(a)?a:"overview"},[j,d]=m.useState(s),A=ht(),[v,w]=m.useState({currencyId:"",open:!1});m.useEffect(()=>{const a=o.get("creditTab");a&&Object.values(J).includes(a)&&d(a)},[o]),m.useEffect(()=>{const a=o.get("action"),l=o.get("currencyId");if(a==="auto-recharge"&&l){w({currencyId:l,open:!0});const y=new URLSearchParams(o);y.delete("action"),y.delete("currencyId"),b(y,{replace:!0})}},[o,b]);const k=m.useMemo(()=>r?.paymentMethods?.filter(a=>a.type==="arcblock")?.flatMap(a=>a.payment_currencies)?.filter(a=>a.type==="credit")||[],[r]),{data:z}=H(xt,{defaultParams:[t],refreshDeps:[j==="overview"],onSuccess:a=>{const l=k.filter(y=>a.grants?.[y.id]);A?.hideRender(l.length===0)}}),R=async a=>{try{const l=await N.get(`/api/payment-currencies/${a.id}/recharge-config`).then(y=>y.data);if(l.recharge_config&&l.recharge_config.payment_url){const y=new URL(l.recharge_config.payment_url);y.searchParams.set("redirect",window.location.href),window.open(y.toString(),"_self")}else q.error(c("customer.recharge.unsupported"))}catch(l){console.error("Failed to fetch recharge config:",l),q.error(pt(l))}},S=a=>{w({currencyId:a.id,open:!0})},I=a=>{d(a);const l=new URLSearchParams(o);a==="overview"?l.delete("creditTab"):l.set("creditTab",a),b(l)},p=a=>{if(r?.paymentMethods?.find(M=>M.id===a.payment_method_id)?.type!=="arcblock")return null;const y=a.id,_=z?.grants?.[y],F=z?.pendingAmount?.[y]||"0";if(!_||_.meter?.status==="inactive")return null;const L=_.paymentCurrency.recharge_config?.base_price_id&&i==="portal",T=_.totalAmount||"0",C=_.remainingAmount||"0",D=_.meter?.name||a.name;return e.jsx(ce,{sx:{height:"100%",display:"flex",flexDirection:"column",border:"1px solid",borderColor:"divider",boxShadow:1,borderRadius:1,backgroundColor:"background.default"},children:e.jsx(Me,{sx:{flexGrow:1},children:e.jsxs(u,{spacing:2,children:[e.jsxs(u,{direction:"row",spacing:.5,sx:{alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider",pb:2},children:[e.jsx(f,{variant:"h6",component:"div",children:D}),L&&e.jsx(te,{variant:"outlined",size:"small",color:"primary",menu:[e.jsxs(te.Item,{onClick:()=>S(a),sx:{color:"primary.main"},children:[e.jsx($e,{fontSize:"small",sx:{mr:.5}}),e.jsx(f,{variant:"body2",className:"recharge-title",children:c("customer.credit.autoRecharge")})]},"autoRecharge")],children:e.jsxs(G,{variant:"text",color:"primary",size:"small",onClick:()=>R(a),children:[e.jsx(ue,{fontSize:"small"}),e.jsx(f,{variant:"body2",className:"recharge-title",children:c("customer.credit.recharge")})]})})]}),(()=>{const M=new ne(C),$=new ne(F),g=M.sub($),W=g.isNeg(),V=W?g.abs().toString():g.toString(),E=T==="0"&&C==="0"&&F==="0"?"0":pe(he(V,a.decimal),a.symbol,!1);return e.jsxs(P,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(f,{variant:"body2",gutterBottom:!0,sx:{color:"text.secondary"},children:c("admin.customer.creditGrants.creditBalance")}),e.jsx(f,{variant:"h5",component:"div",sx:{fontWeight:"normal",color:W?"error.main":"text.primary"},children:W?`-${E}`:E})]})})()]})})},a.id)},x=m.useMemo(()=>k.filter(a=>!!z?.grants?.[a.id]),[k,z?.grants]);return e.jsxs(u,{sx:{width:"100%"},children:[e.jsxs(ze,{value:j,onChange:(a,l)=>I(l),sx:{flex:"1 0 auto",maxWidth:"100%",fontSize:14,borderBottom:1,borderColor:"divider",".Mui-selected":{fontSize:"14px !important",color:"primary.main"}},children:[e.jsx(Z,{label:c("admin.creditGrants.overview"),value:"overview"}),e.jsx(Z,{label:c("admin.creditGrants.tab"),value:"grants"}),e.jsx(Z,{label:c("admin.creditTransactions.tab"),value:"transactions"})]}),e.jsxs(P,{className:"section-body",children:[j==="overview"&&e.jsxs(P,{sx:{width:"100%",mt:1},children:[e.jsx(P,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",md:"repeat(2, 1fr)"},gap:2,"@container (max-width: 600px)":{gridTemplateColumns:"repeat(1, 1fr)"}},children:x.map(p)}),x.length===0&&e.jsxs(P,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,textAlign:"center"},children:[e.jsx(f,{variant:"h6",gutterBottom:!0,sx:{color:"text.secondary"},children:c("admin.customer.creditGrants.noGrants")}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:c("admin.customer.creditGrants.noGrantsDescription")})]})]},j),j==="grants"&&e.jsx(tt,{customer_id:t,mode:i},j),j==="transactions"&&e.jsx(nt,{customer_id:t,mode:i,includeGrants:!0},j)]}),v.open&&e.jsx(mt,{open:!0,onClose:()=>w({currencyId:"",open:!1}),currencyId:v.currencyId})]})}export{jt as C,vt as a,ht as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as F,j as e,B as v,q as f,a3 as q,x as Y,w as ne,aN as ie,aM as G,a7 as K,bf as O}from"./vendor-mui-BXZut9Pz.js";import{V as I,G as $,$ as re,Y as B,X as ce,O as ae}from"./vendor-blocklet-D_i_QeSo.js";import{a as se,h as ue,Y as N,F as me,e as k,b8 as W,k as V,I as X,T as J,v as Q,j as A}from"./index-DgSc1Qy8.js";import{D as Z,P as de}from"./index-Clbt8nRm.js";import{A as le}from"./actions-jxGAdGfb.js";import{L as ee}from"./link-DMWJcQvZ.js";import{C as oe}from"./link-3eeclTeS.js";import{S as pe}from"./description-Ym17DL48.js";import{S as fe}from"./status-l6pD08fw.js";import{a as _e}from"./vendor-react-BPknnnEA.js";function Ae({open:o,onClose:h,onSubmit:S=()=>{},couponId:t,promotionCode:s=null,isEditing:a=!1,availableCurrencies:p=[]}){const{t:m}=I(),{settings:c}=se(),w=ue({mode:"onChange",defaultValues:Z}),{handleSubmit:L,reset:C,formState:{isSubmitting:P}}=w;F.useEffect(()=>{if(o)if(a&&s){const n={},_=s.restrictions?.minimum_amount_currency?N(c.paymentMethods,s.restrictions.minimum_amount_currency):null,x=s.restrictions?.minimum_amount?parseFloat($(s.restrictions.minimum_amount,_?.decimal||0)):void 0;let M=!1;if(s.restrictions?.currency_options){const H=Object.entries(s.restrictions.currency_options);M=H.length>0,H.forEach(([U,T])=>{const E=N(c.paymentMethods,U);let g=0;if(T&&typeof T=="object"&&"minimum_amount"in T){const u=T.minimum_amount;E&&u?g=parseFloat($(u||"0",E.decimal)):g=u||0}n[U]={minimum_amount:g}})}C({code:s.code||"",active:s.active??!0,max_redemptions:s.max_redemptions||void 0,description:s.description||"",expires_at:s.expires_at?new Date(s.expires_at*1e3).toISOString().slice(0,16):"",verification_type:s.verification_type||"code",limit_number_redemptions:!!s.max_redemptions,add_expiration_date:!!s.expires_at,restrictions:{first_time_transaction:s.restrictions?.first_time_transaction||!1,require_minimum_amount:M,minimum_amount:x,minimum_amount_currency:_?.id,currency_options:n},customer_dids:s.customer_dids||[],nft_addresses:s.nft_config?.addresses||[],nft_tags:s.nft_config?.tags||[],trusted_issuers:s.nft_config?.trusted_issuers||[],trusted_parents:s.nft_config?.trusted_parents||[],min_balance:s.nft_config?.min_balance||1,vc_roles:s.vc_config?.roles||[],vc_trusted_issuers:s.vc_config?.trusted_issuers||[]})}else C(Z)},[o,a,s,C,c.paymentMethods]);const b=async n=>{try{const _={active:n.active,verification_type:n.verification_type,restrictions:n.restrictions,description:n.description,metadata:{}};a||(_.coupon_id=t),n.code&&n.code.trim()&&(_.code=n.code),n.limit_number_redemptions&&n.max_redemptions&&(_.max_redemptions=n.max_redemptions),n.expires_at&&(_.expires_at=Math.floor(new Date(n.expires_at).getTime()/1e3)),n.verification_type==="nft"?_.nft_config={addresses:n.nft_addresses?.filter(x=>x.trim())||[],tags:n.nft_tags?.filter(x=>x.trim())||[],trusted_issuers:n.trusted_issuers?.filter(x=>x.trim())||[],trusted_parents:n.trusted_parents?.filter(x=>x.trim())||[],min_balance:n.min_balance||1}:n.verification_type==="vc"?_.vc_config={roles:n.vc_roles?.filter(x=>x.trim())||[],trusted_issuers:n.vc_trusted_issuers?.filter(x=>x.trim())||[]}:n.verification_type==="user_restricted"&&(_.customer_dids=n.customer_dids?.filter(x=>x.trim())||[]),a&&s?(await k.put(`/api/promotion-codes/${s.id}`,_),B.success(m("common.saved")),W("promotion-code.updated")):(await k.post("/api/promotion-codes",_),B.success(m("admin.coupon.saved")),W("promotion-code.created")),S&&S(),h()}catch(_){console.error(_),B.error(V(_))}},D=()=>{C(),h()},d=m(a?"admin.promotionCode.edit":"admin.coupon.createPromotionCode");return e.jsx(re,{open:o,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:D,showCloseButton:!1,title:d,actions:e.jsxs(q,{direction:"row",children:[e.jsx(Y,{size:"small",sx:{mr:2},onClick:D,disabled:P,children:m("common.cancel")}),e.jsxs(Y,{variant:"contained",color:"primary",size:"small",disabled:P,onClick:L(b),children:[P&&e.jsx(ne,{size:16,sx:{mr:1}}),m(a?"common.save":"admin.coupon.createPromotionCode")]})]}),children:e.jsx(me,{...w,children:e.jsxs(v,{sx:{display:"flex",flexDirection:"column",gap:3},children:[e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:m("admin.coupon.promotionCodeDescription")}),e.jsx(de,{showCodeInput:!0,showExpandedOptions:!0,availableCurrencies:p})]})})})}function $e({data:o,onChange:h,variant:S="compact"}){const{t}=I(),s=!o.locked&&o.active,a=!o.locked,p=o.active,[m,c]=ce({action:"",loading:!1}),w=async()=>{try{c({loading:!0}),await k.put(`/api/promotion-codes/${o.id}/archive`).then(b=>b.data),B.success(t("common.saved")),W("promotion-code.updated"),h(m.action)}catch(b){console.error(b),B.error(V(b))}finally{c({loading:!1,action:""})}},L=async()=>{try{c({loading:!0}),await k.delete(`/api/promotion-codes/${o.id}`).then(b=>b.data),B.success(t("common.removed")),W("promotion-code.deleted"),h(m.action)}catch(b){console.error(b),B.error(V(b))}finally{c({loading:!1,action:""})}},C=()=>{c({action:"edit"}),h("edit",o)},P=[{label:t("admin.promotionCode.edit"),handler:C,color:s?"text.primary":"text.disabled",disabled:!s},{label:t("admin.promotionCode.archive"),handler:()=>c({action:"archive"}),color:p?"text.primary":"text.disabled",disabled:!p},{label:t("admin.promotionCode.delete"),handler:()=>c({action:"delete"}),color:a?"error.main":"text.disabled",disabled:!a}];return e.jsxs(e.Fragment,{children:[e.jsx(le,{variant:S,actions:P}),m.action==="archive"&&e.jsx(X,{onConfirm:w,onCancel:()=>c({action:""}),title:t("admin.promotionCode.archive"),message:t("admin.promotionCode.archiveTip")}),m.action==="delete"&&e.jsx(X,{onConfirm:L,onCancel:()=>c({action:""}),title:t("admin.promotionCode.delete"),message:t("admin.promotionCode.deleteTip")})]})}function xe(o){if((!o.couponId||o.couponId==="")&&(!o.promotionCodeId||o.promotionCodeId===""))throw new Error("Either couponId or promotionCodeId must be provided")}const be=(o,h,S,t="coupon")=>{const s=new URLSearchParams({page:h.page.toString(),pageSize:h.pageSize.toString()});s.append("type",S);const a=t==="coupon"?`/api/coupons/${o}/redemptions`:`/api/promotion-codes/${o}/redemptions`;return k.get(`${a}?${s}`).then(p=>p.data)};function ke({couponId:o="",promotionCodeId:h=""}){xe({couponId:o,promotionCodeId:h});const{t}=I(),s=_e(),[a,p]=F.useState(0),[m,c]=F.useState({page:0,pageSize:10}),[w,L]=F.useState({page:0,pageSize:10}),C=o&&o!==""?o:h,P=o&&o!==""?"coupon":"promotion-code",b=a===0?m:w,D=a===0?"customer":"subscription",{data:d={customers:[],subscriptions:[],count:0},loading:n}=ae(()=>be(C,{page:b.page+1,pageSize:b.pageSize},D,P),{refreshDeps:[C,b.page,b.pageSize,a]}),_=(g,u)=>{p(u),u===0?c({page:0,pageSize:10}):L({page:0,pageSize:10})},x=({page:g,rowsPerPage:u})=>{c({page:g,pageSize:u})},M=({page:g,rowsPerPage:u})=>{L({page:g,pageSize:u})},U=(()=>{const g=[{label:t("common.name"),name:"name",options:{customBodyRenderLite:(u,r)=>{const l=d.customers?.[r];return e.jsx(oe,{customer:l,size:"small"})}}},{label:t("common.email"),name:"email",options:{customBodyRenderLite:(u,r)=>d.customers?.[r]?.email||"—"}},{label:t("admin.coupon.usageStats"),name:"usage_stats",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats;return i?e.jsx(f,{variant:"body2",children:i.total_discount_records}):"—"}}}];return P==="coupon"&&g.push({label:t("admin.coupon.promotionCodesUsed"),name:"promotion_codes",options:{customBodyRenderLite:(u,r)=>{const l=d.customers?.[r],i=l?.coupon_usage_stats?.promotion_codes_used||[],z=l?.discount_records||[];if(i.length===0)return"—";const R=new Map;return z.forEach(y=>{if(y.promotion_code){const j=y.promotion_code.id||y.promotion_code.code;R.set(j,(R.get(j)||0)+1)}}),e.jsx(v,{sx:{display:"flex",flexWrap:"wrap",gap:.5,maxWidth:"200px"},children:i.map(y=>{const j=R.get(y.id||y.code)||0;return e.jsx(K,{label:`${y.code} (${j})`,size:"small",variant:"outlined",onClick:()=>s(`/admin/products/promotion-codes/${y.id}`),sx:{cursor:"pointer","&:hover":{backgroundColor:"action.hover"}}},`${y.id||y.code}`)})})}}}),g.push({label:t("admin.coupon.totalSavings"),name:"total_savings",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats?.total_savings||{};return Object.keys(i).length===0?e.jsx(f,{variant:"body2",children:"—"}):e.jsx(v,{children:Object.entries(i).map(([z,R],y)=>{if(!R)return null;const j=R;return e.jsxs(f,{variant:"body2",sx:{display:"inline-flex"},children:[y>0&&"、",Q(j.amount,j.currency?.decimal||18)," ",j.currency?.symbol||""]},z)})})}}},{label:t("admin.coupon.usagePeriod"),name:"usage_period",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats;return i?e.jsxs(v,{children:[e.jsxs(f,{variant:"body2",children:[t("admin.coupon.firstUsed"),": ",A(i.first_used)]}),i.first_used!==i.last_used&&e.jsxs(f,{variant:"body2",sx:{color:"text.secondary"},children:[t("admin.coupon.lastUsed"),": ",A(i.last_used)]})]}):"—"}}}),g})(),E=(()=>{const g=[{label:t("admin.subscription.product"),name:"id",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return e.jsx(ee,{to:`/admin/billing/${l.id}`,children:e.jsx(pe,{subscription:l})})}}},{label:t("common.status"),name:"status",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return e.jsx(ee,{to:`/admin/billing/${l.id}`,children:e.jsx(fe,{subscription:l})})}}},{label:t("common.customer"),name:"customer_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.customer;return e.jsx(oe,{customer:i,size:"small"})}}}];return P==="coupon"&&g.push({label:t("admin.coupon.promotionCodesUsed"),name:"promotion_code_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info?.promotion_code;return i?e.jsx(v,{children:e.jsx(K,{label:i.code,size:"small",variant:"outlined",onClick:()=>s(`/admin/products/promotion-codes/${i.id}`),sx:{cursor:"pointer",mb:.5,"&:hover":{backgroundColor:"action.hover"}}})}):e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.directCouponUsage")})}}}),g.push({label:t("admin.coupon.totalSavings"),name:"total_savings",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info?.total_savings||{};return Object.keys(i).length===0?e.jsx(f,{variant:"body2",sx:{color:"text.lighter"},children:"—"}):e.jsx(v,{children:Object.entries(i).map(([z,R],y)=>{if(!R)return null;const j=R;return e.jsxs(f,{variant:"body2",sx:{lineHeight:1.2},children:[y>0&&", ",Q(j.amount,j.currency?.decimal||18)," ",j.currency?.symbol||""]},z)})})}}},{label:t("admin.coupon.discountInfo"),name:"discount_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info;if(!i)return e.jsx(f,{variant:"body2",children:"—"});const z=i.coupon_info;return e.jsxs(v,{children:[e.jsxs(f,{variant:"body2",children:[t("admin.coupon.discountPeriod"),": ",A(i.discount_start*1e3),i.discount_end&&` - ${A(i.discount_end*1e3)}`]}),e.jsxs(f,{variant:"caption",sx:{color:"text.secondary"},children:[t("admin.coupon.duration"),":"," ",t(`admin.coupon.couponTermsDuration.${z.duration}`,{months:z.duration_in_months})]})]})}}},{label:t("common.created"),name:"created_at",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return A(l?.created_at)}}}),g})();return e.jsxs(v,{children:[e.jsxs(ie,{value:a,onChange:_,sx:{flex:"1 0 auto",maxWidth:"100%",fontSize:14,borderBottom:1,borderColor:"divider",".Mui-selected":{fontSize:"14px !important",color:"primary.main"}},children:[e.jsx(G,{label:t("admin.coupon.customers")}),e.jsx(G,{label:t("admin.coupon.subscriptions")})]}),a===0&&e.jsx(v,{sx:{mt:2},children:d.customers?.length>0?e.jsx(J,{data:d.customers,columns:U,loading:n,toolbar:!1,options:{selectableRows:"none",serverSide:!0,count:d.count||0,page:m.page,rowsPerPage:m.pageSize,rowsPerPageOptions:[5,10,25,50]},onChange:x}):!n&&e.jsxs(v,{sx:{textAlign:"center",py:4},children:[e.jsx(f,{variant:"h6",sx:{color:"text.secondary"},children:t("admin.coupon.noCustomersFound")}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.noCustomersRedeem")})]})}),a===1&&e.jsx(v,{children:d.subscriptions?.length>0?e.jsx(J,{data:d.subscriptions,columns:E,loading:n,options:{selectableRows:"none",serverSide:!0,count:d.count||0,page:w.page,rowsPerPage:w.pageSize,rowsPerPageOptions:[5,10,25,50]},onChange:M}):!n&&e.jsxs(v,{sx:{textAlign:"center",py:4},children:[e.jsx(f,{variant:"h6",sx:{color:"text.secondary"},children:t("admin.coupon.noSubscriptionsFound")}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.noSubscriptionsRedeem")})]})})]})}const ge=O(q)(({theme:o})=>({flexDirection:"row",justifyContent:"space-between",alignItems:"center",padding:o.spacing(1.5,2),backgroundColor:o.palette.grey[50],borderRadius:o.shape.borderRadius,marginBottom:o.spacing(1),"&:last-child":{marginBottom:0}})),he=O(f)(({theme:o})=>({fontWeight:500,color:o.palette.text.primary,textTransform:"uppercase",fontSize:"0.875rem"})),ye=O(f)(({theme:o})=>({color:o.palette.text.secondary,fontSize:"0.875rem",fontFamily:"monospace"})),ve=O(q)(({theme:o})=>({flexDirection:"row",justifyContent:"space-between",alignItems:"center",padding:o.spacing(1,2),marginBottom:o.spacing(1),borderBottom:`1px solid ${o.palette.divider}`})),te=O(f)(({theme:o})=>({fontWeight:600,color:o.palette.text.primary,fontSize:"0.75rem",letterSpacing:"0.5px"}));function Oe({currencyOptions:o,type:h="coupon"}){const{t:S}=I(),{settings:t}=se();if(!o||Object.keys(o).length===0)return null;const s=Object.entries(o);return e.jsxs(v,{children:[e.jsxs(ve,{children:[e.jsx(te,{children:S("admin.coupon.currency")}),e.jsx(te,{children:S(h==="coupon"?"admin.coupon.discountAmount":"admin.coupon.minimumAmount")})]}),e.jsx(q,{children:s.map(([a,p])=>{const m=N(t.paymentMethods,a)||{symbol:a.toUpperCase(),name:a.toUpperCase(),decimal:18};let c;return typeof p=="string"?c=$(p,m.decimal):typeof p=="number"?c=p.toLocaleString():typeof p=="object"&&p!==null?"minimum_amount"in p?c=$(p.minimum_amount,m.decimal):"amount_off"in p?c=$(p.amount_off,m.decimal):c="0":c="0",e.jsxs(ge,{children:[e.jsx(he,{children:m.symbol}),e.jsx(ye,{children:c})]},a)})})]})}export{ke as A,Oe as C,$e as P,Ae as a};
|
|
1
|
+
import{r as F,j as e,B as v,q as f,a3 as q,x as Y,w as ne,aN as ie,aM as K,a7 as Z,bf as O}from"./vendor-mui-BXZut9Pz.js";import{V as H,H as $,$ as re,Z as B,Y as ce,P as ae}from"./vendor-blocklet-DcLR2Cyf.js";import{a as se,h as ue,Y as N,F as me,e as k,b8 as W,k as V,I as G,T as J,v as Q,j as A}from"./index-BarN7DfU.js";import{D as X,P as de}from"./index-DoX0A-rP.js";import{A as le}from"./actions-BJDN6Op2.js";import{L as ee}from"./link-DMWJcQvZ.js";import{C as oe}from"./link-CmPoIweR.js";import{S as pe}from"./description-SnR5WxWT.js";import{S as fe}from"./status-CUVYrUIG.js";import{a as _e}from"./vendor-react-BPknnnEA.js";function Ae({open:o,onClose:h,onSubmit:S=()=>{},couponId:t,promotionCode:s=null,isEditing:a=!1,availableCurrencies:p=[]}){const{t:m}=H(),{settings:c}=se(),w=ue({mode:"onChange",defaultValues:X}),{handleSubmit:L,reset:C,formState:{isSubmitting:P}}=w;F.useEffect(()=>{if(o)if(a&&s){const n={},_=s.restrictions?.minimum_amount_currency?N(c.paymentMethods,s.restrictions.minimum_amount_currency):null,x=s.restrictions?.minimum_amount?parseFloat($(s.restrictions.minimum_amount,_?.decimal||0)):void 0;let M=!1;if(s.restrictions?.currency_options){const I=Object.entries(s.restrictions.currency_options);M=I.length>0,I.forEach(([U,T])=>{const E=N(c.paymentMethods,U);let g=0;if(T&&typeof T=="object"&&"minimum_amount"in T){const u=T.minimum_amount;E&&u?g=parseFloat($(u||"0",E.decimal)):g=u||0}n[U]={minimum_amount:g}})}C({code:s.code||"",active:s.active??!0,max_redemptions:s.max_redemptions||void 0,description:s.description||"",expires_at:s.expires_at?new Date(s.expires_at*1e3).toISOString().slice(0,16):"",verification_type:s.verification_type||"code",limit_number_redemptions:!!s.max_redemptions,add_expiration_date:!!s.expires_at,restrictions:{first_time_transaction:s.restrictions?.first_time_transaction||!1,require_minimum_amount:M,minimum_amount:x,minimum_amount_currency:_?.id,currency_options:n},customer_dids:s.customer_dids||[],nft_addresses:s.nft_config?.addresses||[],nft_tags:s.nft_config?.tags||[],trusted_issuers:s.nft_config?.trusted_issuers||[],trusted_parents:s.nft_config?.trusted_parents||[],min_balance:s.nft_config?.min_balance||1,vc_roles:s.vc_config?.roles||[],vc_trusted_issuers:s.vc_config?.trusted_issuers||[]})}else C(X)},[o,a,s,C,c.paymentMethods]);const b=async n=>{try{const _={active:n.active,verification_type:n.verification_type,restrictions:n.restrictions,description:n.description,metadata:{}};a||(_.coupon_id=t),n.code&&n.code.trim()&&(_.code=n.code),n.limit_number_redemptions&&n.max_redemptions&&(_.max_redemptions=n.max_redemptions),n.expires_at&&(_.expires_at=Math.floor(new Date(n.expires_at).getTime()/1e3)),n.verification_type==="nft"?_.nft_config={addresses:n.nft_addresses?.filter(x=>x.trim())||[],tags:n.nft_tags?.filter(x=>x.trim())||[],trusted_issuers:n.trusted_issuers?.filter(x=>x.trim())||[],trusted_parents:n.trusted_parents?.filter(x=>x.trim())||[],min_balance:n.min_balance||1}:n.verification_type==="vc"?_.vc_config={roles:n.vc_roles?.filter(x=>x.trim())||[],trusted_issuers:n.vc_trusted_issuers?.filter(x=>x.trim())||[]}:n.verification_type==="user_restricted"&&(_.customer_dids=n.customer_dids?.filter(x=>x.trim())||[]),a&&s?(await k.put(`/api/promotion-codes/${s.id}`,_),B.success(m("common.saved")),W("promotion-code.updated")):(await k.post("/api/promotion-codes",_),B.success(m("admin.coupon.saved")),W("promotion-code.created")),S&&S(),h()}catch(_){console.error(_),B.error(V(_))}},D=()=>{C(),h()},d=m(a?"admin.promotionCode.edit":"admin.coupon.createPromotionCode");return e.jsx(re,{open:o,disableEscapeKeyDown:!0,fullWidth:!0,maxWidth:"sm",className:"base-dialog",onClose:D,showCloseButton:!1,title:d,actions:e.jsxs(q,{direction:"row",children:[e.jsx(Y,{size:"small",sx:{mr:2},onClick:D,disabled:P,children:m("common.cancel")}),e.jsxs(Y,{variant:"contained",color:"primary",size:"small",disabled:P,onClick:L(b),children:[P&&e.jsx(ne,{size:16,sx:{mr:1}}),m(a?"common.save":"admin.coupon.createPromotionCode")]})]}),children:e.jsx(me,{...w,children:e.jsxs(v,{sx:{display:"flex",flexDirection:"column",gap:3},children:[e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:m("admin.coupon.promotionCodeDescription")}),e.jsx(de,{showCodeInput:!0,showExpandedOptions:!0,availableCurrencies:p})]})})})}function $e({data:o,onChange:h,variant:S="compact"}){const{t}=H(),s=!o.locked&&o.active,a=!o.locked,p=o.active,[m,c]=ce({action:"",loading:!1}),w=async()=>{try{c({loading:!0}),await k.put(`/api/promotion-codes/${o.id}/archive`).then(b=>b.data),B.success(t("common.saved")),W("promotion-code.updated"),h(m.action)}catch(b){console.error(b),B.error(V(b))}finally{c({loading:!1,action:""})}},L=async()=>{try{c({loading:!0}),await k.delete(`/api/promotion-codes/${o.id}`).then(b=>b.data),B.success(t("common.removed")),W("promotion-code.deleted"),h(m.action)}catch(b){console.error(b),B.error(V(b))}finally{c({loading:!1,action:""})}},C=()=>{c({action:"edit"}),h("edit",o)},P=[{label:t("admin.promotionCode.edit"),handler:C,color:s?"text.primary":"text.disabled",disabled:!s},{label:t("admin.promotionCode.archive"),handler:()=>c({action:"archive"}),color:p?"text.primary":"text.disabled",disabled:!p},{label:t("admin.promotionCode.delete"),handler:()=>c({action:"delete"}),color:a?"error.main":"text.disabled",disabled:!a}];return e.jsxs(e.Fragment,{children:[e.jsx(le,{variant:S,actions:P}),m.action==="archive"&&e.jsx(G,{onConfirm:w,onCancel:()=>c({action:""}),title:t("admin.promotionCode.archive"),message:t("admin.promotionCode.archiveTip")}),m.action==="delete"&&e.jsx(G,{onConfirm:L,onCancel:()=>c({action:""}),title:t("admin.promotionCode.delete"),message:t("admin.promotionCode.deleteTip")})]})}function xe(o){if((!o.couponId||o.couponId==="")&&(!o.promotionCodeId||o.promotionCodeId===""))throw new Error("Either couponId or promotionCodeId must be provided")}const be=(o,h,S,t="coupon")=>{const s=new URLSearchParams({page:h.page.toString(),pageSize:h.pageSize.toString()});s.append("type",S);const a=t==="coupon"?`/api/coupons/${o}/redemptions`:`/api/promotion-codes/${o}/redemptions`;return k.get(`${a}?${s}`).then(p=>p.data)};function ke({couponId:o="",promotionCodeId:h=""}){xe({couponId:o,promotionCodeId:h});const{t}=H(),s=_e(),[a,p]=F.useState(0),[m,c]=F.useState({page:0,pageSize:10}),[w,L]=F.useState({page:0,pageSize:10}),C=o&&o!==""?o:h,P=o&&o!==""?"coupon":"promotion-code",b=a===0?m:w,D=a===0?"customer":"subscription",{data:d={customers:[],subscriptions:[],count:0},loading:n}=ae(()=>be(C,{page:b.page+1,pageSize:b.pageSize},D,P),{refreshDeps:[C,b.page,b.pageSize,a]}),_=(g,u)=>{p(u),u===0?c({page:0,pageSize:10}):L({page:0,pageSize:10})},x=({page:g,rowsPerPage:u})=>{c({page:g,pageSize:u})},M=({page:g,rowsPerPage:u})=>{L({page:g,pageSize:u})},U=(()=>{const g=[{label:t("common.name"),name:"name",options:{customBodyRenderLite:(u,r)=>{const l=d.customers?.[r];return e.jsx(oe,{customer:l,size:"small"})}}},{label:t("common.email"),name:"email",options:{customBodyRenderLite:(u,r)=>d.customers?.[r]?.email||"—"}},{label:t("admin.coupon.usageStats"),name:"usage_stats",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats;return i?e.jsx(f,{variant:"body2",children:i.total_discount_records}):"—"}}}];return P==="coupon"&&g.push({label:t("admin.coupon.promotionCodesUsed"),name:"promotion_codes",options:{customBodyRenderLite:(u,r)=>{const l=d.customers?.[r],i=l?.coupon_usage_stats?.promotion_codes_used||[],z=l?.discount_records||[];if(i.length===0)return"—";const R=new Map;return z.forEach(y=>{if(y.promotion_code){const j=y.promotion_code.id||y.promotion_code.code;R.set(j,(R.get(j)||0)+1)}}),e.jsx(v,{sx:{display:"flex",flexWrap:"wrap",gap:.5,maxWidth:"200px"},children:i.map(y=>{const j=R.get(y.id||y.code)||0;return e.jsx(Z,{label:`${y.code} (${j})`,size:"small",variant:"outlined",onClick:()=>s(`/admin/products/promotion-codes/${y.id}`),sx:{cursor:"pointer","&:hover":{backgroundColor:"action.hover"}}},`${y.id||y.code}`)})})}}}),g.push({label:t("admin.coupon.totalSavings"),name:"total_savings",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats?.total_savings||{};return Object.keys(i).length===0?e.jsx(f,{variant:"body2",children:"—"}):e.jsx(v,{children:Object.entries(i).map(([z,R],y)=>{if(!R)return null;const j=R;return e.jsxs(f,{variant:"body2",sx:{display:"inline-flex"},children:[y>0&&"、",Q(j.amount,j.currency?.decimal||18)," ",j.currency?.symbol||""]},z)})})}}},{label:t("admin.coupon.usagePeriod"),name:"usage_period",options:{customBodyRenderLite:(u,r)=>{const i=d.customers?.[r]?.coupon_usage_stats;return i?e.jsxs(v,{children:[e.jsxs(f,{variant:"body2",children:[t("admin.coupon.firstUsed"),": ",A(i.first_used)]}),i.first_used!==i.last_used&&e.jsxs(f,{variant:"body2",sx:{color:"text.secondary"},children:[t("admin.coupon.lastUsed"),": ",A(i.last_used)]})]}):"—"}}}),g})(),E=(()=>{const g=[{label:t("admin.subscription.product"),name:"id",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return e.jsx(ee,{to:`/admin/billing/${l.id}`,children:e.jsx(pe,{subscription:l})})}}},{label:t("common.status"),name:"status",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return e.jsx(ee,{to:`/admin/billing/${l.id}`,children:e.jsx(fe,{subscription:l})})}}},{label:t("common.customer"),name:"customer_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.customer;return e.jsx(oe,{customer:i,size:"small"})}}}];return P==="coupon"&&g.push({label:t("admin.coupon.promotionCodesUsed"),name:"promotion_code_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info?.promotion_code;return i?e.jsx(v,{children:e.jsx(Z,{label:i.code,size:"small",variant:"outlined",onClick:()=>s(`/admin/products/promotion-codes/${i.id}`),sx:{cursor:"pointer",mb:.5,"&:hover":{backgroundColor:"action.hover"}}})}):e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.directCouponUsage")})}}}),g.push({label:t("admin.coupon.totalSavings"),name:"total_savings",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info?.total_savings||{};return Object.keys(i).length===0?e.jsx(f,{variant:"body2",sx:{color:"text.lighter"},children:"—"}):e.jsx(v,{children:Object.entries(i).map(([z,R],y)=>{if(!R)return null;const j=R;return e.jsxs(f,{variant:"body2",sx:{lineHeight:1.2},children:[y>0&&", ",Q(j.amount,j.currency?.decimal||18)," ",j.currency?.symbol||""]},z)})})}}},{label:t("admin.coupon.discountInfo"),name:"discount_info",options:{customBodyRenderLite:(u,r)=>{const i=d.subscriptions?.[r]?.discount_info;if(!i)return e.jsx(f,{variant:"body2",children:"—"});const z=i.coupon_info;return e.jsxs(v,{children:[e.jsxs(f,{variant:"body2",children:[t("admin.coupon.discountPeriod"),": ",A(i.discount_start*1e3),i.discount_end&&` - ${A(i.discount_end*1e3)}`]}),e.jsxs(f,{variant:"caption",sx:{color:"text.secondary"},children:[t("admin.coupon.duration"),":"," ",t(`admin.coupon.couponTermsDuration.${z.duration}`,{months:z.duration_in_months})]})]})}}},{label:t("common.created"),name:"created_at",options:{customBodyRenderLite:(u,r)=>{const l=d.subscriptions?.[r];return A(l?.created_at)}}}),g})();return e.jsxs(v,{children:[e.jsxs(ie,{value:a,onChange:_,sx:{flex:"1 0 auto",maxWidth:"100%",fontSize:14,borderBottom:1,borderColor:"divider",".Mui-selected":{fontSize:"14px !important",color:"primary.main"}},children:[e.jsx(K,{label:t("admin.coupon.customers")}),e.jsx(K,{label:t("admin.coupon.subscriptions")})]}),a===0&&e.jsx(v,{sx:{mt:2},children:d.customers?.length>0?e.jsx(J,{data:d.customers,columns:U,loading:n,toolbar:!1,options:{selectableRows:"none",serverSide:!0,count:d.count||0,page:m.page,rowsPerPage:m.pageSize,rowsPerPageOptions:[5,10,25,50]},onChange:x}):!n&&e.jsxs(v,{sx:{textAlign:"center",py:4},children:[e.jsx(f,{variant:"h6",sx:{color:"text.secondary"},children:t("admin.coupon.noCustomersFound")}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.noCustomersRedeem")})]})}),a===1&&e.jsx(v,{children:d.subscriptions?.length>0?e.jsx(J,{data:d.subscriptions,columns:E,loading:n,options:{selectableRows:"none",serverSide:!0,count:d.count||0,page:w.page,rowsPerPage:w.pageSize,rowsPerPageOptions:[5,10,25,50]},onChange:M}):!n&&e.jsxs(v,{sx:{textAlign:"center",py:4},children:[e.jsx(f,{variant:"h6",sx:{color:"text.secondary"},children:t("admin.coupon.noSubscriptionsFound")}),e.jsx(f,{variant:"body2",sx:{color:"text.secondary"},children:t("admin.coupon.noSubscriptionsRedeem")})]})})]})}const ge=O(q)(({theme:o})=>({flexDirection:"row",justifyContent:"space-between",alignItems:"center",padding:o.spacing(1.5,2),backgroundColor:o.palette.grey[50],borderRadius:o.shape.borderRadius,marginBottom:o.spacing(1),"&:last-child":{marginBottom:0}})),he=O(f)(({theme:o})=>({fontWeight:500,color:o.palette.text.primary,textTransform:"uppercase",fontSize:"0.875rem"})),ye=O(f)(({theme:o})=>({color:o.palette.text.secondary,fontSize:"0.875rem",fontFamily:"monospace"})),ve=O(q)(({theme:o})=>({flexDirection:"row",justifyContent:"space-between",alignItems:"center",padding:o.spacing(1,2),marginBottom:o.spacing(1),borderBottom:`1px solid ${o.palette.divider}`})),te=O(f)(({theme:o})=>({fontWeight:600,color:o.palette.text.primary,fontSize:"0.75rem",letterSpacing:"0.5px"}));function Oe({currencyOptions:o,type:h="coupon"}){const{t:S}=H(),{settings:t}=se();if(!o||Object.keys(o).length===0)return null;const s=Object.entries(o);return e.jsxs(v,{children:[e.jsxs(ve,{children:[e.jsx(te,{children:S("admin.coupon.currency")}),e.jsx(te,{children:S(h==="coupon"?"admin.coupon.discountAmount":"admin.coupon.minimumAmount")})]}),e.jsx(q,{children:s.map(([a,p])=>{const m=N(t.paymentMethods,a)||{symbol:a.toUpperCase(),name:a.toUpperCase(),decimal:18};let c;return typeof p=="string"?c=$(p,m.decimal):typeof p=="number"?c=p.toLocaleString():typeof p=="object"&&p!==null?"minimum_amount"in p?c=$(p.minimum_amount,m.decimal):"amount_off"in p?c=$(p.amount_off,m.decimal):c="0":c="0",e.jsxs(ge,{children:[e.jsx(he,{children:m.symbol}),e.jsx(ye,{children:c})]},a)})})]})}export{ke as A,Oe as C,$e as P,Ae as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as x,j as n,q as l,ch as D,aT as G,ad as T,bN as H,a3 as $,bH as I}from"./vendor-mui-BXZut9Pz.js";import{V as L}from"./vendor-blocklet-
|
|
1
|
+
import{r as x,j as n,q as l,ch as D,aT as G,ad as T,bN as H,a3 as $,bH as I}from"./vendor-mui-BXZut9Pz.js";import{V as L}from"./vendor-blocklet-DcLR2Cyf.js";import{a as P}from"./index-BarN7DfU.js";import{C as V}from"./currency-GstdXsJf.js";function _({mode:i,hasSelected:d,onSelect:b,value:r,width:z="100%",disabled:h=!1,selectSX:k={},currencyFilter:v=()=>!0,hideMethod:t=!1,includeAllOption:j=!1,allOption:o={value:"all",label:"All"},selectedSx:A={}}){const{t:E}=L(),{settings:g}=P(),[C,u]=x.useState(i),c=x.useMemo(()=>(g.paymentMethods||[]).map(e=>({method:e,currencies:(e.payment_currencies||[]).map(s=>({...s,method:e}))})),[g.paymentMethods]),f=x.useMemo(()=>c.flatMap(e=>e.currencies),[c]);x.useEffect(()=>{if(r&&i==="selected"&&f.length>0){const e=f.find(s=>s.id===r);if(e&&!d(e)){const s=setTimeout(()=>{b(r)},0);return()=>clearTimeout(s)}}},[r,i,f,d]);const W=e=>{h||(u(i),b(e.target.value))},p=f.find(e=>e.id===r),a=c.find(e=>e.currencies.some(s=>s.id===r))?.method,S=x.useMemo(()=>c.map(e=>({method:e.method,currencies:e.currencies.filter(s=>v(s)&&!d(s))})).filter(e=>e.currencies.length>0),[c,d]),y=S.length>0&&!h;if(C==="selected"){const e=j&&r===o.value;let s="";return e?s=o.label:p?.symbol?s=t?p.symbol:`${p.symbol} (${a?.name||""})`:!t&&a?.name&&(s=`(${a.name})`),n.jsxs(l,{onClick:()=>{y&&u("selecting")},sx:{cursor:y?"pointer":"default",display:"inline-flex",minWidth:"120px",justifyContent:"flex-end",textAlign:"right",width:"100%",...A},children:[s,y&&n.jsx(D,{sx:{color:"text.secondary",fontSize:21}})]})}return y?C==="selecting"?n.jsxs(G,{size:"small",value:r,renderValue:()=>{if(j&&r===o.value)return n.jsx(l,{variant:"body1",sx:{display:"inline-flex",fontSize:"12px",color:"text.secondary"},children:o.label});const e=p?.symbol||"",s=!t&&a?.name?` (${a.name})`:"";return n.jsx(l,{variant:"body1",sx:{display:"inline-flex",fontSize:"12px",color:"text.secondary"},children:`${e}${s}`.trim()})},onChange:W,open:!0,sx:{width:z,...k},disabled:h,onClose:()=>u(i),children:[j?n.jsx(T,{value:o.value,children:n.jsx(l,{sx:{fontWeight:"bold"},children:o.label})}):null,S.flatMap(e=>{const s=t?null:n.jsx(H,{sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:"2.1875rem"},children:e.method.name},e.method.id),w=e.currencies.map(m=>n.jsx(T,{sx:{pl:3},value:m.id,children:n.jsxs($,{direction:"row",sx:{width:"100%",justifyContent:"space-between",gap:2},children:[t?null:n.jsx(V,{logo:m.logo,name:m.name}),n.jsx(l,{sx:{fontWeight:t?"normal":"bold"},children:m.symbol})]})},m.id));return s?[s,...w]:w})]}):n.jsx("span",{children:n.jsxs($,{direction:"row",onClick:()=>u("selecting"),sx:{alignItems:"center",cursor:"pointer",display:"inline-flex"},children:[n.jsx(I,{color:"primary"}),n.jsx(l,{color:"primary",children:E("admin.price.currency.add")})]})}):null}export{_ as C};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./vendor-mui-BXZut9Pz.js";import"./vendor-blocklet-
|
|
1
|
+
import"./vendor-mui-BXZut9Pz.js";import"./vendor-blocklet-DcLR2Cyf.js";import"./index-BarN7DfU.js";const d=(i,f,{t:m,separator:c=" "})=>{const h=(r,o)=>`${r||0} ${m(`common.${o}${r>1?"s":""}`).toLowerCase()}`,s=(r,o)=>{switch(o){case"hour":{if(r<24)return[["hour",r]];if(r<48)return[["day",Math.floor(r/24)],["hour",r%24]];const t=Math.floor(r/24);return s(t,"day")}case"day":{if(r<7)return[["day",r]];if(r<14)return[["week",Math.floor(r/7)],["day",r%7]];if(r<30)return r%7===0?[["week",r/7]]:[["day",r]];const t=Math.floor(r/365),e=r%365,n=Math.floor(e/30);return t>0?n>0?[["year",t],["month",n]]:[["year",t]]:n>0?[["month",n],["week",Math.floor(e%30/7)]]:[["week",Math.floor(r/7)]]}case"week":{if(r<4)return[["week",r]];if(r<8)return[["month",Math.floor(r/4)],["week",r%4]];const t=Math.floor(r/4);return s(t,"month")}case"month":{const t=Math.floor(r/12),e=r%12;return t>0?e>0?[["year",t],["month",e]]:[["year",t]]:[["month",r]]}case"year":return[["year",r]];default:return[[o,r]]}},u=s(i,f).filter(([,r])=>r>0);return u.length===0?h(0,f):u.map(([r,o])=>h(o,r)).join(c)};export{d as f};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s,a3 as d,q as r,O as l,be as x}from"./vendor-mui-BXZut9Pz.js";import"./vendor-blocklet-
|
|
1
|
+
import{j as s,a3 as d,q as r,O as l,be as x}from"./vendor-mui-BXZut9Pz.js";import"./vendor-blocklet-DcLR2Cyf.js";import{d as p,aM as o,J as n}from"./index-BarN7DfU.js";function f({subscription:t,variant:e="body1",hideSubscription:a=!1,maxLength:i=80}){const{isMobile:c}=p();return t.description?s.jsxs(d,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[s.jsx(r,{variant:e,className:"subscription-description",children:s.jsx(o,{text:t.description,maxLength:i,useWidth:!0})}),!a&&!c&&s.jsx(l,{title:n(t.items),children:s.jsx(x,{sx:{color:"text.secondary"},fontSize:"small"})})]}):s.jsx(r,{variant:e,children:s.jsx(o,{text:n(t.items),maxLength:i,useWidth:!0})})}export{f as S};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e,b$ as U,a3 as d,B as s,q as c,bf as C,bg as q,a7 as v,A as z,w as H,z as Y,bv as G,Y as f,x as O}from"./vendor-mui-BXZut9Pz.js";import{V as E,P as W,Y as Z,Z as A}from"./vendor-blocklet-DcLR2Cyf.js";import{e as w,d as J,a as K,n as Q,j as N,b8 as X,k as ee}from"./index-BarN7DfU.js";import{C as oe}from"./copyable-QrCyyiou.js";import{E as ie}from"./list-DaK9287Y.js";import{I as b}from"./info-metric-Dl4ZDm0Z.js";import{I as p}from"./info-row-jI0h_hv4.js";import{I as te}from"./info-row-group-CFuMWJf1.js";import{M as ne}from"./editor-AmthipP2.js";import{M as se}from"./list-CkHExntK.js";import{S as g}from"./header-ivXuPt06.js";import{g as re}from"./util-DxXTXkeY.js";import{P as ae,C as ce,A as de,a as le}from"./currency-restrictions-BcEm8W45.js";import{C as me}from"./link-CmPoIweR.js";import{a as pe}from"./vendor-react-BPknnnEA.js";import"./table-BrtHemkA.js";import"./lodash-B4Ozcv0x.js";import"./form-CAPjlw7l.js";import"./index-DoX0A-rP.js";import"./collapse-CSrlJ0eG.js";import"./drawer-form-DspWWj3x.js";import"./currency-select-B4ieQBvv.js";import"./currency-GstdXsJf.js";import"./product-select-ChEyoJqJ.js";import"./form-cX026J4G.js";import"./info-card-BvIMFQo5.js";import"./uploader-CsQNHG4I.js";import"./tax-code-select-TS07I0rB.js";import"./collapse-BvbJGg1V.js";import"./actions-BJDN6Op2.js";import"./link-DMWJcQvZ.js";import"./description-SnR5WxWT.js";import"./status-CUVYrUIG.js";const xe=()=>w.get("/api/customers?limit=1000").then(t=>t.data);function ue({data:t}){const{t:o}=E(),{data:M}=W(xe,{ready:t.verification_type==="user_restricted"&&(t.customer_dids?.length??0)>0}),S=M?.list||[],k=()=>t.nft_config?e.jsxs(d,{spacing:2,children:[t.nft_config.nft_addresses&&t.nft_config.nft_addresses.length>0&&e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.nftAddresses")}),e.jsx(_,{children:t.nft_config.nft_addresses.map(n=>e.jsx(v,{label:n,size:"small",variant:"outlined",color:"default",sx:{backgroundColor:"grey.50",borderColor:"grey.300",fontFamily:"monospace",fontSize:"0.75rem",maxWidth:200}},n))})]}),t.nft_config.nft_tags&&t.nft_config.nft_tags.length>0&&e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.nftTags")}),e.jsx(_,{children:t.nft_config.nft_tags.map(n=>e.jsx(v,{label:n,size:"small",variant:"outlined",color:"primary",sx:{backgroundColor:"primary.50",fontWeight:500}},n))})]}),t.nft_config.min_balance&&e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.minBalance")}),e.jsx(c,{variant:"body2",sx:{fontWeight:"medium"},children:t.nft_config.min_balance})]})]}):e.jsx(c,{variant:"body2",sx:{color:"text.secondary"},children:o("admin.promotionCode.noNftConfig")}),x=()=>t.vc_config?e.jsxs(d,{spacing:2,children:[t.vc_config.vc_roles&&t.vc_config.vc_roles.length>0&&e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.requiredRoles")}),e.jsx(_,{children:t.vc_config.vc_roles.map(n=>e.jsx(v,{label:n,size:"small",variant:"outlined",color:"secondary",sx:{backgroundColor:"secondary.50",fontWeight:500,textTransform:"capitalize"}},n))})]}),t.vc_config.vc_trusted_issuers&&t.vc_config.vc_trusted_issuers.length>0&&e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.trustedIssuers")}),e.jsx(_,{children:t.vc_config.vc_trusted_issuers.map(n=>e.jsx(v,{label:n,size:"small",variant:"outlined",color:"info",sx:{backgroundColor:"info.50",fontFamily:"monospace",fontSize:"0.75rem",maxWidth:200}},n))})]})]}):e.jsx(c,{variant:"body2",sx:{color:"text.secondary"},children:o("admin.promotionCode.noVcConfig")}),l=()=>t.customer_dids?.length?e.jsxs(j,{children:[e.jsx(h,{children:o("admin.promotionCode.allowedUsers")}),e.jsx(ge,{children:t.customer_dids.map(n=>{const i=S.find(u=>u.did===n||u.id===n);return i?e.jsx(me,{customer:i,size:"small",cardProps:{sx:{border:"none",p:0,minWidth:0}}},n):e.jsx(v,{label:n,size:"small",variant:"outlined",color:"default",sx:{maxWidth:200,backgroundColor:"grey.50",borderColor:"grey.300"}},n)})})]}):e.jsx(c,{variant:"body2",sx:{color:"text.secondary"},children:o("admin.promotionCode.noUsersSpecified")}),I=()=>{switch(t.verification_type){case"nft":return k();case"vc":return x();case"user_restricted":return l();default:return e.jsx(c,{variant:"body2",sx:{color:"text.secondary",fontStyle:"italic"},children:o("admin.promotionCode.codeVerificationOnly")})}};return e.jsx(fe,{children:e.jsx(U,{children:e.jsxs(d,{spacing:2,children:[e.jsxs(s,{sx:{display:"flex",flexDirection:{xs:"column",sm:"row"},gap:{xs:1,sm:2},alignItems:{xs:"flex-start",sm:"center"}},children:[e.jsx(c,{variant:"caption",sx:{color:"text.secondary"},children:o("admin.promotionCode.verificationType")}),e.jsx(c,{variant:"subtitle2",sx:{color:"text.primary",fontWeight:"medium"},children:o(`admin.promotionCode.verificationTypeMap.${t.verification_type}`)})]}),I()]})})})}const fe=C(q)(({theme:t})=>({border:`1px solid ${t.palette.divider}`,boxShadow:"none",backgroundColor:t.palette.background.paper})),j=C(s)({display:"flex",flexDirection:"column",gap:8}),h=C(c)(({theme:t})=>({fontSize:"0.875rem",fontWeight:500,color:t.palette.text.secondary})),_=C(s)({display:"flex",flexDirection:"row",flexWrap:"wrap",gap:8}),ge=C(s)({display:"flex",flexDirection:"row",flexWrap:"wrap",gap:8,alignItems:"center"}),je=t=>w.get(`/api/promotion-codes/${t}`).then(o=>o.data),he=t=>w.get(`/api/coupons/${t}`).then(o=>o.data);function eo(t){const{t:o}=E(),{isMobile:M}=J(),S=pe(),{settings:k}=K(),[x,l]=Z({editing:{metadata:!1},loading:{metadata:!1},editModalOpen:!1}),{loading:I,error:n,data:i,runAsync:u}=W(()=>je(t.id)),{data:m}=W(()=>i?.coupon_id?he(i.coupon_id):Promise.resolve(null),{refreshDeps:[i?.coupon_id]});if(n)return e.jsx(z,{severity:"error",children:n.message});if(I||!i)return e.jsx(H,{});const T=(()=>{const r=k.paymentMethods?.flatMap(y=>y.payment_currencies)||[];if(!m||m.percent_off)return r;const a=new Set;return m.currency_id&&a.add(m.currency_id),m.currency_options&&typeof m.currency_options=="object"&&Object.keys(m.currency_options).forEach(y=>{a.add(y)}),r.filter(y=>a.has(y.id))})(),P=async r=>{try{l(a=>({loading:{...a.loading,metadata:!0}})),await w.put(`/api/promotion-codes/${t.id}`,{metadata:r.metadata}),A.success(o("common.saved")),X("promotion-code.updated"),u()}catch(a){console.error(a),A.error(ee(a))}finally{l(a=>({loading:{...a.loading,metadata:!1}}))}},D=()=>{l(r=>({editing:{...r.editing,metadata:!0}}))},$=(r,a)=>{r==="edit"&&a?l({editModalOpen:!0}):u()},B=()=>{l({editModalOpen:!1})},L=()=>{l({editModalOpen:!1}),u()},V=()=>{const r=i.expires_at&&Math.floor(Date.now()/1e3)>i.expires_at,a=i.max_redemptions&&i.times_redeemed>=i.max_redemptions;return r?{label:o("admin.promotionCode.expired"),color:"default"}:a?{label:o("admin.promotionCode.maxedOut"),color:"default"}:i.active?{label:o("admin.promotionCode.active"),color:"success"}:{label:o("admin.promotionCode.inactive"),color:"default"}},F=()=>{const r=i.max_redemptions?i.max_redemptions.toString():o("admin.promotionCode.unlimited");return`${i.times_redeemed||0}/${r}`},R=V();return e.jsxs(Ce,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(s,{children:[!i.active&&e.jsxs(z,{severity:"warning",children:[e.jsx(Y,{children:o("admin.promotionCode.inactiveTitle")}),o("admin.promotionCode.inactiveTip")]}),e.jsxs(d,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(d,{direction:"row",onClick:()=>re("/admin/products/coupons"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(G,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(c,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:o("admin.coupons")})]}),e.jsx(d,{direction:"row",spacing:2,children:e.jsx(ae,{data:i,onChange:$,variant:"normal"})})]}),e.jsxs(s,{sx:{mt:4,mb:3,display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(d,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:e.jsx(c,{variant:"h2",sx:{color:"text.primary",fontFamily:"monospace",letterSpacing:1},children:i.code})}),e.jsxs(d,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap","hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(b,{label:o("admin.promotionCode.id"),value:e.jsx(oe,{text:t.id,style:{marginLeft:4}}),divider:!0}),e.jsx(b,{label:o("admin.promotionCode.redemptions"),value:F(),divider:!0}),e.jsx(b,{label:o("admin.promotionCode.status"),value:e.jsx(Q,{label:R.label,color:R.color}),divider:!0}),e.jsx(b,{label:o("admin.promotionCode.verificationType"),value:o(`admin.promotionCode.verificationTypeMap.${i.verification_type}`),divider:!0}),e.jsx(b,{label:o("admin.promotionCode.created"),value:N(i.created_at),divider:!0})]})]}),e.jsx(f,{})]}),e.jsxs(d,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".promotion-code-column-1":{minWidth:{xs:"100%",lg:"600px"}},".promotion-code-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(s,{className:"promotion-code-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("common.details")}),e.jsxs(te,{children:[e.jsx(p,{label:o("common.active"),value:i.active?o("admin.promotionCode.yes"):o("admin.promotionCode.no")}),i.description&&e.jsx(p,{label:o("admin.coupon.desc"),value:i.description}),e.jsx(p,{label:o("admin.promotionCode.couponId"),value:e.jsx(O,{variant:"text",color:"inherit",size:"small",sx:{color:"secondary.main"},onClick:()=>S(`/admin/products/coupons/${i.coupon_id}`),children:i.coupon_id})}),e.jsx(p,{label:o("admin.promotionCode.maxRedemptions"),value:i.max_redemptions||o("admin.promotionCode.unlimited")}),e.jsx(p,{label:o("admin.promotionCode.timesRedeemed"),value:i.times_redeemed||0}),e.jsx(p,{label:o("admin.promotionCode.expires"),value:i.expires_at?N(i.expires_at*1e3):o("admin.promotionCode.never")}),e.jsx(p,{label:o("admin.promotionCode.updated"),value:N(i.updated_at)})]})]}),e.jsx(f,{}),e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("admin.promotionCode.verificationConfig")}),e.jsx(s,{className:"section-body",children:e.jsx(ue,{data:i})})]}),i.restrictions?.currency_options&&Object.keys(i.restrictions.currency_options).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(f,{}),e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("admin.coupon.currencies")}),e.jsx(s,{className:"section-body",children:e.jsx(ce,{currencyOptions:i.restrictions.currency_options,type:"promotion_code"})})]})]}),e.jsx(f,{}),e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("admin.coupon.activeRedemptions")}),e.jsx(s,{className:"section-body",children:e.jsx(de,{promotionCodeId:i.id})})]}),e.jsx(f,{}),e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("common.events")}),e.jsx(s,{className:"section-body",children:e.jsx(ie,{features:{toolbar:!1},object_id:i.id})})]})]}),M&&e.jsx(f,{}),e.jsx(s,{className:"promotion-code-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:e.jsxs(s,{className:"section",children:[e.jsx(g,{title:o("common.metadata.label"),children:e.jsx(O,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:x.editing.metadata,onClick:D,children:o("common.edit")})}),e.jsxs(s,{className:"section-body",children:[e.jsx(se,{data:i.metadata,handleEditMetadata:D}),x.editing.metadata&&e.jsx(ne,{data:i,loading:x.loading.metadata,onSave:P,onCancel:()=>l(r=>({editing:{...r.editing,metadata:!1}}))})]})]})})]}),e.jsx(le,{open:x.editModalOpen,onClose:B,onSubmit:L,couponId:i.coupon_id,promotionCode:i,isEditing:!0,availableCurrencies:T})]})}const Ce=C(d)``;export{eo as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as v,j as e,A as w,w as y,B as r,a3 as a,bv as _,q as n,x as u,Y as d,N as C,a7 as k,bf as I}from"./vendor-mui-BXZut9Pz.js";import{V as E,
|
|
1
|
+
import{r as v,j as e,A as w,w as y,B as r,a3 as a,bv as _,q as n,x as u,Y as d,N as C,a7 as k,bf as I}from"./vendor-mui-BXZut9Pz.js";import{V as E,P as N}from"./vendor-blocklet-DcLR2Cyf.js";import{k as D,a3 as S,i as T,N as A,p as B,j as f,e as G}from"./index-BarN7DfU.js";import{S as W}from"./source-data-viewer-i1q9wNIG.js";import{I as h}from"./info-metric-Dl4ZDm0Z.js";import{I as i}from"./info-row-jI0h_hv4.js";import{I as M}from"./info-row-group-CFuMWJf1.js";import{C as $}from"./copyable-QrCyyiou.js";import{S as c}from"./header-ivXuPt06.js";import{M as z}from"./list-CkHExntK.js";import{g as R}from"./util-DxXTXkeY.js";import{E as L}from"./list-DaK9287Y.js";import{a as O}from"./vendor-react-BPknnnEA.js";import"./lodash-B4Ozcv0x.js";import"./table-BrtHemkA.js";const q=l=>G.get(`/api/credit-transactions/${l}`).then(s=>s.data);function ie({id:l}){const{t:s}=E(),o=O(),{loading:j,error:x,data:t}=N(()=>q(l)),g=v.useCallback(()=>{R("/admin/customers")},[]);if(x)return e.jsx(w,{severity:"error",children:D(x)});if(j||!t)return e.jsx(y,{});const b=m=>{if(!m)return null;const p={pending:{label:s("common.pending"),color:"warning"},completed:{label:s("common.completed"),color:"success"},failed:{label:s("common.failed"),color:"error"}}[m]||{label:m,color:"default"};return e.jsx(k,{label:p.label,size:"small",color:p.color})};return e.jsxs(F,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(r,{children:[e.jsxs(a,{className:"page-header",direction:"row",justifyContent:"space-between",alignItems:"center",children:[e.jsxs(a,{direction:"row",alignItems:"center",sx:{fontWeight:"normal",cursor:"pointer"},onClick:g,children:[e.jsx(_,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(n,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:s("admin.creditTransactions.title")})]}),e.jsxs(a,{direction:"row",spacing:1,children:[t.creditGrant&&e.jsx(u,{variant:"outlined",size:"small",onClick:()=>o(`/admin/customers/${t.credit_grant_id}`),children:s("common.viewGrant")}),t.subscription&&e.jsx(u,{variant:"outlined",size:"small",onClick:()=>o(`/admin/billing/${t.subscription_id}`),children:s("common.viewSubscription")})]})]}),e.jsxs(r,{mt:4,mb:3,sx:{display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(a,{direction:"row",justifyContent:"space-between",alignItems:"center",children:e.jsxs(a,{direction:"column",spacing:.5,children:[e.jsx(n,{variant:"h2",sx:{fontWeight:600},children:t.description||s("common.creditTransaction")}),e.jsx($,{text:t.id})]})}),e.jsxs(a,{className:"section-body",justifyContent:"flex-start",flexWrap:"wrap",sx:{"hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(h,{label:s("common.creditAmount"),value:e.jsx(a,{direction:"row",alignItems:"center",spacing:.5,children:e.jsxs(n,{variant:"body2",sx:{color:"error.main"},children:["-",S(T(t.credit_amount,t.creditGrant?.paymentCurrency?.decimal||0),t.creditGrant?.paymentCurrency?.symbol||"")]})}),divider:!!t.transfer_status}),t.transfer_status&&e.jsx(h,{label:s("common.transferStatus"),value:b(t.transfer_status)})]})]}),e.jsx(d,{})]}),e.jsxs(a,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".transaction-column-1":{minWidth:{xs:"100%",lg:"600px"}},".transaction-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(r,{flex:1,className:"transaction-column-1",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(r,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(c,{title:s("admin.details")}),e.jsxs(M,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:[e.jsx(i,{label:s("common.customer"),value:e.jsxs(a,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(C,{src:A(t.customer?.did,t.customer?.updated_at?new Date(t.customer.updated_at).toISOString():"",24),alt:t.customer?.name,sx:{width:24,height:24}}),e.jsx(n,{children:t.customer?.name})]})}),e.jsx(i,{label:s("common.creditGrant"),value:e.jsx(n,{component:"span",onClick:()=>o(`/admin/customers/${t.credit_grant_id}`),sx:{color:"text.link",cursor:"pointer"},children:t.creditGrant?.name||t.credit_grant_id})}),t.meter&&e.jsx(i,{label:s("common.meterEvent"),value:e.jsx(n,{component:"span",onClick:()=>o(`/admin/billing/${t.meter_id}`),sx:{color:"text.link",cursor:"pointer"},children:t.meter.name||t.meter.event_name})}),t.subscription&&e.jsx(i,{label:s("admin.subscription.name"),value:e.jsx(n,{component:"span",onClick:()=>o(`/admin/billing/${t.subscription_id}`),sx:{color:"text.link",cursor:"pointer"},children:t.subscription.description||t.subscription_id})}),t.transfer_hash&&t.paymentMethod&&e.jsx(i,{label:s("common.transferTxHash"),value:e.jsx(B,{details:{arcblock:{tx_hash:t.transfer_hash,payer:""}},method:t.paymentMethod,mode:"dashboard"})}),e.jsx(i,{label:s("admin.meterEvent.reportedAt"),value:f(t.meterEvent?.timestamp?t.meterEvent.timestamp*1e3:t.meterEvent?.created_at||t.created_at)}),e.jsx(i,{label:s("admin.meterEvent.processedAt"),value:f(t.meterEvent?.processed_at?t.meterEvent.processed_at*1e3:t.created_at)})]})]}),t.meterEvent?.source_data&&e.jsxs(e.Fragment,{children:[e.jsx(d,{}),e.jsxs(r,{className:"section",children:[e.jsx(c,{title:s("common.sourceData")}),e.jsx(r,{className:"section-body",children:e.jsx(W,{data:t.meterEvent.source_data})})]})]}),e.jsx(d,{}),e.jsxs(r,{className:"section",children:[e.jsx(c,{title:s("admin.events.title")}),e.jsx(r,{className:"section-body",children:e.jsx(L,{features:{toolbar:!1},object_id:t.id})})]})]}),e.jsx(r,{className:"transaction-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:e.jsxs(r,{className:"section",children:[e.jsx(c,{title:s("common.metadata.label")}),e.jsx(r,{className:"section-body",children:e.jsx(z,{data:t.metadata})})]})})]})]})}const F=I(a)``;export{ie as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e,A as E,w as O,B as r,a3 as o,bv as R,q as w,N as W,Y as x,O as H,be as U,x as q,bf as G}from"./vendor-mui-BXZut9Pz.js";import{V,Y,P as F,cw as J,a7 as C,Z as k}from"./vendor-blocklet-DcLR2Cyf.js";import{d as Z,i as K,a5 as Q,n as _,a6 as M,a7 as X,N as ee,j as S,p as te,e as A,k as ae}from"./index-BarN7DfU.js";import{T as se}from"./gas-nyR96dB0.js";import{L as ne}from"./vendor-react-BPknnnEA.js";import{C as ie}from"./copyable-QrCyyiou.js";import{C as oe}from"./link-CmPoIweR.js";import{E as re}from"./list-DaK9287Y.js";import{I as N}from"./info-metric-Dl4ZDm0Z.js";import{I as i}from"./info-row-jI0h_hv4.js";import{M as le}from"./editor-AmthipP2.js";import{M as me}from"./list-CkHExntK.js";import{S as p}from"./header-ivXuPt06.js";import{g as ce,l as de}from"./util-DxXTXkeY.js";import{I as D}from"./info-card-BvIMFQo5.js";import{I as xe}from"./info-row-group-CFuMWJf1.js";import"./table-BrtHemkA.js";import"./lodash-B4Ozcv0x.js";import"./form-CAPjlw7l.js";const pe=d=>A.get(`/api/payouts/${d}`).then(a=>a.data),m="column",c="flex-start";function Le(d){const{t:a,locale:T}=V(),{isMobile:j}=Z(),[f,u]=Y({adding:{price:!1},editing:{metadata:!1,product:!1},loading:{metadata:!1,price:!1,product:!1}}),{loading:$,error:y,data:t,runAsync:z}=F(()=>pe(d.id));if(y)return e.jsx(E,{severity:"error",children:y.message});if($||!t)return e.jsx(O,{});const L=(n=>async B=>{try{u(l=>({loading:{...l.loading,[n]:!0}})),await A.put(`/api/payouts/${d.id}`,B).then(l=>l.data),k.success(a("common.saved")),z()}catch(l){console.error(l),k.error(ae(l))}finally{u(l=>({loading:{...l.loading,[n]:!1}}))}})("metadata"),g=t.paymentCurrency,h=[K(t?.amount,g.decimal),g.symbol].join(" "),b=()=>{u(n=>({editing:{...n.editing,metadata:!0}}))},{paymentIntent:s}=t||{},P=()=>{if(t.customer)return e.jsx(oe,{customer:t.customer});const n=de(t.destination);return n?e.jsx(D,{name:n.name,description:e.jsx(C,{did:t.destination}),logo:n.avatar,size:40}):t.destination},I=s?.customer?.metadata?.anonymous,v=s?.customer?.did||s?.metadata?.payerDid||"";return e.jsxs(ue,{direction:"column",spacing:2.5,mb:4,children:[e.jsxs(r,{children:[e.jsx(o,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(o,{direction:"row",onClick:()=>ce("/admin/payments/payouts"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(R,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(w,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:a("admin.payouts")})]})}),e.jsxs(r,{sx:{mt:4,mb:3,display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(o,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsx(o,{direction:"row",sx:{alignItems:"center"},children:e.jsxs(o,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(W,{src:t.paymentCurrency.logo,alt:t.paymentCurrency.symbol,variant:"square",sx:{width:"52px",height:"52px",borderRadius:.5}}),e.jsxs(o,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:[e.jsx(Q,{amount:h,sx:{my:0,fontSize:"1.75rem",lineHeight:"32px"}}),e.jsx(ie,{text:d.id})]})]})})}),e.jsxs(o,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap","hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(N,{label:a("common.status"),value:e.jsx(_,{label:t.status,color:M(t.status)}),divider:!0}),s?.id&&e.jsx(N,{label:a("customer.payout.payer"),value:e.jsx(D,{variant:"circular",logo:ee(s?.customer?.did,s?.customer?.updated_at?new Date(s?.customer?.updated_at).toISOString():"",48),logoName:s?.customer?.metadata?.anonymous?"":s?.customer?.name,name:e.jsxs(w,{variant:"subtitle2",sx:{...I?{}:{cursor:"pointer","&:hover":{color:"text.link"}}},onClick:()=>{if(I)return;const n=X(s?.customer?.did,T);window.open(n,"_blank")},children:[s?.customer?.name,s?.customer?.email?` (${s?.customer?.email})`:""]}),description:J(v)&&e.jsx(C,{did:v,...j?{responsive:!1,compact:!0}:{}}),size:40}),divider:!0})]})]}),e.jsx(x,{})]}),e.jsxs(o,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".payment-link-column-1":{minWidth:{xs:"100%",lg:"600px"}},".payment-link-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(r,{className:"payment-link-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(r,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(p,{title:a("admin.details")}),e.jsxs(xe,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:[e.jsx(i,{label:a("common.status"),value:e.jsxs(o,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(_,{label:t.status,color:M(t.status)}),t.last_attempt_error&&e.jsx(H,{title:e.jsx("pre",{style:{whiteSpace:"break-spaces"},children:JSON.stringify(t.last_attempt_error,null,2)}),children:e.jsx(U,{fontSize:"small",color:"error"})})]})}),e.jsx(i,{label:a("common.amount"),value:h}),e.jsx(i,{label:a("common.customer"),value:P()}),e.jsx(i,{label:a("common.createdAt"),value:S(t.created_at)}),e.jsx(i,{label:a("common.description"),value:t.description}),e.jsx(i,{label:a("common.updatedAt"),value:S(t.updated_at)})]})]}),e.jsx(x,{}),e.jsxs(r,{className:"section",children:[e.jsx(p,{title:a("admin.events.title")}),e.jsx(r,{className:"section-body",children:e.jsx(re,{features:{toolbar:!1},object_id:t.id})})]})]}),j&&e.jsx(x,{}),e.jsxs(r,{className:"payment-link-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(r,{className:"section",children:[e.jsx(p,{title:a("admin.paymentMethod._name")}),e.jsxs(o,{children:[e.jsx(i,{label:a("common.id"),value:t.paymentMethod?.id,direction:m,alignItems:c}),e.jsx(i,{label:a("admin.paymentMethod.type"),value:t.paymentMethod?.type,direction:m,alignItems:c}),e.jsx(i,{label:a("admin.paymentCurrency.name"),value:`${t.paymentCurrency.symbol} (${t.paymentMethod?.name})`,direction:m,alignItems:c}),(!!t.payment_details?.ethereum||!!t.payment_details?.base)&&e.jsx(i,{label:a("common.txGas"),value:e.jsx(se,{details:t.payment_details,method:t.paymentMethod}),direction:m,alignItems:c}),e.jsx(i,{label:a(`common.${t.payment_details?.arcblock?.type||"transfer"}TxHash`),value:e.jsx(te,{details:t.payment_details,method:t.paymentMethod}),direction:m,alignItems:c})]})]}),e.jsx(x,{}),e.jsxs(r,{className:"section",children:[e.jsx(p,{title:a("admin.connections")}),e.jsx(o,{children:t.payment_intent_id?e.jsx(i,{label:a("admin.paymentIntent.name"),value:e.jsx(ne,{to:`/admin/payments/${t.paymentIntent.id}`,children:t.paymentIntent.id}),direction:m,alignItems:c}):a("common.none")})]}),e.jsx(x,{}),e.jsxs(r,{className:"section",children:[e.jsx(p,{title:a("common.metadata.label"),children:e.jsx(q,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:f.editing.metadata,onClick:b,children:a("common.edit")})}),e.jsxs(r,{className:"section-body",children:[e.jsx(me,{data:t.metadata,handleEditMetadata:b}),f.editing.metadata&&e.jsx(le,{data:t,loading:f.loading.metadata,onSave:L,onCancel:()=>u(n=>({editing:{...n.editing,metadata:!1}}))})]})]})]})]})]})}const ue=G(o)``;export{Le as default};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import{r as p,u as _e,j as e,A as v,w as Ce,B as a,a3 as c,bv as Se,q as o,ai as we,O as w,b4 as Q,bL as ke,Y as k,x as P,bM as X,v as Pe,a4 as Ie,D as De,bh as ze,N as Me,I as Ne,bf as Ae}from"./vendor-mui-BXZut9Pz.js";import{V as Te,P as W,Z as j,F as Re,G as O,H as ee}from"./vendor-blocklet-DcLR2Cyf.js";import{d as We,u as Oe,a as Le,i as L,j as g,y as $e,z as Ue,p as te,A as Fe,m as Ee,B as Be,e as D,k as re,l as He}from"./index-BarN7DfU.js";import{e as Ge,a as qe,L as Ve}from"./vendor-react-BPknnnEA.js";import{C as ne}from"./currency-GstdXsJf.js";import{C as Ke}from"./link-CmPoIweR.js";import{I as se}from"./info-metric-Dl4ZDm0Z.js";import{I as l}from"./info-row-jI0h_hv4.js";import{I as Ye}from"./info-row-group-CFuMWJf1.js";import{S as Ze}from"./description-SnR5WxWT.js";import{P as Je,D as Qe,S as Xe,V as et}from"./payment-method-info-Bsf89VxV.js";import{S as tt}from"./metrics-UvxyQbUF.js";import{S as rt}from"./actions-DGQs8fFF.js";import{u as nt,a as st,b as at}from"./subscription-DrnSPIfs.js";import{f as it}from"./dayjs-DUTDpcNU.js";import{c as ot}from"./util-DxXTXkeY.js";import{u as ct}from"./browser-DDv4_sgY.js";import"./copyable-QrCyyiou.js";import"./usage-records-DAUQMJAW.js";import"./actions-BJDN6Op2.js";import"./click-boundary-CafubiPp.js";import"./generateCategoricalChart-BadryV3H.js";import"./status-CUVYrUIG.js";import"./lodash-B4Ozcv0x.js";const I={mode:"percent",percent:.5},lt=s=>D.get(`/api/subscriptions/${s}`).then(x=>x.data),dt=s=>D.get(`/api/subscriptions/${s}/overdraft-protection`).then(x=>x.data),mt=(s,x)=>D.get(`/api/subscriptions/${s}/cycle-amount`,{params:x}).then(r=>r.data);function Lt(){const{id:s}=Ge(),x=qe(),{t:r,locale:ae}=Te(),{isMobile:d}=We(),{session:$}=Oe(),{connect:z}=Le(),ie=ct(),{loading:oe,error:U,data:t,refresh:_}=W(()=>lt(s)),{hasUnpaid:ce,checkUnpaidInvoices:M}=nt(s),{hasPendingAmount:F,pendingAmount:N}=st(s,t?.paymentCurrency),E=["active","trialing","past_due"].includes(t?.status||"")&&t?.paymentMethod?.type==="arcblock",[le,A]=p.useState(!1),[m,b]=p.useState(I),[B,T]=p.useState(I),[H,G]=p.useState(!1),{liveRateInfo:f}=at({subscriptionId:s,currencyId:t?.paymentCurrency?.id,enabled:!!t?.paymentCurrency?.id});p.useEffect(()=>{const n=t?.slippage_config;if(n&&typeof n=="object"){const i=n.mode==="rate"?"rate":"percent",u=Number(n.percent),y=Number.isFinite(u)&&u>=0?u:.5,S={mode:i,percent:y,...n.min_acceptable_rate?{min_acceptable_rate:String(n.min_acceptable_rate)}:{},...n.base_currency?{base_currency:String(n.base_currency)}:{},...n.updated_at_ms?{updated_at_ms:Number(n.updated_at_ms)}:{}};b(S),T(S);return}b(I),T(I)},[t]);const de=p.useMemo(()=>(t?.items||[]).some(n=>{const i=n.upsell_price||n.price;return i&&i?.pricing_type==="dynamic"}),[t?.items]),q=p.useMemo(()=>{if(m.min_acceptable_rate)return m.min_acceptable_rate;if(f?.rate&&m.percent!==void 0){const n=Number(f.rate),{percent:i}=m;if(Number.isFinite(n)&&n>0&&Number.isFinite(i))return(n*(1-i/100)).toFixed(8).replace(/\.?0+$/,"")}return null},[m.min_acceptable_rate,m.percent,f?.rate]),{data:h=null,loading:me,run:pe}=W(()=>dt(s),{ready:E}),V=_e(),{data:ue={amount:"0",gas:"0"}}=W(()=>mt(s,{overdraftProtection:!0}),{refreshDeps:[s],ready:E}),C=p.useRef(void 0),xe=!!h?.enabled,he=p.useCallback(n=>{C.current=n},[]),K=p.useCallback(()=>{A(!1),b(B)},[B]),fe=async()=>{if(s){G(!0);try{const n={...m,...m.base_currency?{}:{base_currency:f?.base_currency||"USD"}},i=await D.put(`/api/subscriptions/${s}/slippage`,{slippage_config:n});T(n),await _(),A(!1);const u=i.data?.delegation_warning;u&&!u.sufficient?(j.info(r("payment.customer.changePayment.reauthorizationRequired")),z.open({locale:ae,containerEl:void 0,action:"delegation",prefix:Re(He(),"/api/did"),saveConnect:!1,extraParams:{subscriptionId:s},messages:{scan:r("common.connect.defaultScan"),title:r("payment.customer.changePayment.reauthorizationTitle"),confirm:r("common.connect.confirm")},onSuccess:async()=>{z.close(),j.success(r("payment.customer.changePayment.reauthorizationCompleted")),await _()},onClose:()=>{z.close()},onError:y=>{console.error("Delegation failed:",y),j.error(re(y))}})):j.success(r("common.saved"))}catch(n){j.error(re(n))}finally{G(!1)}}};if(t?.customer?.did&&$?.user?.did&&t.customer.did!==$.user.did)return e.jsx(v,{severity:"error",children:r("common.accessDenied")});if(U)return e.jsx(v,{severity:"error",children:U.message});if(oe||!t)return e.jsx(Ce,{});const R=t?.serviceType==="credit"||t?.paymentCurrency?.type==="credit"||t?.items?.some(n=>n?.price?.product?.type==="credit"||n?.price?.metadata?.credit_config),Y=t?.paymentMethod?.type==="arcblock"&&!me&&!!h&&["active","trialing","past_due"].includes(t.status)&&!R,ye=()=>{const n=t?.overdraft_protection?.enabled,i=h?.upcoming?.amount||"0",u=h?.gas||"0",y=!xe||h.unused==="0"||new O(h.unused).lt(new O(i).add(new O(u))),S=+ee(ue.amount||"0",t.paymentCurrency?.decimal),ge=+ee(h?.unused||"0",t.paymentCurrency?.decimal),be=ve=>{if(!t?.pending_invoice_item_interval)return"";const{interval:Z,interval_count:je}=t.pending_invoice_item_interval,J=ve*je;return["hour","day","week","month","year"].includes(Z)?r("common.estimatedDuration",{duration:it(J,Z,{t:r})}):r("customer.overdraftProtection.estimatedDuration",{duration:J,unit:r("customer.overdraftProtection.intervals").toLowerCase()})};return n?n&&y?e.jsx(P,{size:"small",color:"error",sx:{fontSize:"12px",textAlign:"left"},onClick:()=>C.current?.openOverdraftProtection({enabled:!0}),children:r("customer.overdraftProtection.insufficient")}):e.jsxs(c,{direction:"row",sx:{alignItems:"center",flexWrap:"wrap",justifyContent:"flex-end",columnGap:.5},children:[e.jsxs(c,{direction:"row",spacing:.5,sx:{alignItems:"center"},children:[e.jsx(ze,{sx:{fontSize:"16px",color:"success.main",verticalAlign:"middle"}}),e.jsx(o,{sx:{color:"success.main",fontWeight:500},children:r("customer.overdraftProtection.enabled")})]}),!d&&e.jsx(k,{orientation:"vertical",flexItem:!0,sx:{mx:1,borderColor:"divider"}}),e.jsxs(o,{sx:{color:"text.primary",display:"flex",alignItems:"center",gap:.5,fontWeight:500},children:[e.jsx(Me,{src:t.paymentCurrency?.logo,sx:{width:16,height:16},alt:t.paymentCurrency?.symbol}),e.jsxs(a,{sx:{display:"flex",alignItems:"baseline"},children:[L(h?.unused,t.paymentCurrency.decimal),e.jsxs(o,{sx:{color:"text.secondary",fontSize:"14px",ml:.5},children:[t.paymentCurrency.symbol,"(",be(Math.ceil(ge/S)),")"]})]})]}),t?.overdraft_protection?.enabled&&e.jsx(w,{title:r("customer.overdraftProtection.setting"),placement:"top",children:e.jsx(Ne,{size:"small",sx:{ml:-1,color:"text.disabled","&:hover":{color:"primary.main",backgroundColor:"transparent"}},onClick:()=>C.current?.openOverdraftProtection({enabled:!0}),children:e.jsx(X,{fontSize:"small",sx:{fontSize:16}})})})]}):e.jsxs(c,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(o,{sx:{color:"text.lighter"},children:r("customer.overdraftProtection.disabled")}),e.jsx(P,{size:"small",sx:{fontSize:"13px",pt:0,pb:0,height:3,color:"text.link","&:hover":{backgroundColor:"primary.lighter"}},onClick:()=>C.current?.openOverdraftProtection({enabled:!0}),children:r("customer.overdraftProtection.open")})]})};return e.jsxs(e.Fragment,{children:[e.jsxs(pt,{children:[e.jsxs(a,{children:[!t.paymentMethodDetails&&["active","trialing"].includes(t.status)&&e.jsx(v,{severity:"warning",sx:{mb:2},children:r("admin.subscription.noPaymentMethodWarning")}),ce&&e.jsx(v,{severity:"error",sx:{mb:2},children:r("customer.unpaidInvoicesWarningTip")}),F&&N&&e.jsx(v,{severity:"error",sx:{mb:2},children:r("customer.pendingAmountWarningTip",{amount:L(N,t?.paymentCurrency?.decimal),symbol:t?.paymentCurrency?.symbol})}),e.jsxs(c,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center",position:"relative"},children:[ie?e.jsx(a,{}):e.jsxs(c,{direction:"row",onClick:()=>x("/customer",{replace:!0}),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(Se,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(o,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:r("payment.customer.subscriptions.title")})]}),e.jsx(c,{direction:"row",sx:{gap:1},children:e.jsx(rt,{subscription:t,onChange:n=>{_(),n==="batch-pay"&&M()},showExtra:!0,showDelegation:!0,showOverdraftProtection:{show:Y,onChange:()=>pe()},showRecharge:!0,mode:d?"menu-only":"primary-buttons",actionProps:{cancel:{variant:"outlined",color:"primary"},recover:{variant:"outlined",color:"info"},pastDue:{variant:"outlined",color:"primary"}},setUp:he})})]}),e.jsxs(a,{sx:{mt:d?2:4,display:"flex",border:d?`1px solid ${V.palette.divider}`:"none",borderRadius:d?1:0,p:d?2:0,gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(c,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsx(c,{direction:"row",sx:{alignItems:"center",flexWrap:"wrap",gap:1},children:e.jsx(Ze,{subscription:t,variant:"h1"})})}),e.jsxs(c,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap",flex:1,width:"100%","hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(tt,{subscription:t}),Y&&e.jsx(se,{label:e.jsxs(c,{direction:"row",spacing:.5,sx:{alignItems:"center"},children:[e.jsx(o,{component:"span",sx:{fontSize:14,fontWeight:500},children:r("customer.overdraftProtection.title")}),e.jsx(we,{href:"https://www.arcblock.io/content/blog/en/payment-kit-v117-sub-guard#listen-to-the-audio-overview",target:"_blank",rel:"noopener noreferrer",sx:{display:"flex",alignItems:"center"},children:e.jsx(w,{title:r("customer.overdraftProtection.learnMore"),placement:"top",children:e.jsx(Q,{fontSize:"small",sx:{fontSize:"14px",ml:-.2,color:"text.secondary",cursor:"pointer",opacity:.8,"&:hover":{color:"primary.main"}}})})}),t.overdraft_protection?.payment_details?.arcblock?.staking?.address&&e.jsx(w,{title:e.jsxs(o,{sx:{fontFamily:"monospace",fontSize:"13px"},children:[r("customer.overdraftProtection.stakingAddress"),":",t.overdraft_protection?.payment_details?.arcblock?.staking?.address]}),arrow:!0,placement:"top",children:e.jsx(ke,{sx:{fontSize:"16px",color:"text.secondary",cursor:"pointer",ml:1,"&:hover":{color:"primary.main"},display:{xs:"none",md:"block"}}})})]}),value:ye()}),R&&F&&e.jsx(se,{label:r("admin.customer.creditGrants.pendingAmount"),value:e.jsx(o,{sx:{color:"error.main"},children:`${L(N,t?.paymentCurrency?.decimal)} ${t?.paymentCurrency?.symbol}`})})]})]})]}),d?null:e.jsx(k,{}),e.jsxs(a,{className:"section",sx:{containerType:"inline-size",border:d?`1px solid ${V.palette.divider}`:"none",borderRadius:d?1:0,p:d?2:0},children:[e.jsx(o,{variant:"h3",className:"section-header",sx:{mb:3},children:r("admin.details")}),e.jsxs(Ye,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 980px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:d?.5:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 980px)":{flexDirection:"row",alignItems:"center"}},".currency-name":{color:"text.secondary",lineHeight:1,fontSize:14},".tx-link-text":{fontSize:14,lineHeight:1}},children:[e.jsx(l,{label:r("common.customer"),value:e.jsx(Ke,{customer:t.customer,linked:!1,size:"small"})}),e.jsx(l,{label:r("common.createdAt"),value:g(t.created_at)}),e.jsx(l,{label:r("admin.subscription.currentPeriod"),value:[g(t.current_period_start*1e3),g(t.current_period_end*1e3)].join(" ~ ")}),e.jsx(l,{label:r("admin.subscription.trialingPeriod"),value:t.trial_end&&t.trial_start?[g(t.trial_start*1e3),g(t.trial_end*1e3)].join(" ~ "):""}),t.status==="paused"&&!!t.pause_collection?.resumes_at&&e.jsx(l,{label:r("common.resumesAt"),value:g(t.pause_collection.resumes_at*1e3)}),e.jsx(l,{label:r("admin.subscription.collectionMethod"),value:t.collection_method}),e.jsx(l,{label:r("admin.paymentMethod._name"),value:e.jsx(ne,{logo:t.paymentMethod?.logo,name:t.paymentMethod?.name,size:16})}),e.jsx(l,{label:r("admin.paymentCurrency.name"),value:e.jsxs(c,{direction:"row",spacing:2,children:[e.jsx(ne,{logo:t.paymentCurrency.logo,name:t.paymentCurrency.symbol,size:16}),ot(t)&&e.jsx(P,{variant:"text",sx:{color:"text.link"},size:"small",onClick:async()=>{t?.overdraft_protection?.enabled&&await M()||x(`/customer/subscription/${t.id}/change-payment`)},children:r("payment.customer.subscriptions.changePayment")})]})}),de&&t.paymentMethod?.type!=="stripe"&&e.jsx(l,{label:e.jsxs(c,{direction:"row",spacing:.5,sx:{alignItems:"center"},children:[e.jsx("span",{children:r("common.slippage")}),e.jsx(w,{title:r("common.slippageTooltip"),placement:"top",children:e.jsx(Q,{sx:{fontSize:"0.875rem",color:"text.secondary",cursor:"help"}})})]}),value:e.jsxs(c,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(o,{color:q?"text.primary":"text.secondary",children:$e(q)||"—"}),e.jsx(P,{variant:"text",size:"small",sx:{color:"text.link",minWidth:"auto",p:.5},onClick:()=>A(!0),disabled:H,children:e.jsx(X,{sx:{fontSize:"1rem"}})})]})}),e.jsx(l,{label:r("admin.subscription.payerAddress"),value:e.jsx(Je,{subscriptionId:s,customer:t.customer,paymentMethodDetails:t.paymentMethodDetails,editable:["active","trialing","past_due"].includes(t.status),onUpdate:()=>{_(),M()},paymentMethodType:t.paymentMethod?.type})}),t.payment_details&&Ue(t.payment_details,t.paymentMethod)&&e.jsx(l,{label:r("common.delegateTxHash"),value:e.jsx(te,{details:t.payment_details,method:t.paymentMethod,size:16})}),t.paymentMethod?.type==="arcblock"&&t.payment_details?.arcblock?.staking?.tx_hash&&e.jsx(l,{label:r("common.stakeTxHash"),value:e.jsx(a,{sx:{".MuiTypography-root":{color:"text.link"}},children:e.jsx(te,{details:{arcblock:{tx_hash:t.payment_details?.arcblock?.staking?.tx_hash,payer:""}},method:t.paymentMethod,size:16})})}),!!t.recovered_from&&e.jsx(l,{label:r("common.recoverFrom"),value:e.jsx(Ve,{to:`/customer/subscription/${t.recovered_from}`,target:"_blank",children:t.recovered_from})})]})]}),e.jsx(k,{}),t.discountStats&&e.jsxs(a,{className:"section",children:[e.jsx(o,{variant:"h3",className:"section-header",sx:{mb:1.5},children:r("admin.subscription.discount")}),e.jsx(a,{className:"section-body",children:e.jsx(Qe,{discountStats:t.discountStats})})]}),e.jsx(a,{className:"divider"}),e.jsxs(a,{className:"section",children:[e.jsx(o,{variant:"h3",className:"section-header",sx:{mb:1.5},children:r("admin.products")}),e.jsx(a,{className:"section-body",children:e.jsx(Xe,{data:t.items,currency:t.paymentCurrency,mode:"customer"})})]}),(()=>{const n=t.items?.map(i=>i.price?.product?.vendor_config||[]).flat();return!n||n.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(k,{}),e.jsx(a,{className:"section",children:e.jsx(et,{vendorServices:n,subscriptionId:s,isCanceled:t.status==="canceled"})})]})})(),e.jsx(a,{className:"divider"}),R?e.jsxs(a,{className:"section",children:[e.jsx(o,{variant:"h3",className:"section-header",children:r("admin.creditTransactions.title")}),e.jsx(a,{className:"section-body",children:e.jsx(Fe,{customer_id:t.customer_id,subscription_id:t.id,showAdminColumns:!1,includeGrants:!0})})]}):e.jsxs(a,{className:"section",children:[e.jsx(o,{variant:"h3",className:"section-header",children:r("customer.invoiceHistory")}),e.jsx(a,{className:"section-body",children:e.jsx(Ee,{subscription_id:t.id,type:"table",include_staking:!0,status:"open,paid,uncollectible,void"})})]})]}),e.jsxs(Pe,{open:le,onClose:K,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:2}},children:[e.jsx(Ie,{children:r("payment.checkout.quote.slippageLimit.title")}),e.jsx(De,{sx:{pb:3},children:e.jsx(Be,{value:m.percent,onChange:n=>b(i=>({...i,percent:n})),config:m,onConfigChange:b,exchangeRate:f?.rate||null,baseCurrency:f?.base_currency||"USD",disabled:H,onCancel:K,onSave:fe})})]})]})}const pt=Ae(c)`
|
|
2
|
+
margin-bottom: 24px;
|
|
3
|
+
gap: 24px;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
@media (max-width: ${({theme:s})=>s.breakpoints.values.md}px) {
|
|
6
|
+
. {
|
|
7
|
+
border: none;
|
|
8
|
+
box-shadow: none;
|
|
9
|
+
padding: 0;
|
|
10
|
+
}
|
|
11
|
+
.section-header {
|
|
12
|
+
font-size: 18px;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
`;export{Lt as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as A,j as e,A as j,w as G,B as i,a3 as s,bv as N,q as a,x as T,N as d,Y as u,bf as k}from"./vendor-mui-BXZut9Pz.js";import{V as S,
|
|
1
|
+
import{r as A,j as e,A as j,w as G,B as i,a3 as s,bv as N,q as a,x as T,N as d,Y as u,bf as k}from"./vendor-mui-BXZut9Pz.js";import{V as S,P as Y}from"./vendor-blocklet-DcLR2Cyf.js";import{u as M,a2 as P,a3 as g,i as f,j as x,N as B,p as H,A as F,e as R}from"./index-BarN7DfU.js";import{I as n}from"./info-metric-Dl4ZDm0Z.js";import{S as y}from"./header-ivXuPt06.js";import{C as W}from"./credit-grant-item-list-CeDAM3qV.js";import{I as l}from"./info-row-jI0h_hv4.js";import{I as z}from"./info-row-group-CFuMWJf1.js";import{u as L}from"./browser-DDv4_sgY.js";import{e as $,a as q}from"./vendor-react-BPknnnEA.js";import"./util-DxXTXkeY.js";import"./lodash-B4Ozcv0x.js";import"./copyable-QrCyyiou.js";const E=o=>R.get(`/api/credit-grants/${o}`).then(c=>c.data);function ne(){const{id:o}=$(),c=q(),{t:r}=S(),{session:p}=M(),v=L(),{loading:b,error:h,data:t}=Y(()=>E(o)),w=A.useCallback(()=>{c("/customer",{replace:!0})},[c]);if(t?.customer?.did&&p?.user?.did&&t.customer.did!==p.user.did)return e.jsx(j,{severity:"error",children:r("common.accessDenied")});if(h)return e.jsx(j,{severity:"error",children:h.message});if(b||!t)return e.jsx(G,{});const C=t?.status==="depleted",I=m=>{switch(m){case"granted":return r("admin.customer.creditGrants.status.granted");case"pending":return r("admin.customer.creditGrants.status.pending");case"depleted":return r("admin.customer.creditGrants.status.depleted");case"expired":return r("admin.customer.creditGrants.status.expired");case"voided":return r("admin.customer.creditGrants.status.voided");default:return m}},_=()=>{if(!t.amount||!t.remaining_amount)return 0;const m=parseFloat(t.amount),D=parseFloat(t.remaining_amount);return(m-D)/m*100};return e.jsxs(O,{children:[e.jsxs(i,{children:[e.jsxs(s,{className:"page-header",direction:"row",justifyContent:"space-between",alignItems:"center",sx:{position:"relative"},children:[v?e.jsx(i,{}):e.jsxs(s,{direction:"row",onClick:w,alignItems:"center",sx:{fontWeight:"normal",cursor:"pointer"},children:[e.jsx(N,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(a,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:r("admin.customer.creditGrants.title")})]}),t.metadata?.invoice_id&&e.jsx(T,{variant:"outlined",size:"small",onClick:()=>c(`/customer/invoice/${t.metadata.invoice_id}`),children:r("admin.customer.creditGrants.viewInvoice")})]}),e.jsxs(i,{mt:4,sx:{display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsx(s,{direction:"row",justifyContent:"space-between",alignItems:"center",children:e.jsx(s,{direction:"row",alignItems:"center",flexWrap:"wrap",gap:1,children:e.jsx(s,{direction:"column",alignItems:"flex-start",justifyContent:"space-around",children:e.jsx(a,{variant:"h2",color:"text.primary",children:t.name||t.id})})})}),e.jsxs(s,{className:"section-body",justifyContent:"flex-start",flexWrap:"wrap",sx:{"hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(n,{label:r("common.status"),value:e.jsx(P,{status:t.status,label:I(t.status)})}),e.jsx(n,{label:r("admin.customer.creditGrants.originalAmount"),value:e.jsxs(s,{direction:"row",alignItems:"center",spacing:.5,children:[e.jsx(d,{src:t.paymentCurrency?.logo,sx:{width:16,height:16},alt:t.paymentCurrency?.symbol}),e.jsx(a,{variant:"body2",children:g(f(t.amount,t.paymentCurrency.decimal),t.paymentCurrency.symbol)})]}),divider:!0}),e.jsx(n,{label:r("common.remainingCredit"),value:e.jsxs(s,{direction:"row",alignItems:"center",spacing:.5,children:[e.jsx(d,{src:t.paymentCurrency?.logo,sx:{width:16,height:16},alt:t.paymentCurrency?.symbol}),e.jsx(a,{variant:"body2",children:g(f(t.remaining_amount,t.paymentCurrency.decimal),t.paymentCurrency.symbol)})]}),divider:!0}),e.jsx(n,{label:r("admin.customer.creditGrants.usage"),value:e.jsxs(a,{variant:"body2",color:C?"error.main":"text.primary",children:[_().toFixed(1),"%"]}),divider:!0}),e.jsx(n,{label:r("common.effectiveDate"),value:x(t.effective_at?t.effective_at*1e3:t.created_at,"YYYY-MM-DD HH:mm:ss")}),t.expires_at?e.jsx(n,{label:r("common.expirationDate"),value:x(t.expires_at*1e3,"YYYY-MM-DD HH:mm:ss")}):null]})]})]}),e.jsxs(i,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(y,{title:r("admin.details")}),e.jsxs(z,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:[e.jsx(l,{label:r("common.customer"),value:e.jsxs(s,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(d,{src:B(t.customer?.did,t.customer?.updated_at?new Date(t.customer.updated_at).toISOString():"",24),alt:t.customer?.name,sx:{width:24,height:24}}),e.jsx(a,{children:t.customer?.name})]})}),e.jsx(l,{label:r("common.scope"),value:e.jsx(a,{children:t.applicability_config?.scope?.prices?r("common.specific"):r("common.general")})}),e.jsx(l,{label:r("admin.creditProduct.priority.label"),value:e.jsx(a,{children:t.priority})}),e.jsx(l,{label:r("common.createdAt"),value:x(t.created_at)}),t.chain_detail?.mint?.hash&&t.paymentMethod?.type==="arcblock"&&e.jsx(l,{label:r("common.mintTxHash"),value:e.jsx(H,{details:{arcblock:{tx_hash:t.chain_detail.mint.hash,payer:""}},method:t.paymentMethod,mode:"customer"})})]})]}),e.jsx(u,{}),t.items&&t.items.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs(i,{className:"section",children:[e.jsx(y,{title:r("admin.creditProduct.associatedPrices.label")}),e.jsx(i,{className:"section-body",children:e.jsx(W,{data:t.items,currency:t.paymentCurrency})})]}),e.jsx(u,{})]}),e.jsx(u,{}),e.jsxs(i,{className:"section",children:[e.jsx(a,{variant:"h3",className:"section-header",children:r("admin.creditTransactions.title")}),e.jsx(i,{className:"section-body",children:e.jsx(F,{customer_id:t.customer_id,credit_grant_id:t.id,showAdminColumns:!1,showTimeFilter:!0})})]})]})}const O=k(s)`
|
|
2
2
|
margin-bottom: 24px;
|
|
3
3
|
gap: 24px;
|
|
4
4
|
flex-direction: column;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,A as x,w as p,B as a,a3 as r,bv as u,q as n,O as h,bf as j}from"./vendor-mui-BXZut9Pz.js";import{V as b,
|
|
1
|
+
import{j as e,A as x,w as p,B as a,a3 as r,bv as u,q as n,O as h,bf as j}from"./vendor-mui-BXZut9Pz.js";import{V as b,P as f}from"./vendor-blocklet-DcLR2Cyf.js";import{n as g,j as c,e as v}from"./index-BarN7DfU.js";import{C as w}from"./copyable-QrCyyiou.js";import{I as o}from"./info-metric-Dl4ZDm0Z.js";import{S as y}from"./header-ivXuPt06.js";import{W as k}from"./attempts-CKlxkJuE.js";import{g as C,w as S}from"./util-DxXTXkeY.js";import"./vendor-react-BPknnnEA.js";import"./vendor-arcblock-BTCAQSUK.js";import"./lodash-B4Ozcv0x.js";import"./info-card-BvIMFQo5.js";const W=i=>v.get(`/api/webhook-endpoints/${i}`).then(s=>s.data);function F(i){const{t:s}=b(),{loading:m,error:l,data:t}=f(()=>W(i.id));return l?e.jsx(x,{severity:"error",children:l.message}):m||!t?e.jsx(p,{}):e.jsxs(_,{direction:"column",spacing:4,sx:{mb:4},children:[e.jsxs(a,{children:[e.jsxs(r,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(r,{direction:"row",onClick:()=>C("/admin/developers/webhooks"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(u,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(n,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:s("admin.webhooks")})]}),e.jsx(w,{text:i.id,style:{marginLeft:4}})]}),e.jsxs(a,{sx:{mt:2},children:[e.jsx(r,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(r,{direction:"column",sx:{alignItems:"flex-start"},children:[e.jsx(n,{variant:"h5",children:t.url}),e.jsx(n,{variant:"body1",sx:{color:"text.secondary"},children:t.description})]})}),e.jsxs(r,{className:"section-body",direction:"row",spacing:3,sx:{justifyContent:"flex-start",flexWrap:"wrap",pt:2,mt:2,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(o,{label:s("common.status"),value:e.jsx(g,{label:t.status,color:S(t.status)}),divider:!0}),e.jsx(o,{label:s("admin.webhookEndpoint.listen"),value:e.jsx(h,{arrow:!0,title:e.jsx("ul",{style:{padding:0,margin:0},children:t.enabled_events.map(d=>e.jsx("li",{style:{fontSize:"0.7875rem"},children:d},d))}),children:e.jsxs(n,{sx:{backgroundColor:"grey.100",paddingX:.5,borderRadius:.5},children:[t.enabled_events.length," events"]})}),divider:!0}),e.jsx(o,{label:s("admin.webhookEndpoint.version"),value:t.api_version,divider:!0}),e.jsx(o,{label:s("common.createdAt"),value:c(t.created_at),divider:!0}),e.jsx(o,{label:s("common.updatedAt"),value:c(t.updated_at)})]})]})]}),e.jsxs(a,{className:"section",children:[e.jsx(y,{title:s("admin.webhookEndpoint.attempts"),mb:0}),e.jsx(a,{className:"section-body",children:e.jsx(k,{webhook_endpoint_id:t.id})})]})]})}const _=j(r)``;export{F as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as q,j as e,A as M,w as R,aT as V,ad as $,a3 as u,q as I,bH as K,$ as L,I as X,ci as J,B as s,z as Q,bv as Z,Y as j,x as U,bf as O}from"./vendor-mui-BXZut9Pz.js";import{V as G,X as E,O as H,Y as w}from"./vendor-blocklet-D_i_QeSo.js";import{f as N,e as C,k as S,a as ee,Y as te,d as re,j as W,aP as ie,bb as ne,T as ae,b8 as se}from"./index-DgSc1Qy8.js";import{a as le,L as oe}from"./vendor-react-BPknnnEA.js";import{C as ce}from"./copyable-DpX04wZz.js";import{C as A}from"./currency-GstdXsJf.js";import{E as de}from"./list-D1aevUOI.js";import{I as z}from"./info-metric-CNse3r66.js";import{I as d}from"./info-row-DOK2whMn.js";import{I as F}from"./info-row-group-BeUhWnnY.js";import{M as me}from"./editor-BF5I0siU.js";import{M as ue}from"./list-C521zE_7.js";import{A as pe}from"./add-price-CD-utowo.js";import{P as xe,E as ge}from"./actions-QPa-8lfB.js";import{S as y}from"./header-ivXuPt06.js";import{g as he}from"./util-mDHAL0lx.js";import"./table-BRU4Enia.js";import"./lodash-B4Ozcv0x.js";import"./form-BGm5NPDn.js";import"./form-P4luyUpY.js";import"./collapse-CSrlJ0eG.js";import"./product-select-0ScZE2e8.js";import"./currency-select-DGS-62-L.js";import"./info-card-C1yxhxJG.js";import"./uploader-DRXDz_r0.js";import"./tax-code-select-CWhIIiXi.js";import"./collapse-BvbJGg1V.js";import"./actions-jxGAdGfb.js";const fe=n=>C.get(`/api/prices/${n}/upsell`).then(t=>t.data);function je({price:n,onSelect:t,onAdd:g}){const{t:h}=G(),[m,c]=E({loading:!1,adding:!1,action:""}),{loading:p,error:b,data:o}=H(()=>fe(n.id)),r=q.useMemo(()=>{if(!o||o.length===0)return[];const l=n.currency_options?.map(v=>v.currency_id)||[],f=l.length;return o.filter(v=>v.currency_options.length===f&&v.currency_options.every(D=>l.includes(D.currency_id)))},[o,n.id]);if(b)return e.jsx(M,{severity:"error",children:b.message});if(p||!o)return e.jsx(R,{});const P=l=>{l.target.value&&l.target.value!=="empty"&&(l.target.value==="add"?c({action:"add"}):t(l.target.value))},T=async l=>{try{c({adding:!0}),await C.post("/api/prices",{...l,product_id:n.product_id}),w.success(h("common.saved")),g()}catch(f){throw console.error(f),w.error(S(f)),f}finally{c({adding:!1})}};return e.jsxs(e.Fragment,{children:[e.jsxs(V,{value:"empty",sx:{width:300},size:"small",onChange:P,MenuProps:{style:{maxHeight:480}},children:[e.jsx($,{value:"empty",children:e.jsx(u,{direction:"row",sx:{alignItems:"center"},children:e.jsx(I,{children:h("admin.price.find")})})}),e.jsx($,{value:"add",children:e.jsxs(u,{direction:"row",sx:{alignItems:"center"},children:[e.jsx(K,{}),e.jsx(I,{children:h("admin.price.add")})]})}),r.map(l=>e.jsx($,{value:l.id,children:N(l,n.currency||l.currency)},l.id))]}),m.action==="add"&&e.jsx(pe,{loading:m.adding,onSave:T,onCancel:()=>c({action:""})})]})}function ye({data:n,onChange:t}){const{settings:g}=ee(),[h,m]=E({loading:!1}),c=async()=>{try{m({loading:!0}),await C.put(`/api/prices/${n.id}`,{upsell:{upsells_to_id:""}}).then(o=>o.data),m({loading:!1}),t()}catch(o){console.error(o),w.error(S(o)),m({loading:!1})}},p=async o=>{try{m({loading:!0}),await C.put(`/api/prices/${n.id}`,{upsell:{upsells_to_id:o}}).then(r=>r.data),m({loading:!1}),t()}catch(r){console.error(r),w.error(S(r)),m({loading:!1})}};if(h.loading)return e.jsx(R,{});const b=te(g.paymentMethods,n?.currency_id||"")||g.baseCurrency;return n.upsell?.upsells_to_id?e.jsxs(u,{spacing:1,direction:"row",sx:{alignItems:"center"},children:[e.jsx(I,{children:N(n.upsell.upsells_to,b)}),e.jsx(X,{size:"small",sx:{ml:1},onClick:c,children:e.jsx(J,{color:"error",sx:{opacity:.75}})})]}):e.jsx(je,{price:n,onSelect:p,onAdd:t})}function be({data:n,onChange:t}){return e.jsx(L,{container:!0,children:e.jsx(L,{size:{xs:12,md:12},children:e.jsx(d,{label:"",value:e.jsx(ye,{data:n,onChange:t}),showLabel:!1})})})}const ve=n=>C.get(`/api/prices/${n}`).then(t=>t.data);function Qe(n){const{t,locale:g}=G(),{isMobile:h}=re(),m=le(),[c,p]=E({adding:{price:!1},editing:{metadata:!1,price:!1},loading:{metadata:!1,price:!1}}),{loading:b,error:o,data:r,runAsync:P}=H(()=>ve(n.id));if(o)return e.jsx(M,{severity:"error",children:o.message});if(b||!r)return e.jsx(R,{});const T=i=>async x=>{try{p(a=>({loading:{...a.loading,[i]:!0}})),await C.put(`/api/prices/${n.id}`,x).then(a=>a.data),w.success(t("common.saved")),se("price.updated"),P()}catch(a){throw console.error(a),w.error(S(a)),a}finally{p(a=>({loading:{...a.loading,[i]:!1}}))}},l=T("metadata"),f=T("price"),v=i=>{i==="remove"?m("/admin/products"):P()},D=()=>{p(i=>({editing:{...i.editing,metadata:!0}}))},Y=i=>i==="recurring"?t("admin.price.types.recurring"):i==="one_time"?t("admin.price.types.onetime"):i;return e.jsxs(_e,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(s,{children:[r.active===!1&&e.jsxs(M,{severity:"warning",children:[e.jsx(Q,{children:t("admin.price.archived")}),t("admin.price.archivedTip")]}),r.locked&&e.jsx(M,{severity:"warning",sx:{mb:1},children:t("admin.price.locked")}),e.jsxs(u,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(u,{direction:"row",onClick:()=>he(`/admin/products/${r.product_id}`),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(Z,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(I,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:t("admin.products")})]}),e.jsx(xe,{data:r,onChange:v,variant:"normal"})]}),e.jsxs(s,{sx:{mt:4,mb:3,display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsxs(u,{direction:"column",sx:{gap:1},children:[e.jsxs(I,{variant:"h2",sx:{fontWeight:600},children:["Price for ",r.product.name]}),e.jsx(ce,{text:n.id,style:{marginLeft:4}})]}),e.jsxs(u,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap","hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(z,{label:t("admin.price.amount"),value:N(r,r.currency,r.product.unit_label,1,!0,g),divider:!0}),e.jsx(z,{label:t("common.createdAt"),value:W(r.created_at),divider:!0}),e.jsx(z,{label:t("common.updatedAt"),value:W(r.updated_at)})]})]}),e.jsx(j,{})]}),e.jsxs(u,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".payment-link-column-1":{minWidth:{xs:"100%",lg:"600px"}},".payment-link-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(s,{className:"payment-link-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(s,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(y,{title:t("admin.details"),children:e.jsx(U,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},onClick:()=>p(i=>({editing:{...i.editing,price:!0}})),children:t("common.edit")})}),e.jsxs(F,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:[e.jsx(d,{label:t("admin.price.type"),value:Y(r.type)}),r.type==="recurring"&&e.jsx(d,{label:t("admin.price.recurring.interval"),value:ie(r.recurring,!0,"per",g)}),e.jsx(d,{label:t("admin.price.lookupKey"),value:r.lookup_key}),e.jsx(d,{label:t("admin.price.nickname.label"),value:r.nickname}),c.editing.price&&e.jsx(ge,{price:r,loading:c.loading.price,onSave:f,onCancel:()=>p(i=>({editing:{...i.editing,price:!1}}))})]})]}),e.jsx(j,{}),r.metadata?.credit_config&&e.jsxs(e.Fragment,{children:[e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("admin.creditProduct.configTitle")}),e.jsx(F,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:(()=>{const i=r.metadata.credit_config,x=i.schedule?.enabled,a=r.currency_options?.find(k=>k.currency_id===i.currency_id),_=a?a.currency:null;return e.jsxs(e.Fragment,{children:[x&&i.schedule?.interval_value&&i.schedule?.interval_unit&&e.jsx(d,{label:t("admin.creditProduct.schedule.interval.label"),value:`${t("common.every")} ${i.schedule.interval_value} ${t(`admin.creditProduct.schedule.interval.${i.schedule.interval_unit}`)}`}),x&&i.schedule?.amount_per_grant&&e.jsx(d,{label:t("admin.creditProduct.schedule.amountPerGrant.label"),value:_?e.jsxs(u,{direction:"row",spacing:.5,alignItems:"center",children:[e.jsx("span",{children:i.schedule.amount_per_grant}),e.jsx(A,{logo:_.logo,name:_.symbol,size:16})]}):i.schedule.amount_per_grant}),!x&&i.credit_amount&&e.jsx(d,{label:t("admin.creditProduct.creditAmount.label"),value:_?e.jsxs(u,{direction:"row",spacing:.5,alignItems:"center",children:[e.jsx("span",{children:i.credit_amount}),e.jsx(A,{logo:_.logo,name:_.symbol,size:16})]}):i.credit_amount}),e.jsx(d,{label:t("admin.creditProduct.expirationTime.label"),value:(()=>{if(x&&i.schedule?.expire_with_next_grant)return t("admin.creditProduct.expirationTime.expireWithNextGrant");const k=i.valid_duration_value,B=i.valid_duration_unit;return k&&k>0&&B?`${k} ${t(`admin.creditProduct.validDuration.${B}`)}`:"-"})()}),i.priority!==void 0&&e.jsx(d,{label:t("admin.creditProduct.priority.label"),value:i.priority}),i.applicable_prices&&i.applicable_prices.length>0&&e.jsx(d,{label:t("admin.creditProduct.associatedPrices.label"),value:i.applicable_prices.length})]})})()})]}),e.jsx(j,{})]}),ne(r)&&e.jsxs(e.Fragment,{children:[e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("admin.meters")}),e.jsx(s,{className:"section-body",children:e.jsx(d,{label:t("admin.meter.eventName.label"),value:e.jsx(oe,{to:`/admin/billing/${r.meter?.id}`,target:"_blank",children:r.meter?.event_name})})})]}),e.jsx(j,{})]}),e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("admin.price.currency.list")}),e.jsx(s,{className:"section-body",children:e.jsx(we,{children:e.jsx(ae,{toolbar:!1,footer:!1,data:r.currency_options,columns:[{label:t("admin.price.name"),name:"currency_id",width:200,options:{customBodyRenderLite:(i,x)=>{const a=r.currency_options[x];return e.jsx(A,{logo:a.currency?.logo,name:a.currency?.symbol})}}},{label:t("common.amount"),name:"unit_amount",options:{customBodyRenderLite:(i,x)=>{const a=r.currency_options[x];return N({id:r.id,currency_id:a.currency_id,type:r.type,unit_amount:a.unit_amount,custom_unit_amount:a.custom_unit_amount,recurring:r.recurring},a.currency,r.product.unit_label,1,!0,g)}}}],options:{count:r.currency_options.length,page:0,rowsPerPage:20},mobileTDFlexDirection:"row"})})})]}),e.jsx(j,{}),e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("admin.events.title")}),e.jsx(s,{className:"section-body",children:e.jsx(de,{features:{toolbar:!1},object_id:r.id})})]})]}),h&&e.jsx(j,{}),e.jsxs(s,{className:"payment-link-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("admin.price.upsell.title")}),e.jsx(s,{className:"section-body",children:e.jsx(be,{data:r,onChange:P})})]}),e.jsx(j,{}),e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("common.metadata.label"),children:e.jsx(U,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:c.editing.metadata,onClick:D,children:t("common.edit")})}),e.jsxs(s,{className:"section-body",children:[e.jsx(ue,{data:r.metadata,handleEditMetadata:D}),c.editing.metadata&&e.jsx(me,{data:r,loading:c.loading.metadata,onSave:l,onCancel:()=>p(i=>({editing:{...i.editing,metadata:!1}}))})]})]})]})]})]})}const _e=O(u)``,we=O(s)`
|
|
1
|
+
import{r as q,j as e,A as M,w as R,aT as V,ad as $,a3 as u,q as I,bH as K,$ as L,I as Z,ci as J,B as s,z as Q,bv as X,Y as j,x as U,bf as O}from"./vendor-mui-BXZut9Pz.js";import{V as G,Y as E,P as H,Z as w}from"./vendor-blocklet-DcLR2Cyf.js";import{f as N,e as C,k as S,a as ee,Y as te,d as re,j as W,aP as ie,bb as ne,T as ae,b8 as se}from"./index-BarN7DfU.js";import{a as le,L as oe}from"./vendor-react-BPknnnEA.js";import{C as ce}from"./copyable-QrCyyiou.js";import{C as A}from"./currency-GstdXsJf.js";import{E as de}from"./list-DaK9287Y.js";import{I as z}from"./info-metric-Dl4ZDm0Z.js";import{I as d}from"./info-row-jI0h_hv4.js";import{I as F}from"./info-row-group-CFuMWJf1.js";import{M as me}from"./editor-AmthipP2.js";import{M as ue}from"./list-CkHExntK.js";import{A as pe}from"./add-price-BpnICuHO.js";import{P as xe,E as ge}from"./actions-BD9BAp3M.js";import{S as y}from"./header-ivXuPt06.js";import{g as he}from"./util-DxXTXkeY.js";import"./table-BrtHemkA.js";import"./lodash-B4Ozcv0x.js";import"./form-CAPjlw7l.js";import"./form-cX026J4G.js";import"./collapse-CSrlJ0eG.js";import"./product-select-ChEyoJqJ.js";import"./currency-select-B4ieQBvv.js";import"./info-card-BvIMFQo5.js";import"./uploader-CsQNHG4I.js";import"./tax-code-select-TS07I0rB.js";import"./collapse-BvbJGg1V.js";import"./actions-BJDN6Op2.js";const fe=n=>C.get(`/api/prices/${n}/upsell`).then(t=>t.data);function je({price:n,onSelect:t,onAdd:g}){const{t:h}=G(),[m,c]=E({loading:!1,adding:!1,action:""}),{loading:p,error:b,data:o}=H(()=>fe(n.id)),r=q.useMemo(()=>{if(!o||o.length===0)return[];const l=n.currency_options?.map(v=>v.currency_id)||[],f=l.length;return o.filter(v=>v.currency_options.length===f&&v.currency_options.every(D=>l.includes(D.currency_id)))},[o,n.id]);if(b)return e.jsx(M,{severity:"error",children:b.message});if(p||!o)return e.jsx(R,{});const P=l=>{l.target.value&&l.target.value!=="empty"&&(l.target.value==="add"?c({action:"add"}):t(l.target.value))},T=async l=>{try{c({adding:!0}),await C.post("/api/prices",{...l,product_id:n.product_id}),w.success(h("common.saved")),g()}catch(f){throw console.error(f),w.error(S(f)),f}finally{c({adding:!1})}};return e.jsxs(e.Fragment,{children:[e.jsxs(V,{value:"empty",sx:{width:300},size:"small",onChange:P,MenuProps:{style:{maxHeight:480}},children:[e.jsx($,{value:"empty",children:e.jsx(u,{direction:"row",sx:{alignItems:"center"},children:e.jsx(I,{children:h("admin.price.find")})})}),e.jsx($,{value:"add",children:e.jsxs(u,{direction:"row",sx:{alignItems:"center"},children:[e.jsx(K,{}),e.jsx(I,{children:h("admin.price.add")})]})}),r.map(l=>e.jsx($,{value:l.id,children:N(l,n.currency||l.currency)},l.id))]}),m.action==="add"&&e.jsx(pe,{loading:m.adding,onSave:T,onCancel:()=>c({action:""})})]})}function ye({data:n,onChange:t}){const{settings:g}=ee(),[h,m]=E({loading:!1}),c=async()=>{try{m({loading:!0}),await C.put(`/api/prices/${n.id}`,{upsell:{upsells_to_id:""}}).then(o=>o.data),m({loading:!1}),t()}catch(o){console.error(o),w.error(S(o)),m({loading:!1})}},p=async o=>{try{m({loading:!0}),await C.put(`/api/prices/${n.id}`,{upsell:{upsells_to_id:o}}).then(r=>r.data),m({loading:!1}),t()}catch(r){console.error(r),w.error(S(r)),m({loading:!1})}};if(h.loading)return e.jsx(R,{});const b=te(g.paymentMethods,n?.currency_id||"")||g.baseCurrency;return n.upsell?.upsells_to_id?e.jsxs(u,{spacing:1,direction:"row",sx:{alignItems:"center"},children:[e.jsx(I,{children:N(n.upsell.upsells_to,b)}),e.jsx(Z,{size:"small",sx:{ml:1},onClick:c,children:e.jsx(J,{color:"error",sx:{opacity:.75}})})]}):e.jsx(je,{price:n,onSelect:p,onAdd:t})}function be({data:n,onChange:t}){return e.jsx(L,{container:!0,children:e.jsx(L,{size:{xs:12,md:12},children:e.jsx(d,{label:"",value:e.jsx(ye,{data:n,onChange:t}),showLabel:!1})})})}const ve=n=>C.get(`/api/prices/${n}`).then(t=>t.data);function Qe(n){const{t,locale:g}=G(),{isMobile:h}=re(),m=le(),[c,p]=E({adding:{price:!1},editing:{metadata:!1,price:!1},loading:{metadata:!1,price:!1}}),{loading:b,error:o,data:r,runAsync:P}=H(()=>ve(n.id));if(o)return e.jsx(M,{severity:"error",children:o.message});if(b||!r)return e.jsx(R,{});const T=i=>async x=>{try{p(a=>({loading:{...a.loading,[i]:!0}})),await C.put(`/api/prices/${n.id}`,x).then(a=>a.data),w.success(t("common.saved")),se("price.updated"),P()}catch(a){throw console.error(a),w.error(S(a)),a}finally{p(a=>({loading:{...a.loading,[i]:!1}}))}},l=T("metadata"),f=T("price"),v=i=>{i==="remove"?m("/admin/products"):P()},D=()=>{p(i=>({editing:{...i.editing,metadata:!0}}))},Y=i=>i==="recurring"?t("admin.price.types.recurring"):i==="one_time"?t("admin.price.types.onetime"):i;return e.jsxs(_e,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(s,{children:[r.active===!1&&e.jsxs(M,{severity:"warning",children:[e.jsx(Q,{children:t("admin.price.archived")}),t("admin.price.archivedTip")]}),r.locked&&e.jsx(M,{severity:"warning",sx:{mb:1},children:t("admin.price.locked")}),e.jsxs(u,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(u,{direction:"row",onClick:()=>he(`/admin/products/${r.product_id}`),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(X,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(I,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:t("admin.products")})]}),e.jsx(xe,{data:r,onChange:v,variant:"normal"})]}),e.jsxs(s,{sx:{mt:4,mb:3,display:"flex",gap:{xs:2,sm:2,md:5},flexWrap:"wrap",flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:{xs:"flex-start",sm:"flex-start",md:"center"}},children:[e.jsxs(u,{direction:"column",sx:{gap:1},children:[e.jsxs(I,{variant:"h2",sx:{fontWeight:600},children:["Price for ",r.product.name]}),e.jsx(ce,{text:n.id,style:{marginLeft:4}})]}),e.jsxs(u,{className:"section-body",sx:{justifyContent:"flex-start",flexWrap:"wrap","hr.MuiDivider-root:last-child":{display:"none"},flexDirection:{xs:"column",sm:"column",md:"row"},alignItems:"flex-start",gap:{xs:1,sm:1,md:3}},children:[e.jsx(z,{label:t("admin.price.amount"),value:N(r,r.currency,r.product.unit_label,1,!0,g),divider:!0}),e.jsx(z,{label:t("common.createdAt"),value:W(r.created_at),divider:!0}),e.jsx(z,{label:t("common.updatedAt"),value:W(r.updated_at)})]})]}),e.jsx(j,{})]}),e.jsxs(u,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".payment-link-column-1":{minWidth:{xs:"100%",lg:"600px"}},".payment-link-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(s,{className:"payment-link-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(s,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(y,{title:t("admin.details"),children:e.jsx(U,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},onClick:()=>p(i=>({editing:{...i.editing,price:!0}})),children:t("common.edit")})}),e.jsxs(F,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:[e.jsx(d,{label:t("admin.price.type"),value:Y(r.type)}),r.type==="recurring"&&e.jsx(d,{label:t("admin.price.recurring.interval"),value:ie(r.recurring,!0,"per",g)}),e.jsx(d,{label:t("admin.price.lookupKey"),value:r.lookup_key}),e.jsx(d,{label:t("admin.price.nickname.label"),value:r.nickname}),c.editing.price&&e.jsx(ge,{price:r,loading:c.loading.price,onSave:f,onCancel:()=>p(i=>({editing:{...i.editing,price:!1}}))})]})]}),e.jsx(j,{}),r.metadata?.credit_config&&e.jsxs(e.Fragment,{children:[e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("admin.creditProduct.configTitle")}),e.jsx(F,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",xl:"repeat(2, 1fr)"},"@container (min-width: 1000px)":{gridTemplateColumns:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",xl:"row"},alignItems:{xs:"flex-start",xl:"center"},"@container (min-width: 1000px)":{flexDirection:"row",alignItems:"center"}}},children:(()=>{const i=r.metadata.credit_config,x=i.schedule?.enabled,a=r.currency_options?.find(k=>k.currency_id===i.currency_id),_=a?a.currency:null;return e.jsxs(e.Fragment,{children:[x&&i.schedule?.interval_value&&i.schedule?.interval_unit&&e.jsx(d,{label:t("admin.creditProduct.schedule.interval.label"),value:`${t("common.every")} ${i.schedule.interval_value} ${t(`admin.creditProduct.schedule.interval.${i.schedule.interval_unit}`)}`}),x&&i.schedule?.amount_per_grant&&e.jsx(d,{label:t("admin.creditProduct.schedule.amountPerGrant.label"),value:_?e.jsxs(u,{direction:"row",spacing:.5,alignItems:"center",children:[e.jsx("span",{children:i.schedule.amount_per_grant}),e.jsx(A,{logo:_.logo,name:_.symbol,size:16})]}):i.schedule.amount_per_grant}),!x&&i.credit_amount&&e.jsx(d,{label:t("admin.creditProduct.creditAmount.label"),value:_?e.jsxs(u,{direction:"row",spacing:.5,alignItems:"center",children:[e.jsx("span",{children:i.credit_amount}),e.jsx(A,{logo:_.logo,name:_.symbol,size:16})]}):i.credit_amount}),e.jsx(d,{label:t("admin.creditProduct.expirationTime.label"),value:(()=>{if(x&&i.schedule?.expire_with_next_grant)return t("admin.creditProduct.expirationTime.expireWithNextGrant");const k=i.valid_duration_value,B=i.valid_duration_unit;return k&&k>0&&B?`${k} ${t(`admin.creditProduct.validDuration.${B}`)}`:"-"})()}),i.priority!==void 0&&e.jsx(d,{label:t("admin.creditProduct.priority.label"),value:i.priority}),i.applicable_prices&&i.applicable_prices.length>0&&e.jsx(d,{label:t("admin.creditProduct.associatedPrices.label"),value:i.applicable_prices.length})]})})()})]}),e.jsx(j,{})]}),ne(r)&&e.jsxs(e.Fragment,{children:[e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("admin.meters")}),e.jsx(s,{className:"section-body",children:e.jsx(d,{label:t("admin.meter.eventName.label"),value:e.jsx(oe,{to:`/admin/billing/${r.meter?.id}`,target:"_blank",children:r.meter?.event_name})})})]}),e.jsx(j,{})]}),e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("admin.price.currency.list")}),e.jsx(s,{className:"section-body",children:e.jsx(we,{children:e.jsx(ae,{toolbar:!1,footer:!1,data:r.currency_options,columns:[{label:t("admin.price.name"),name:"currency_id",width:200,options:{customBodyRenderLite:(i,x)=>{const a=r.currency_options[x];return e.jsx(A,{logo:a.currency?.logo,name:a.currency?.symbol})}}},{label:t("common.amount"),name:"unit_amount",options:{customBodyRenderLite:(i,x)=>{const a=r.currency_options[x];return N({id:r.id,currency_id:a.currency_id,type:r.type,unit_amount:a.unit_amount,custom_unit_amount:a.custom_unit_amount,recurring:r.recurring},a.currency,r.product.unit_label,1,!0,g)}}}],options:{count:r.currency_options.length,page:0,rowsPerPage:20},mobileTDFlexDirection:"row"})})})]}),e.jsx(j,{}),e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("admin.events.title")}),e.jsx(s,{className:"section-body",children:e.jsx(de,{features:{toolbar:!1},object_id:r.id})})]})]}),h&&e.jsx(j,{}),e.jsxs(s,{className:"payment-link-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("admin.price.upsell.title")}),e.jsx(s,{className:"section-body",children:e.jsx(be,{data:r,onChange:P})})]}),e.jsx(j,{}),e.jsxs(s,{className:"section",children:[e.jsx(y,{title:t("common.metadata.label"),children:e.jsx(U,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:c.editing.metadata,onClick:D,children:t("common.edit")})}),e.jsxs(s,{className:"section-body",children:[e.jsx(ue,{data:r.metadata,handleEditMetadata:D}),c.editing.metadata&&e.jsx(me,{data:r,loading:c.loading.metadata,onSave:l,onCancel:()=>p(i=>({editing:{...i.editing,metadata:!1}}))})]})]})]})]})]})}const _e=O(u)``,we=O(s)`
|
|
2
2
|
@media (max-width: ${({theme:n})=>n.breakpoints.values.md}px) {
|
|
3
3
|
.MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > .MuiTableCell-root {
|
|
4
4
|
> div {
|