@arcblock/payment-service 1.29.9 → 1.29.10
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.js +51 -51
- package/dist/index.js +195 -43
- package/package.json +3 -3
- package/web/assets/{account-Clbqiiw3.js → account-DrsnH5wP.js} +1 -1
- package/web/assets/{action-DENqSeOa.js → action-C2c0yWuW.js} +1 -1
- package/web/assets/{actions-CDsj5j8l.js → actions--FNKSNIs.js} +1 -1
- package/web/assets/{actions-BJDN6Op2.js → actions-BEUwbsq1.js} +1 -1
- package/web/assets/{actions-CSpJGOX7.js → actions-C9AfME83.js} +1 -1
- package/web/assets/{actions-BD9BAp3M.js → actions-D2-s31n3.js} +1 -1
- package/web/assets/{actions-BSNy5bOd.js → actions-DXMceTgd.js} +1 -1
- package/web/assets/{actions-0iWP2mcx.js → actions-DeCPtfTK.js} +1 -1
- package/web/assets/{actions-DGQs8fFF.js → actions-DtNZGZWf.js} +1 -1
- package/web/assets/{actions-D3tJgrUn.js → actions-JHsqbHpB.js} +1 -1
- package/web/assets/{actions-CZL47E9r.js → actions-izdZ2Mn4.js} +1 -1
- package/web/assets/{add-price-BpnICuHO.js → add-price-TdXAR3NW.js} +1 -1
- package/web/assets/{admin-CD8ViZ7D.js → admin-BpFv3eF5.js} +1 -1
- package/web/assets/{assign-0vMUDW_C.js → assign-DKRfmN7W.js} +1 -1
- package/web/assets/{attempts-CKlxkJuE.js → attempts-BfbYfiJa.js} +1 -1
- package/web/assets/browser-DF2vfpBa.js +1 -0
- package/web/assets/{change-payment-gAlRmJpv.js → change-payment-j5UC8_h0.js} +1 -1
- package/web/assets/{change-plan-C47wfWH8.js → change-plan-CtXvsIDw.js} +1 -1
- package/web/assets/{click-boundary-CafubiPp.js → click-boundary-Bi28Y0Fq.js} +1 -1
- package/web/assets/{connect-BHHzrwLA.js → connect-CXek4LAE.js} +1 -1
- package/web/assets/{copyable-QrCyyiou.js → copyable-CprMHdhV.js} +1 -1
- package/web/assets/{create-ke4FrPx1.js → create-B-Ubepl_.js} +1 -1
- package/web/assets/{create-DNar5UQD.js → create-BVt_sQ_7.js} +1 -1
- package/web/assets/{create-0PUtkJZY.js → create-BWviSWbC.js} +1 -1
- package/web/assets/{create-BJ1asdcy.js → create-C6jihslA.js} +1 -1
- package/web/assets/{create-C7GOgZZM.js → create-IaalYGmm.js} +1 -1
- package/web/assets/{create-Bgv5ux17.js → create-jzl1m8ZK.js} +1 -1
- package/web/assets/{credit-grant-item-list-CeDAM3qV.js → credit-grant-item-list-DQcvdSRs.js} +1 -1
- package/web/assets/{credit-overview-4zh0H02x.js → credit-overview-CPId2vzk.js} +1 -1
- package/web/assets/{currency-restrictions-BcEm8W45.js → currency-restrictions-Dsupz2ce.js} +1 -1
- package/web/assets/{currency-select-B4ieQBvv.js → currency-select-C8j7QQMP.js} +1 -1
- package/web/assets/{dayjs-DUTDpcNU.js → dayjs-DUNWtvju.js} +1 -1
- package/web/assets/{description-SnR5WxWT.js → description-BHxdy5I3.js} +1 -1
- package/web/assets/{detail-DNcp_u5S.js → detail-B17BN6kU.js} +1 -1
- package/web/assets/detail-BJ-hl5PK.js +10 -0
- package/web/assets/{detail-46aLUdJj.js → detail-BJEqTXDS.js} +1 -1
- package/web/assets/{detail-BQpDGZJQ.js → detail-BdC9VIc6.js} +1 -1
- package/web/assets/{detail-DbU3p040.js → detail-BkRkrKyw.js} +1 -1
- package/web/assets/{detail-DACnmls3.js → detail-BvcI9cB_.js} +1 -1
- package/web/assets/detail-C--ATvwm.js +24 -0
- package/web/assets/{detail-Cg505nKX.js → detail-CHJqYZ0W.js} +1 -1
- package/web/assets/{detail-B0IHl4MI.js → detail-CfvKZ7IV.js} +1 -1
- package/web/assets/{detail-Ct5QNBqu.js → detail-CmIweOLE.js} +1 -1
- package/web/assets/{detail-BXTsnQny.js → detail-D729Bgs6.js} +1 -1
- package/web/assets/{detail-C_Zdfa0y.js → detail-DD1YBtex.js} +1 -1
- package/web/assets/detail-DOcm4Kqg.js +15 -0
- package/web/assets/{detail-Bfnkg0A1.js → detail-DQj1mbhA.js} +1 -1
- package/web/assets/detail-DTXDMIR9.js +15 -0
- package/web/assets/{detail-CsGZMimg.js → detail-DUAJzKsu.js} +1 -1
- package/web/assets/{detail-BwH0DwAi.js → detail-De8PyTyx.js} +1 -1
- package/web/assets/{detail-B_lpOomD.js → detail-DqfxOHky.js} +1 -1
- package/web/assets/{detail-CMBRd4Ct.js → detail-Dzt5tfyZ.js} +1 -1
- package/web/assets/{detail-Tn2R5C8i.js → detail-H0dkKVyS.js} +1 -1
- package/web/assets/{detail-CyMhK5K_.js → detail-MgdgGj5J.js} +1 -1
- package/web/assets/{detail-DCTb8R7F.js → detail-WAmPM6yq.js} +1 -1
- package/web/assets/{detail-B-ceWfZr.js → detail-g6el9Fxj.js} +1 -1
- package/web/assets/did-Bqcz-NjH.js +1 -0
- package/web/assets/{drawer-form-DspWWj3x.js → drawer-form-CQjNFFWk.js} +1 -1
- package/web/assets/{edit-Bkj-OTJh.js → edit-DAU8AWzT.js} +1 -1
- package/web/assets/{editor-AmthipP2.js → editor-vZvxDUTl.js} +1 -1
- package/web/assets/{embed-rRKjDoHi.js → embed-ClYNqZbf.js} +1 -1
- package/web/assets/{filter-toolbar-DXGSTq57.js → filter-toolbar-VvmMATj0.js} +1 -1
- package/web/assets/{form-BmQlJZ84.js → form-4_MzglPj.js} +1 -1
- package/web/assets/{form-cX026J4G.js → form-AFzUvoFE.js} +1 -1
- package/web/assets/{form-B5WW-lS5.js → form-Bro99BjK.js} +1 -1
- package/web/assets/{form-CAPjlw7l.js → form-CnrBCyTJ.js} +1 -1
- package/web/assets/form-Cuvruf4H.js +16 -0
- package/web/assets/{gas-nyR96dB0.js → gas-kw2KMH1u.js} +1 -1
- package/web/assets/{generateCategoricalChart-BadryV3H.js → generateCategoricalChart-BCpuUeC_.js} +1 -1
- package/web/assets/{home-_eX1aim8.js → home-ZNJREzbw.js} +1 -1
- package/web/assets/{index-CbSXdD6E.js → index-ASk8vU2H.js} +1 -1
- package/web/assets/{index-ajD9Iotk.js → index-B4n6PvPu.js} +1 -1
- package/web/assets/{index-BarN7DfU.js → index-B4yaPb7B.js} +5 -5
- package/web/assets/{index-DSe7Dot_.js → index-BHwID_s4.js} +1 -1
- package/web/assets/index-BMcnd_jZ.js +1 -0
- package/web/assets/{index-BTfJ08JU.js → index-BRmN8ViQ.js} +1 -1
- package/web/assets/index-BdbLl6St.js +1 -0
- package/web/assets/{index-CCVDDX0c.js → index-BjKRyxNQ.js} +1 -1
- package/web/assets/index-BjLJQRKY.js +1 -0
- package/web/assets/index-BkNCPnTn.js +1 -0
- package/web/assets/index-BlAwTTmu.js +1 -0
- package/web/assets/{index-C136x0O2.js → index-BtWfmATr.js} +1 -1
- package/web/assets/{index-DNGmCIRP.js → index-C-5n472s.js} +1 -1
- package/web/assets/{index-CW8VfoJO.js → index-C3AP4jq0.js} +1 -1
- package/web/assets/{index-C-RT84yb.js → index-C3Rh1SaB.js} +1 -1
- package/web/assets/index-CDyxbCzc.js +1 -0
- package/web/assets/{index-SOzRg0yJ.js → index-CH_k9MVv.js} +1 -1
- package/web/assets/{index-XaFn2ySq.js → index-CKPfOW6M.js} +1 -1
- package/web/assets/{index-BQjlhCSt.js → index-CPFlZhA2.js} +1 -1
- package/web/assets/{index-Du0Ieh1F.js → index-CPyGjEd3.js} +2 -2
- package/web/assets/index-ChC-jsE2.js +1 -0
- package/web/assets/{index-D-bx9Kam.js → index-CiWvs3j9.js} +1 -1
- package/web/assets/{index-mn5Zdrtn.js → index-D6gv9jHh.js} +1 -1
- package/web/assets/{index-Cd_BD9TM.js → index-D7pWd60Z.js} +1 -1
- package/web/assets/{index-YG5oc8O3.js → index-DAen2-cr.js} +1 -1
- package/web/assets/{index-BRENdB5m.js → index-DNobX-Tr.js} +1 -1
- package/web/assets/{index-Kd_qCyRG.js → index-DY-g0BPU.js} +1 -1
- package/web/assets/{index-D0mynT6_.js → index-DZkpxY-C.js} +1 -1
- package/web/assets/{index-DcddP3R9.js → index-Dh9agU9O.js} +1 -1
- package/web/assets/{index-BBHMsIxJ.js → index-Dju8k6mq.js} +1 -1
- package/web/assets/{index-DeK5Pqjv.js → index-DwDNPqjF.js} +1 -1
- package/web/assets/{index-DEiuhiEo.js → index-Dze0CpfQ.js} +1 -1
- package/web/assets/{index-UYeD8rTJ.js → index-eDERHpkr.js} +1 -1
- package/web/assets/{index-BzABukCz.js → index-mgPU1lyd.js} +1 -1
- package/web/assets/{index-W2uZUlFs.js → index-olGOY5KB.js} +1 -1
- package/web/assets/{index-DoX0A-rP.js → index-oy7LrXGT.js} +1 -1
- package/web/assets/{index-qulrJQ4J.js → index-x7sBb6oM.js} +1 -1
- package/web/assets/{index.es-C8dcCHdW.js → index.es-C2Q6Owow.js} +1 -1
- package/web/assets/{info-card-BvIMFQo5.js → info-card-C9dRgztS.js} +1 -1
- package/web/assets/{info-metric-Dl4ZDm0Z.js → info-metric-ukWq8INi.js} +1 -1
- package/web/assets/{info-row-jI0h_hv4.js → info-row-CaPaNF4L.js} +1 -1
- package/web/assets/{info-row-group-CFuMWJf1.js → info-row-group-Cxo-4Gk5.js} +1 -1
- package/web/assets/{libphonenumber-Qs8PCdM-.js → libphonenumber-CTvobi0D.js} +1 -1
- package/web/assets/{link-CmPoIweR.js → link-DsltSF2Q.js} +1 -1
- package/web/assets/{list-CkHExntK.js → list-B2b-s8wM.js} +1 -1
- package/web/assets/{list-DLB_hd0Q.js → list-BzgF4i3i.js} +1 -1
- package/web/assets/{list-BdSkPjIa.js → list-Cd1O-aDi.js} +1 -1
- package/web/assets/{list-DaK9287Y.js → list-CvM46TsP.js} +1 -1
- package/web/assets/{list-CWMEf-_C.js → list-DtEjqlED.js} +1 -1
- package/web/assets/{list-DVFJwd_I.js → list-O_uCSLFq.js} +1 -1
- package/web/assets/{list-DghnUOc4.js → list-YNWVqjwW.js} +1 -1
- package/web/assets/{list-eFkvVlp5.js → list-ZaBapEXW.js} +1 -1
- package/web/assets/{metadata-BmQTVFku.js → metadata-_hV0ZaVh.js} +1 -1
- package/web/assets/{meter-event-B1JIhVpb.js → meter-event-CPVBpekF.js} +1 -1
- package/web/assets/{metrics-UvxyQbUF.js → metrics-DVPdwpyf.js} +1 -1
- package/web/assets/{overview-Cxc6WKba.js → overview-CGdVIJrJ.js} +1 -1
- package/web/assets/{overview-DrMaIptb.js → overview-CN59I5Sc.js} +1 -1
- package/web/assets/{past-due-CUXkxns0.js → past-due-C3PtU8uo.js} +1 -1
- package/web/assets/pay-XVdSNq__.js +4 -0
- package/web/assets/{payment-method-info-Bsf89VxV.js → payment-method-info-D_qR04xC.js} +1 -1
- package/web/assets/{preview-C-H8pGVw.js → preview-Bdtbh-xk.js} +1 -1
- package/web/assets/{preview-BifsgUGT.js → preview-F3lma170.js} +1 -1
- package/web/assets/{pricing-table-BUJdtkMq.js → pricing-table-Bt2WljzE.js} +1 -1
- package/web/assets/{pricing-table-B3QOaAB5.js → pricing-table-D9FGYBVa.js} +1 -1
- package/web/assets/{product-select-ChEyoJqJ.js → product-select-_72p-5lF.js} +1 -1
- package/web/assets/{recharge-BVT4USAO.js → recharge-CSlKshbU.js} +1 -1
- package/web/assets/{related-credit-grants-JV2ICsR5.js → related-credit-grants-DnKdAit6.js} +3 -3
- package/web/assets/{safe-did-address-CiG_V6Gy.js → safe-did-address-CRTPYo34.js} +1 -1
- package/web/assets/{source-data-viewer-i1q9wNIG.js → source-data-viewer-D1GShrs5.js} +1 -1
- package/web/assets/{status-CUVYrUIG.js → status-3Swm2gK5.js} +1 -1
- package/web/assets/subscription-BX00k6FU.js +1 -0
- package/web/assets/{subscription-DrnSPIfs.js → subscription-Bzeblscr.js} +1 -1
- package/web/assets/table-BN3WBnr3.js +1 -0
- package/web/assets/{tax-code-select-TS07I0rB.js → tax-code-select-j2arPbaE.js} +1 -1
- package/web/assets/{tax-utils-bPjALcVG.js → tax-utils-B8J0Kfnz.js} +1 -1
- package/web/assets/{uploader-CsQNHG4I.js → uploader-BLdAbLR6.js} +1 -1
- package/web/assets/{usage-records-DAUQMJAW.js → usage-records-BAwNs1y8.js} +1 -1
- package/web/assets/{util-DxXTXkeY.js → util-B8B3fsMa.js} +1 -1
- package/web/assets/{vendor-arcblock-BTCAQSUK.js → vendor-arcblock-D1drrE7q.js} +1 -1
- package/web/assets/{vendor-blocklet-DcLR2Cyf.js → vendor-blocklet-B67R14so.js} +2 -2
- package/web/index.html +1 -1
- package/web/assets/browser-DDv4_sgY.js +0 -1
- package/web/assets/detail-B8eOBVSQ.js +0 -15
- package/web/assets/detail-BO3zglCn.js +0 -15
- package/web/assets/detail-C1FupF1D.js +0 -24
- package/web/assets/detail-wU4wNf4s.js +0 -10
- package/web/assets/form-DD-EiA7W.js +0 -16
- package/web/assets/index-BhcoukR2.js +0 -1
- package/web/assets/index-BturOfxo.js +0 -1
- package/web/assets/index-CDVogp6E.js +0 -1
- package/web/assets/index-DcrGSDby.js +0 -1
- package/web/assets/index-Dybqd298.js +0 -1
- package/web/assets/index-EXZPddtw.js +0 -1
- package/web/assets/index-brUCsnBA.js +0 -1
- package/web/assets/pay-omLYkqRA.js +0 -4
- package/web/assets/subscription-BYz_k9dq.js +0 -1
- package/web/assets/table-BrtHemkA.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,A as d,w as x,B as o,a3 as r,bv as p,q as l,Y as f,bf as u}from"./vendor-mui-BXZut9Pz.js";import{V as j,P as h}from"./vendor-blocklet-
|
|
1
|
+
import{j as e,A as d,w as x,B as o,a3 as r,bv as p,q as l,Y as f,bf as u}from"./vendor-mui-BXZut9Pz.js";import{V as j,P as h}from"./vendor-blocklet-B67R14so.js";import{j as m,e as g}from"./index-B4yaPb7B.js";import{C as v}from"./copyable-CprMHdhV.js";import{I as i}from"./info-metric-ukWq8INi.js";import{S as b}from"./header-ivXuPt06.js";import{W as y}from"./attempts-BfbYfiJa.js";import{g as w}from"./util-B8B3fsMa.js";import"./vendor-react-BPknnnEA.js";import"./vendor-arcblock-D1drrE7q.js";import"./lodash-B4Ozcv0x.js";import"./info-card-C9dRgztS.js";const k=a=>g.get(`/api/events/${a}`).then(t=>t.data);function O(a){const{t}=j(),{loading:c,error:n,data:s}=h(()=>k(a.id));return n?e.jsx(d,{severity:"error",children:n.message}):c||!s?e.jsx(x,{}):e.jsxs(W,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(o,{children:[e.jsx(r,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(r,{direction:"row",onClick:()=>w("/admin/developers/events"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(p,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(l,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:t("admin.events.title")})]})}),e.jsxs(o,{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(r,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsx(l,{variant:"h2",sx:{fontWeight:600},children:s.type})}),e.jsxs(r,{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(i,{label:t("common.id"),value:e.jsx(v,{text:a.id,style:{marginLeft:4}})}),e.jsx(i,{label:t("admin.event.pendingWebhooks"),value:s.pending_webhooks,divider:!0}),e.jsx(i,{label:t("common.createdAt"),value:m(s.created_at),divider:!0}),e.jsx(i,{label:t("common.updatedAt"),value:m(s.updated_at)})]})]}),e.jsx(f,{})]}),e.jsxs(o,{className:"section",children:[e.jsx(b,{title:t("admin.event.webhooks")}),e.jsx(o,{className:"section-body",children:e.jsx(y,{event_id:s.id,event:s})})]})]})}const W=u(r)``;export{O 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 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)`
|
|
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-B67R14so.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-B4yaPb7B.js";import{a as le,L as oe}from"./vendor-react-BPknnnEA.js";import{C as ce}from"./copyable-CprMHdhV.js";import{C as A}from"./currency-GstdXsJf.js";import{E as de}from"./list-CvM46TsP.js";import{I as z}from"./info-metric-ukWq8INi.js";import{I as d}from"./info-row-CaPaNF4L.js";import{I as F}from"./info-row-group-Cxo-4Gk5.js";import{M as me}from"./editor-vZvxDUTl.js";import{M as ue}from"./list-B2b-s8wM.js";import{A as pe}from"./add-price-TdXAR3NW.js";import{P as xe,E as ge}from"./actions-D2-s31n3.js";import{S as y}from"./header-ivXuPt06.js";import{g as he}from"./util-B8B3fsMa.js";import"./table-BN3WBnr3.js";import"./lodash-B4Ozcv0x.js";import"./form-CnrBCyTJ.js";import"./form-AFzUvoFE.js";import"./collapse-CSrlJ0eG.js";import"./product-select-_72p-5lF.js";import"./currency-select-C8j7QQMP.js";import"./info-card-C9dRgztS.js";import"./uploader-BLdAbLR6.js";import"./tax-code-select-j2arPbaE.js";import"./collapse-BvbJGg1V.js";import"./actions-BEUwbsq1.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 {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,A as I,w as L,B as s,a3 as n,bv as $,q as m,O as z,Y as c,x as B,bf as G}from"./vendor-mui-BXZut9Pz.js";import{V as P,Y as H,P as O,Z as w}from"./vendor-blocklet-DcLR2Cyf.js";import{d as U,v as q,n as C,s as F,j as x,p as k,w as Y,e as T,k as V}from"./index-BarN7DfU.js";import{T as Z}from"./gas-nyR96dB0.js";import{L as f}from"./vendor-react-BPknnnEA.js";import{l as N}from"./lodash-B4Ozcv0x.js";import{C as J}from"./copyable-QrCyyiou.js";import{C as D}from"./currency-GstdXsJf.js";import{C as K}from"./link-CmPoIweR.js";import{E as Q}from"./list-DaK9287Y.js";import{I as i}from"./info-row-jI0h_hv4.js";import{D as X,R as ee,I as te}from"./related-credit-grants-JV2ICsR5.js";import{I as ae}from"./action-DENqSeOa.js";import{M as se}from"./editor-AmthipP2.js";import{M as ie}from"./list-CkHExntK.js";import{P as ne}from"./list-DghnUOc4.js";import{R as oe}from"./list-DLB_hd0Q.js";import{S as d}from"./header-ivXuPt06.js";import{g as re}from"./util-DxXTXkeY.js";import{I as h}from"./info-metric-Dl4ZDm0Z.js";import{I as le}from"./info-row-group-CFuMWJf1.js";import"./table-BrtHemkA.js";import"./browser-Bb9g-cvG.js";import"./usage-records-DAUQMJAW.js";import"./actions-BJDN6Op2.js";import"./click-boundary-CafubiPp.js";import"./generateCategoricalChart-BadryV3H.js";import"./form-CAPjlw7l.js";import"./cache-state-lld4zuDg.js";import"./filter-toolbar-DXGSTq57.js";import"./product-select-ChEyoJqJ.js";import"./info-card-BvIMFQo5.js";import"./actions-D3tJgrUn.js";import"./actions-0iWP2mcx.js";const me=p=>T.get(`/api/invoices/${p}?sync=true`).then(a=>a.data),M="column",S="flex-start";function Fe(p){const{t:a}=P(),{isMobile:y}=U(),[j,u]=H({adding:{price:!1},editing:{metadata:!1,product:!1},loading:{metadata:!1,price:!1,product:!1}}),{loading:R,error:b,data:t,runAsync:g}=O(()=>me(p.id));if(b)return e.jsx(I,{severity:"error",children:b.message});if(R||!t)return e.jsx(L,{});const E=(o=>async r=>{try{u(l=>({loading:{...l.loading,[o]:!0}})),await T.put(`/api/invoices/${p.id}`,r).then(l=>l.data),w.success(a("common.saved")),g()}catch(l){console.error(l),w.error(V(l))}finally{u(l=>({loading:{...l.loading,[o]:!1}}))}})("metadata"),v=()=>{u(o=>({editing:{...o.editing,metadata:!0}}))},W=o=>{let r=o;return r.startsWith("Slash stake")&&(r=a("payment.invoice.reason.slashStake")),r.startsWith("Subscription ")&&(r=a(`payment.invoice.reason.${r.replace("Subscription ","")}`)),r},_=t?.checkoutSession?.submit_type==="donate",A=["open","paid","uncollectible"].includes(t.status)&&!_&&!N.isEmpty(t.lines);return e.jsxs(ce,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(s,{children:[e.jsxs(n,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(n,{direction:"row",onClick:()=>re("/admin/billing/invoices"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx($,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(m,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:a("admin.invoices")})]}),e.jsxs(s,{style:{display:"flex",gap:"10px"},children:[A&&e.jsx(X,{data:t}),e.jsx(ae,{data:t,onChange:g,variant:"normal"})]})]}),t.status==="uncollectible"&&t.metadata?.slippage?.below_threshold&&e.jsx(I,{severity:"warning",sx:{mt:2},children:e.jsx(m,{variant:"body2",children:a("payment.customer.invoice.slippageExceededDetail",{currentRate:t.metadata.slippage.rate_at_invoice||"—",minRate:t.metadata.slippage.min_acceptable_rate||"—"})})}),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(n,{direction:"column",sx:{gap:1},children:[e.jsxs(n,{direction:"row",sx:{alignItems:"center"},children:[e.jsx(m,{variant:"h2",sx:{fontWeight:600},children:t.number}),e.jsx(m,{variant:"h2",sx:{fontWeight:600,mx:1},children:"for"}),e.jsxs(m,{variant:"h2",sx:{fontWeight:600},children:[q(t.total,t.paymentCurrency.decimal)," ",t.paymentCurrency.symbol]})]}),e.jsx(J,{text:p.id,style:{marginLeft:4}})]}),e.jsxs(n,{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(h,{label:a("common.status"),value:e.jsxs(n,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(C,{label:t.status,color:F(t.status)}),t.status==="uncollectible"&&t.metadata?.slippage?.below_threshold&&e.jsx(z,{title:a("payment.customer.invoice.slippageExceededDetail",{currentRate:t.metadata.slippage.rate_at_invoice||"—",minRate:t.metadata.slippage.min_acceptable_rate||"—"}),arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(C,{label:a("payment.customer.invoice.slippageExceeded"),color:"warning"})})})]}),divider:!0}),t.subscription&&e.jsx(h,{label:a("admin.subscription.name"),value:e.jsx(f,{to:`/admin/billing/${t.subscription.id}`,children:e.jsx(m,{variant:"body1",sx:{color:"text.link"},children:t.subscription.description||t.subscription.id})}),divider:!0}),e.jsx(h,{label:a("common.createdAt"),value:x(t.created_at),divider:!0}),e.jsx(h,{label:a("admin.subscription.currentPeriod"),value:t.period_start&&t.period_end?[x(t.period_start*1e3),x(t.period_end*1e3)].join(" ~ "):""})]})]}),e.jsx(c,{})]}),e.jsxs(n,{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(d,{title:a("admin.details")}),e.jsxs(le,{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"}},".currency-name":{color:"text.secondary"}},children:[e.jsx(i,{label:a("admin.invoice.billTo"),value:e.jsx(K,{customer:t.customer,size:y?"default":"small"})}),e.jsx(i,{label:a("admin.invoice.from"),value:t.statement_descriptor||blocklet.appName}),e.jsx(i,{label:a("admin.invoice.description"),value:W(t.description||"")}),e.jsx(i,{label:a("admin.invoice.billing"),value:t.collection_method}),t.status_transitions?.finalized_at&&e.jsx(i,{label:a("admin.invoice.finalizedAt"),value:x(t.status_transitions.finalized_at*1e3)}),t.status_transitions?.paid_at&&e.jsx(i,{label:a("admin.invoice.paidAt"),value:x(t.status_transitions.paid_at*1e3)}),e.jsx(i,{label:a("admin.paymentMethod._name"),value:e.jsx(D,{logo:t.paymentMethod?.logo,name:t.paymentMethod?.name})}),e.jsx(i,{label:a("admin.paymentCurrency.name"),value:e.jsx(D,{logo:t.paymentCurrency.logo,name:`${t.paymentCurrency.symbol} (${t.paymentMethod?.name})`})}),(!!t.paymentIntent?.payment_details?.ethereum||!!t.paymentIntent?.payment_details?.base)&&e.jsx(i,{label:a("common.txGas"),value:e.jsx(Z,{details:t.paymentIntent.payment_details,method:t.paymentMethod})}),t.paymentIntent&&t.paymentIntent.payment_details&&e.jsx(i,{label:a(`common.${t.paymentIntent.payment_details?.arcblock?.type||"transfer"}TxHash`),value:e.jsx(k,{details:t.paymentIntent.payment_details,method:t.paymentMethod,mode:"customer"})}),["stake","stake_overdraft_protection"].includes(t.billing_reason)&&t?.metadata?.payment_details?.arcblock?.tx_hash&&e.jsx(i,{label:a("common.stakeTxHash"),value:e.jsx(k,{details:{arcblock:{tx_hash:t.metadata?.payment_details?.arcblock?.tx_hash,payer:""}},method:t.paymentMethod})})]})]}),t?.relatedCreditGrants&&t.relatedCreditGrants.length>0&&e.jsx(ee,{grants:t.relatedCreditGrants,mode:"dashboard"}),e.jsx(c,{}),e.jsxs(s,{className:"section",children:[e.jsx(d,{title:a("admin.summary")}),e.jsx(m,{variant:"body2",sx:{color:"text.secondary",mb:2,fontSize:"0.875rem"},children:a("admin.invoice.billingContextNote")}),e.jsx(s,{className:"section-body",children:e.jsx(te,{invoice:t,emptyNodeText:a("empty.summary"),mode:"admin"})})]}),e.jsx(c,{}),_&&!N.isEmpty(t.paymentIntent?.beneficiaries)&&e.jsxs(e.Fragment,{children:[e.jsx(s,{className:"section",children:e.jsx(m,{variant:"h3",className:"section-header",children:a("customer.invoice.donation")})}),e.jsx(s,{sx:{maxWidth:800},children:e.jsx(Y,{data:t?.paymentIntent?.beneficiaries,currency:t.paymentCurrency,totalAmount:t?.amount_paid})}),e.jsx(c,{})]}),e.jsxs(s,{className:"section",children:[e.jsx(d,{title:a("admin.payments")}),e.jsx(s,{className:"section-body",children:e.jsx(ne,{features:{customer:!1,toolbar:!1},invoice_id:t.id})})]}),e.jsx(c,{}),e.jsxs(s,{className:"section",children:[e.jsx(d,{title:a("admin.refunds")}),e.jsx(s,{className:"section-body",children:e.jsx(oe,{features:{customer:!1,toolbar:!1},invoice_id:t.id})})]}),e.jsx(c,{}),e.jsxs(s,{className:"section",children:[e.jsx(d,{title:a("admin.events.title")}),e.jsx(s,{className:"section-body",children:e.jsx(Q,{features:{toolbar:!1},object_id:[t.id,t.payment_intent_id].filter(Boolean).join(",")})})]})]}),y&&e.jsx(c,{}),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(d,{title:a("admin.connections")}),e.jsxs(n,{children:[e.jsx(i,{label:a("admin.subscription.name"),value:t.subscription?e.jsx(f,{to:`/admin/billing/${t.subscription.id}`,children:t.subscription.id}):"",direction:M,alignItems:S}),e.jsx(i,{label:a("admin.paymentIntent.name"),value:t.payment_intent_id?e.jsx(f,{to:`/admin/payments/${t.payment_intent_id}`,children:t.payment_intent_id}):"",direction:M,alignItems:S})]})]}),e.jsx(c,{}),e.jsxs(s,{className:"section",children:[e.jsx(d,{title:a("common.metadata.label"),children:e.jsx(B,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:j.editing.metadata,onClick:v,children:a("common.edit")})}),e.jsxs(s,{className:"section-body",children:[e.jsx(ie,{data:t.metadata,handleEditMetadata:v}),j.editing.metadata&&e.jsx(se,{data:t,loading:j.loading.metadata,onSave:E,onCancel:()=>u(o=>({editing:{...o.editing,metadata:!1}}))})]})]})]})]})]})}const ce=G(n)``;export{Fe as default};
|
|
1
|
+
import{j as e,A as I,w as L,B as s,a3 as n,bv as $,q as m,O as z,Y as c,x as B,bf as G}from"./vendor-mui-BXZut9Pz.js";import{V as P,Y as H,P as O,Z as w}from"./vendor-blocklet-B67R14so.js";import{d as U,v as q,n as C,s as F,j as x,p as k,w as Y,e as T,k as V}from"./index-B4yaPb7B.js";import{T as Z}from"./gas-kw2KMH1u.js";import{L as f}from"./vendor-react-BPknnnEA.js";import{l as N}from"./lodash-B4Ozcv0x.js";import{C as J}from"./copyable-CprMHdhV.js";import{C as D}from"./currency-GstdXsJf.js";import{C as K}from"./link-DsltSF2Q.js";import{E as Q}from"./list-CvM46TsP.js";import{I as i}from"./info-row-CaPaNF4L.js";import{D as X,R as ee,I as te}from"./related-credit-grants-DnKdAit6.js";import{I as ae}from"./action-C2c0yWuW.js";import{M as se}from"./editor-vZvxDUTl.js";import{M as ie}from"./list-B2b-s8wM.js";import{P as ne}from"./list-YNWVqjwW.js";import{R as oe}from"./list-BzgF4i3i.js";import{S as d}from"./header-ivXuPt06.js";import{g as re}from"./util-B8B3fsMa.js";import{I as h}from"./info-metric-ukWq8INi.js";import{I as le}from"./info-row-group-Cxo-4Gk5.js";import"./table-BN3WBnr3.js";import"./browser-Bb9g-cvG.js";import"./usage-records-BAwNs1y8.js";import"./actions-BEUwbsq1.js";import"./click-boundary-Bi28Y0Fq.js";import"./generateCategoricalChart-BCpuUeC_.js";import"./form-CnrBCyTJ.js";import"./cache-state-lld4zuDg.js";import"./filter-toolbar-VvmMATj0.js";import"./product-select-_72p-5lF.js";import"./info-card-C9dRgztS.js";import"./actions-JHsqbHpB.js";import"./actions-DeCPtfTK.js";const me=p=>T.get(`/api/invoices/${p}?sync=true`).then(a=>a.data),M="column",S="flex-start";function Fe(p){const{t:a}=P(),{isMobile:y}=U(),[j,u]=H({adding:{price:!1},editing:{metadata:!1,product:!1},loading:{metadata:!1,price:!1,product:!1}}),{loading:R,error:b,data:t,runAsync:g}=O(()=>me(p.id));if(b)return e.jsx(I,{severity:"error",children:b.message});if(R||!t)return e.jsx(L,{});const E=(o=>async r=>{try{u(l=>({loading:{...l.loading,[o]:!0}})),await T.put(`/api/invoices/${p.id}`,r).then(l=>l.data),w.success(a("common.saved")),g()}catch(l){console.error(l),w.error(V(l))}finally{u(l=>({loading:{...l.loading,[o]:!1}}))}})("metadata"),v=()=>{u(o=>({editing:{...o.editing,metadata:!0}}))},W=o=>{let r=o;return r.startsWith("Slash stake")&&(r=a("payment.invoice.reason.slashStake")),r.startsWith("Subscription ")&&(r=a(`payment.invoice.reason.${r.replace("Subscription ","")}`)),r},_=t?.checkoutSession?.submit_type==="donate",A=["open","paid","uncollectible"].includes(t.status)&&!_&&!N.isEmpty(t.lines);return e.jsxs(ce,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(s,{children:[e.jsxs(n,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(n,{direction:"row",onClick:()=>re("/admin/billing/invoices"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx($,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(m,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:a("admin.invoices")})]}),e.jsxs(s,{style:{display:"flex",gap:"10px"},children:[A&&e.jsx(X,{data:t}),e.jsx(ae,{data:t,onChange:g,variant:"normal"})]})]}),t.status==="uncollectible"&&t.metadata?.slippage?.below_threshold&&e.jsx(I,{severity:"warning",sx:{mt:2},children:e.jsx(m,{variant:"body2",children:a("payment.customer.invoice.slippageExceededDetail",{currentRate:t.metadata.slippage.rate_at_invoice||"—",minRate:t.metadata.slippage.min_acceptable_rate||"—"})})}),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(n,{direction:"column",sx:{gap:1},children:[e.jsxs(n,{direction:"row",sx:{alignItems:"center"},children:[e.jsx(m,{variant:"h2",sx:{fontWeight:600},children:t.number}),e.jsx(m,{variant:"h2",sx:{fontWeight:600,mx:1},children:"for"}),e.jsxs(m,{variant:"h2",sx:{fontWeight:600},children:[q(t.total,t.paymentCurrency.decimal)," ",t.paymentCurrency.symbol]})]}),e.jsx(J,{text:p.id,style:{marginLeft:4}})]}),e.jsxs(n,{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(h,{label:a("common.status"),value:e.jsxs(n,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(C,{label:t.status,color:F(t.status)}),t.status==="uncollectible"&&t.metadata?.slippage?.below_threshold&&e.jsx(z,{title:a("payment.customer.invoice.slippageExceededDetail",{currentRate:t.metadata.slippage.rate_at_invoice||"—",minRate:t.metadata.slippage.min_acceptable_rate||"—"}),arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(C,{label:a("payment.customer.invoice.slippageExceeded"),color:"warning"})})})]}),divider:!0}),t.subscription&&e.jsx(h,{label:a("admin.subscription.name"),value:e.jsx(f,{to:`/admin/billing/${t.subscription.id}`,children:e.jsx(m,{variant:"body1",sx:{color:"text.link"},children:t.subscription.description||t.subscription.id})}),divider:!0}),e.jsx(h,{label:a("common.createdAt"),value:x(t.created_at),divider:!0}),e.jsx(h,{label:a("admin.subscription.currentPeriod"),value:t.period_start&&t.period_end?[x(t.period_start*1e3),x(t.period_end*1e3)].join(" ~ "):""})]})]}),e.jsx(c,{})]}),e.jsxs(n,{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(d,{title:a("admin.details")}),e.jsxs(le,{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"}},".currency-name":{color:"text.secondary"}},children:[e.jsx(i,{label:a("admin.invoice.billTo"),value:e.jsx(K,{customer:t.customer,size:y?"default":"small"})}),e.jsx(i,{label:a("admin.invoice.from"),value:t.statement_descriptor||blocklet.appName}),e.jsx(i,{label:a("admin.invoice.description"),value:W(t.description||"")}),e.jsx(i,{label:a("admin.invoice.billing"),value:t.collection_method}),t.status_transitions?.finalized_at&&e.jsx(i,{label:a("admin.invoice.finalizedAt"),value:x(t.status_transitions.finalized_at*1e3)}),t.status_transitions?.paid_at&&e.jsx(i,{label:a("admin.invoice.paidAt"),value:x(t.status_transitions.paid_at*1e3)}),e.jsx(i,{label:a("admin.paymentMethod._name"),value:e.jsx(D,{logo:t.paymentMethod?.logo,name:t.paymentMethod?.name})}),e.jsx(i,{label:a("admin.paymentCurrency.name"),value:e.jsx(D,{logo:t.paymentCurrency.logo,name:`${t.paymentCurrency.symbol} (${t.paymentMethod?.name})`})}),(!!t.paymentIntent?.payment_details?.ethereum||!!t.paymentIntent?.payment_details?.base)&&e.jsx(i,{label:a("common.txGas"),value:e.jsx(Z,{details:t.paymentIntent.payment_details,method:t.paymentMethod})}),t.paymentIntent&&t.paymentIntent.payment_details&&e.jsx(i,{label:a(`common.${t.paymentIntent.payment_details?.arcblock?.type||"transfer"}TxHash`),value:e.jsx(k,{details:t.paymentIntent.payment_details,method:t.paymentMethod,mode:"customer"})}),["stake","stake_overdraft_protection"].includes(t.billing_reason)&&t?.metadata?.payment_details?.arcblock?.tx_hash&&e.jsx(i,{label:a("common.stakeTxHash"),value:e.jsx(k,{details:{arcblock:{tx_hash:t.metadata?.payment_details?.arcblock?.tx_hash,payer:""}},method:t.paymentMethod})})]})]}),t?.relatedCreditGrants&&t.relatedCreditGrants.length>0&&e.jsx(ee,{grants:t.relatedCreditGrants,mode:"dashboard"}),e.jsx(c,{}),e.jsxs(s,{className:"section",children:[e.jsx(d,{title:a("admin.summary")}),e.jsx(m,{variant:"body2",sx:{color:"text.secondary",mb:2,fontSize:"0.875rem"},children:a("admin.invoice.billingContextNote")}),e.jsx(s,{className:"section-body",children:e.jsx(te,{invoice:t,emptyNodeText:a("empty.summary"),mode:"admin"})})]}),e.jsx(c,{}),_&&!N.isEmpty(t.paymentIntent?.beneficiaries)&&e.jsxs(e.Fragment,{children:[e.jsx(s,{className:"section",children:e.jsx(m,{variant:"h3",className:"section-header",children:a("customer.invoice.donation")})}),e.jsx(s,{sx:{maxWidth:800},children:e.jsx(Y,{data:t?.paymentIntent?.beneficiaries,currency:t.paymentCurrency,totalAmount:t?.amount_paid})}),e.jsx(c,{})]}),e.jsxs(s,{className:"section",children:[e.jsx(d,{title:a("admin.payments")}),e.jsx(s,{className:"section-body",children:e.jsx(ne,{features:{customer:!1,toolbar:!1},invoice_id:t.id})})]}),e.jsx(c,{}),e.jsxs(s,{className:"section",children:[e.jsx(d,{title:a("admin.refunds")}),e.jsx(s,{className:"section-body",children:e.jsx(oe,{features:{customer:!1,toolbar:!1},invoice_id:t.id})})]}),e.jsx(c,{}),e.jsxs(s,{className:"section",children:[e.jsx(d,{title:a("admin.events.title")}),e.jsx(s,{className:"section-body",children:e.jsx(Q,{features:{toolbar:!1},object_id:[t.id,t.payment_intent_id].filter(Boolean).join(",")})})]})]}),y&&e.jsx(c,{}),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(d,{title:a("admin.connections")}),e.jsxs(n,{children:[e.jsx(i,{label:a("admin.subscription.name"),value:t.subscription?e.jsx(f,{to:`/admin/billing/${t.subscription.id}`,children:t.subscription.id}):"",direction:M,alignItems:S}),e.jsx(i,{label:a("admin.paymentIntent.name"),value:t.payment_intent_id?e.jsx(f,{to:`/admin/payments/${t.payment_intent_id}`,children:t.payment_intent_id}):"",direction:M,alignItems:S})]})]}),e.jsx(c,{}),e.jsxs(s,{className:"section",children:[e.jsx(d,{title:a("common.metadata.label"),children:e.jsx(B,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:j.editing.metadata,onClick:v,children:a("common.edit")})}),e.jsxs(s,{className:"section-body",children:[e.jsx(ie,{data:t.metadata,handleEditMetadata:v}),j.editing.metadata&&e.jsx(se,{data:t,loading:j.loading.metadata,onSave:E,onCancel:()=>u(o=>({editing:{...o.editing,metadata:!1}}))})]})]})]})]})]})}const ce=G(n)``;export{Fe 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-B67R14so.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-B4yaPb7B.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-DsltSF2Q.js";import{I as se}from"./info-metric-ukWq8INi.js";import{I as l}from"./info-row-CaPaNF4L.js";import{I as Ye}from"./info-row-group-Cxo-4Gk5.js";import{S as Ze}from"./description-BHxdy5I3.js";import{P as Je,D as Qe,S as Xe,V as et}from"./payment-method-info-D_qR04xC.js";import{S as tt}from"./metrics-DVPdwpyf.js";import{S as rt}from"./actions-DtNZGZWf.js";import{u as nt,a as st,b as at}from"./subscription-Bzeblscr.js";import{f as it}from"./dayjs-DUNWtvju.js";import{c as ot}from"./util-B8B3fsMa.js";import{i as ct}from"./did-Bqcz-NjH.js";import{u as lt}from"./browser-DF2vfpBa.js";import"./copyable-CprMHdhV.js";import"./usage-records-BAwNs1y8.js";import"./actions-BEUwbsq1.js";import"./click-boundary-Bi28Y0Fq.js";import"./generateCategoricalChart-BCpuUeC_.js";import"./status-3Swm2gK5.js";import"./lodash-B4Ozcv0x.js";const I={mode:"percent",percent:.5},dt=s=>D.get(`/api/subscriptions/${s}`).then(x=>x.data),mt=s=>D.get(`/api/subscriptions/${s}/overdraft-protection`).then(x=>x.data),pt=(s,x)=>D.get(`/api/subscriptions/${s}/cycle-amount`,{params:x}).then(r=>r.data);function Ut(){const{id:s}=Ge(),x=qe(),{t:r,locale:ae}=Te(),{isMobile:d}=We(),{session:$}=Oe(),{connect:z}=Le(),ie=lt(),{loading:oe,error:U,data:t,refresh:_}=W(()=>dt(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(()=>mt(s),{ready:E}),V=_e(),{data:ue={amount:"0",gas:"0"}}=W(()=>pt(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&&!ct(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(ut,{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 ut=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{Ut as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,A,w as R,B as n,a3 as i,bv as T,q as $,N as E,Y as d,O as B,be as L,x as W,bf as z}from"./vendor-mui-BXZut9Pz.js";import{V as O,Y as H,P as q,Z as _}from"./vendor-blocklet-
|
|
1
|
+
import{j as e,A,w as R,B as n,a3 as i,bv as T,q as $,N as E,Y as d,O as B,be as L,x as W,bf as z}from"./vendor-mui-BXZut9Pz.js";import{V as O,Y as H,P as q,Z as _}from"./vendor-blocklet-B67R14so.js";import{d as G,i as P,a5 as U,n as I,bd as w,j,p as F,e as M,k as Y}from"./index-B4yaPb7B.js";import{T as J}from"./gas-kw2KMH1u.js";import{L as u}from"./vendor-react-BPknnnEA.js";import{l as V}from"./lodash-B4Ozcv0x.js";import{C as Z}from"./copyable-CprMHdhV.js";import{C as K}from"./link-DsltSF2Q.js";import{E as Q}from"./list-CvM46TsP.js";import{I as C}from"./info-metric-ukWq8INi.js";import{I as s}from"./info-row-CaPaNF4L.js";import{M as X}from"./editor-vZvxDUTl.js";import{M as ee}from"./list-B2b-s8wM.js";import{R as te}from"./actions-DeCPtfTK.js";import{S as x}from"./header-ivXuPt06.js";import{g as ae}from"./util-B8B3fsMa.js";import{I as se}from"./info-row-group-Cxo-4Gk5.js";import"./table-BN3WBnr3.js";import"./form-CnrBCyTJ.js";import"./actions-BEUwbsq1.js";import"./click-boundary-Bi28Y0Fq.js";const ne=c=>M.get(`/api/refunds/${c}`).then(a=>a.data),o="column",r="flex-start";function Se(c){const{t:a}=O(),{isMobile:k}=G(),[f,p]=H({adding:{price:!1},editing:{metadata:!1,product:!1},loading:{metadata:!1,price:!1,product:!1}}),{loading:S,error:h,data:t,runAsync:y}=q(()=>ne(c.id));if(h)return e.jsx(A,{severity:"error",children:h.message});if(S||!t)return e.jsx(R,{});const N=(m=>async D=>{try{p(l=>({loading:{...l.loading,[m]:!0}})),await M.put(`/api/refunds/${c.id}`,D).then(l=>l.data),_.success(a("common.saved")),y()}catch(l){console.error(l),_.error(Y(l))}finally{p(l=>({loading:{...l.loading,[m]:!1}}))}})("metadata"),g=t.paymentCurrency,b=[P(t?.amount,g.decimal),g.symbol].join(" "),v=()=>{p(m=>({editing:{...m.editing,metadata:!0}}))};return e.jsxs(ie,{direction:"column",spacing:2.5,mb:4,children:[e.jsxs(n,{children:[e.jsxs(i,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(i,{direction:"row",onClick:()=>ae("/admin/payments/refunds"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(T,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx($,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:a("admin.refunds")})]}),e.jsx(te,{data:t,variant:"normal",onChange:()=>y()})]}),e.jsxs(n,{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(i,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(i,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(E,{src:t.paymentCurrency.logo,alt:t.paymentCurrency.symbol,variant:"square",sx:{width:"52px",height:"52px",borderRadius:.5}}),e.jsxs(i,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:[e.jsx(U,{amount:b,sx:{my:0,fontSize:"1.75rem",lineHeight:"32px"}}),e.jsx(Z,{text:c.id})]})]})}),e.jsxs(i,{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(C,{label:a("common.status"),value:e.jsx(I,{label:t.status,color:w(t.status)}),divider:!0}),e.jsx(C,{label:a("common.customer"),value:e.jsx(K,{customer:t.customer})})]})]}),e.jsx(d,{})]}),e.jsxs(i,{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(n,{className:"payment-link-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(n,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(x,{title:a("admin.details")}),e.jsxs(se,{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(s,{label:a("common.status"),value:e.jsxs(i,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(I,{label:t.status,color:w(t.status)}),t.last_attempt_error&&t.status!=="canceled"&&e.jsx(B,{title:e.jsx("pre",{style:{whiteSpace:"break-spaces"},children:JSON.stringify({...t.last_attempt_error,next_attempt:t.next_attempt?j(t.next_attempt*1e3):"-",attempt_count:t.attempt_count,type:V.startCase(t.last_attempt_error?.type)},null,2)}),children:e.jsx(L,{fontSize:"small",color:"error"})})]})}),e.jsx(s,{label:a("common.amount"),value:b}),e.jsx(s,{label:a("common.type"),value:a(`refund.type.${t.type}`)}),e.jsx(s,{label:a("common.createdAt"),value:j(t.created_at)}),e.jsx(s,{label:a("common.description"),value:t.description}),e.jsx(s,{label:a("common.updatedAt"),value:j(t.updated_at)})]})]}),e.jsx(d,{}),e.jsxs(n,{className:"section",children:[e.jsx(x,{title:a("admin.events.title")}),e.jsx(n,{className:"section-body",children:e.jsx(Q,{features:{toolbar:!1},object_id:t.id})})]})]}),k&&e.jsx(d,{}),e.jsxs(n,{className:"payment-link-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:[t.paymentMethod&&e.jsxs(e.Fragment,{children:[e.jsxs(n,{className:"section",children:[e.jsx(x,{title:a("admin.paymentMethod._name")}),e.jsxs(i,{children:[e.jsx(s,{label:a("common.id"),value:t.paymentMethod.id,direction:o,alignItems:r}),e.jsx(s,{label:a("admin.paymentMethod.type"),value:t.paymentMethod.type,direction:o,alignItems:r}),e.jsx(s,{label:a("admin.paymentCurrency.name"),value:`${t.paymentCurrency.symbol} (${t.paymentMethod.name})`,direction:o,alignItems:r}),(!!t.payment_details?.ethereum||!!t.payment_details?.base)&&e.jsx(s,{label:a("common.txGas"),value:e.jsx(J,{details:t.payment_details,method:t.paymentMethod}),direction:o,alignItems:r}),e.jsx(s,{label:a("common.txHash"),value:e.jsx(F,{details:t.payment_details,method:t.paymentMethod}),direction:o,alignItems:r})]})]}),e.jsx(d,{})]}),e.jsxs(n,{className:"section",children:[e.jsx(x,{title:a("admin.connections")}),e.jsxs(i,{children:[e.jsx(s,{label:a("admin.subscription.name"),value:t.subscription?e.jsx(u,{to:`/admin/billing/${t.subscription.id}`,children:t.subscription.id}):"",direction:o,alignItems:r}),e.jsx(s,{label:a("admin.invoice.name"),value:t.invoice_id?e.jsx(u,{to:`/admin/billing/${t.invoice_id}`,children:t.invoice_id}):"",direction:o,alignItems:r}),e.jsx(s,{label:a("admin.customers"),value:t.customer_id?e.jsx(u,{to:`/admin/customers/${t.customer_id}`,children:t.customer_id}):"",direction:o,alignItems:r}),e.jsx(s,{label:a("admin.payments"),value:t.payment_intent_id?e.jsx(u,{to:`/admin/payments/${t.payment_intent_id}`,children:t.payment_intent_id}):"",direction:o,alignItems:r})]})]}),e.jsx(d,{}),e.jsxs(n,{className:"section",children:[e.jsx(x,{title:a("common.metadata.label"),children:e.jsx(W,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:f.editing.metadata,onClick:v,children:a("common.edit")})}),e.jsxs(n,{className:"section-body",children:[e.jsx(ee,{data:t.metadata,handleEditMetadata:v}),f.editing.metadata&&e.jsx(X,{data:t,loading:f.loading.metadata,onSave:N,onCancel:()=>p(m=>({editing:{...m.editing,metadata:!1}}))})]})]})]})]})]})}const ie=z(i)``;export{Se as default};
|
|
@@ -0,0 +1,15 @@
|
|
|
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 S,N as d,Y as u,bf as T}from"./vendor-mui-BXZut9Pz.js";import{V as k,P as Y}from"./vendor-blocklet-B67R14so.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-B4yaPb7B.js";import{I as n}from"./info-metric-ukWq8INi.js";import{S as y}from"./header-ivXuPt06.js";import{C as W}from"./credit-grant-item-list-DQcvdSRs.js";import{I as l}from"./info-row-CaPaNF4L.js";import{I as z}from"./info-row-group-Cxo-4Gk5.js";import{u as L}from"./browser-DF2vfpBa.js";import{i as $}from"./did-Bqcz-NjH.js";import{e as q,a as E}from"./vendor-react-BPknnnEA.js";import"./util-B8B3fsMa.js";import"./lodash-B4Ozcv0x.js";import"./copyable-CprMHdhV.js";const O=o=>R.get(`/api/credit-grants/${o}`).then(c=>c.data);function ce(){const{id:o}=q(),c=E(),{t:r}=k(),{session:p}=M(),v=L(),{loading:b,error:h,data:t}=Y(()=>O(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(U,{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(S,{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 U=T(s)`
|
|
2
|
+
margin-bottom: 24px;
|
|
3
|
+
gap: 24px;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
@media (max-width: ${({theme:o})=>o.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{ce as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as M,j as e,A as B,w as E,B as s,a3 as i,bv as W,q as o,x as b,N as g,Y as x,bf as F}from"./vendor-mui-BXZut9Pz.js";import{V as P,Y as L,P as R,Z as v}from"./vendor-blocklet-
|
|
1
|
+
import{r as M,j as e,A as B,w as E,B as s,a3 as i,bv as W,q as o,x as b,N as g,Y as x,bf as F}from"./vendor-mui-BXZut9Pz.js";import{V as P,Y as L,P as R,Z as v}from"./vendor-blocklet-B67R14so.js";import{k as w,a2 as $,a3 as C,i as _,N as z,j as h,p as H,A as O,e as I}from"./index-B4yaPb7B.js";import{I as u}from"./info-metric-ukWq8INi.js";import{I as c}from"./info-row-CaPaNF4L.js";import{I as q}from"./info-row-group-Cxo-4Gk5.js";import{C as U}from"./copyable-CprMHdhV.js";import{S as l}from"./header-ivXuPt06.js";import{M as Y}from"./list-B2b-s8wM.js";import{M as V}from"./editor-vZvxDUTl.js";import{C as Z}from"./credit-grant-item-list-DQcvdSRs.js";import{g as J}from"./util-B8B3fsMa.js";import{E as K}from"./list-CvM46TsP.js";import{a as Q}from"./vendor-react-BPknnnEA.js";import"./lodash-B4Ozcv0x.js";import"./form-CnrBCyTJ.js";import"./table-BN3WBnr3.js";const X=d=>I.get(`/api/credit-grants/${d}`).then(a=>a.data);function fe({id:d}){const{t:a}=P(),N=Q(),[p,m]=L({editing:{metadata:!1,creditGrant:!1},loading:{metadata:!1,creditGrant:!1}}),{loading:D,error:j,data:t,runAsync:G}=R(()=>X(d)),k=M.useCallback(()=>{J("/admin/customers")},[]);if(j)return e.jsx(B,{severity:"error",children:w(j)});if(D||!t)return e.jsx(E,{});const f=t?.status==="depleted",S=r=>{switch(r){case"granted":return a("admin.customer.creditGrants.status.granted");case"pending":return a("admin.customer.creditGrants.status.pending");case"depleted":return a("admin.customer.creditGrants.status.depleted");case"expired":return a("admin.customer.creditGrants.status.expired");case"voided":return a("admin.customer.creditGrants.status.voided");default:return r}},A=()=>{if(!t.amount||!t.remaining_amount)return 0;const r=parseFloat(t.amount),n=parseFloat(t.remaining_amount);return(r-n)/r*100},T=async r=>{try{m(n=>({loading:{...n.loading,metadata:!0}})),await I.put(`/api/credit-grants/${d}`,r),v.success(a("common.saved")),G()}catch(n){console.error(n),v.error(w(n))}finally{m(n=>({loading:{...n.loading,metadata:!1}}))}},y=()=>{m(r=>({editing:{...r.editing,metadata:!0}}))};return e.jsxs(ee,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(s,{children:[e.jsxs(i,{className:"page-header",direction:"row",justifyContent:"space-between",alignItems:"center",children:[e.jsxs(i,{direction:"row",alignItems:"center",sx:{fontWeight:"normal",cursor:"pointer"},onClick:k,children:[e.jsx(W,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(o,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:a("admin.customer.creditGrants.title")})]}),t.metadata.invoice_id&&e.jsx(b,{variant:"outlined",size:"small",onClick:()=>N(`/admin/billing/${t.metadata.invoice_id}`),children:a("admin.customer.creditGrants.viewInvoice")})]}),e.jsxs(s,{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(i,{direction:"row",justifyContent:"space-between",alignItems:"center",children:e.jsxs(i,{direction:"column",spacing:.5,children:[e.jsx(o,{variant:"h2",sx:{fontWeight:600},children:t.name||`${a("admin.customer.creditGrants.grant")} ${t.id.slice(-8)}`}),e.jsx(U,{text:t.id})]})}),e.jsxs(i,{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(u,{label:a("common.status"),value:e.jsx($,{status:t.status,label:S(t.status)}),divider:!0}),e.jsx(u,{label:a("admin.customer.creditGrants.originalAmount"),value:e.jsxs(i,{direction:"row",alignItems:"center",spacing:.5,children:[e.jsx(g,{src:t.paymentCurrency?.logo,sx:{width:16,height:16},alt:t.paymentCurrency?.symbol}),e.jsx(o,{variant:"body2",sx:{color:"text.secondary"},children:C(_(t.amount,t.paymentCurrency.decimal),t.paymentCurrency.symbol)})]}),divider:!0}),e.jsx(u,{label:a("common.remainingCredit"),value:e.jsxs(i,{direction:"row",alignItems:"center",spacing:.5,children:[e.jsx(g,{src:t.paymentCurrency?.logo,sx:{width:16,height:16},alt:t.paymentCurrency?.symbol}),e.jsx(o,{variant:"body2",color:f?"error.main":"text.secondary",children:C(_(t.remaining_amount,t.paymentCurrency.decimal),t.paymentCurrency.symbol)})]}),divider:!0}),e.jsx(u,{label:a("admin.customer.creditGrants.usage"),value:e.jsxs(o,{variant:"body2",color:f?"error.main":"text.secondary",children:[A().toFixed(1),"%"]})})]})]}),e.jsx(x,{})]}),e.jsxs(i,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".credit-grant-column-1":{minWidth:{xs:"100%",lg:"600px"}},".credit-grant-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(s,{flex:1,className:"credit-grant-column-1",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(s,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(l,{title:a("admin.details")}),e.jsxs(q,{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(c,{label:a("common.customer"),value:e.jsxs(i,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(g,{src:z(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(o,{children:t.customer?.name})]})}),e.jsx(c,{label:a("common.scope"),value:e.jsx(o,{children:t.applicability_config?.scope?.prices?a("common.specific"):a("common.general")})}),e.jsx(c,{label:a("admin.creditProduct.priority.label"),value:e.jsx(o,{children:t.priority})}),e.jsx(c,{label:a("common.createdAt"),value:h(t.created_at)}),e.jsx(c,{label:a("common.effectiveDate"),value:h(t.effective_at?t.effective_at*1e3:t.created_at)}),t.expires_at&&e.jsx(c,{label:a("common.expirationDate"),value:h(t.expires_at*1e3)}),t.chain_detail?.mint?.hash&&t.paymentMethod?.type==="arcblock"&&e.jsx(c,{label:a("common.mintTxHash"),value:e.jsx(H,{details:{arcblock:{tx_hash:t.chain_detail.mint.hash,payer:""}},method:t.paymentMethod,mode:"dashboard"})})]})]}),e.jsx(x,{}),t.items&&t.items.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs(s,{className:"section",children:[e.jsx(l,{title:a("admin.creditProduct.associatedPrices.label")}),e.jsx(s,{className:"section-body",children:e.jsx(Z,{data:t.items,currency:t.paymentCurrency,mode:"dashboard"})})]}),e.jsx(x,{})]}),e.jsxs(s,{className:"section",children:[e.jsx(l,{title:a("admin.creditTransactions.title")}),e.jsx(s,{className:"section-body",children:e.jsx(O,{customer_id:t.customer_id,credit_grant_id:t.id,showAdminColumns:!0,showTimeFilter:!0,mode:"dashboard"})})]}),e.jsx(x,{}),e.jsxs(s,{className:"section",children:[e.jsx(l,{title:a("admin.events.title")}),e.jsx(s,{className:"section-body",children:e.jsx(K,{features:{toolbar:!1},object_id:t.id})})]})]}),e.jsx(s,{className:"credit-grant-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:e.jsxs(s,{className:"section",children:[e.jsx(l,{title:a("common.metadata.label"),children:e.jsx(b,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:p.editing.metadata,onClick:y,children:a("common.edit")})}),e.jsxs(s,{className:"section-body",children:[e.jsx(Y,{data:t.metadata,handleEditMetadata:y}),p.editing.metadata&&e.jsx(V,{data:t,loading:p.loading.metadata,onSave:T,onCancel:()=>m(r=>({editing:{...r.editing,metadata:!1}}))})]})]})})]})]})}const ee=F(i)``;export{fe as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,B as x,a3 as w,ck as re,a2 as F,N as se,q as A,x as T,r as M,cD as ue,bp as X,bs as fe,bt as te,bg as pe,a1 as xe,aF as ge,A as W,aN as he,aM as ae,w as ye,z as ve,bv as je,Y as $,cA as be,bf as Ce}from"./vendor-mui-BXZut9Pz.js";import{V as G,Y as J,$ as _e,B as y,Z as Y,O as De,P as ie,H as ne}from"./vendor-blocklet-DcLR2Cyf.js";import{d as Q,aW as H,N as oe,e as _,k as Z,a as de,j as U,T as le,Y as we,n as ke,h as Se,F as Me}from"./index-BarN7DfU.js";import{C as Ee}from"./copyable-QrCyyiou.js";import{I as K}from"./info-metric-Dl4ZDm0Z.js";import{I as z}from"./info-row-jI0h_hv4.js";import{I as Te}from"./info-row-group-CFuMWJf1.js";import{M as Ie}from"./editor-AmthipP2.js";import{M as Ae}from"./list-CkHExntK.js";import{M as Pe}from"./actions-BSNy5bOd.js";import{S as B}from"./header-ivXuPt06.js";import{n as Ye,g as Le}from"./util-DxXTXkeY.js";import{L as R,a as Oe}from"./vendor-react-BPknnnEA.js";import{R as ze,A as Re,C as Ne,a as $e,D as Be,g as Fe}from"./overview-Cxc6WKba.js";import{C as He}from"./link-CmPoIweR.js";import{X as We,Y as Ue,T as Ge}from"./generateCategoricalChart-BadryV3H.js";import Ve from"./create-ke4FrPx1.js";import{I as qe}from"./info-card-BvIMFQo5.js";import{P as Ke}from"./actions-CSpJGOX7.js";import{M as Xe}from"./form-B5WW-lS5.js";import{D as Ze}from"./drawer-form-DspWWj3x.js";import"./lodash-B4Ozcv0x.js";import"./form-CAPjlw7l.js";import"./actions-BJDN6Op2.js";import"./click-boundary-CafubiPp.js";import"./currency-select-B4ieQBvv.js";import"./currency-GstdXsJf.js";import"./collapse-CSrlJ0eG.js";import"./form-cX026J4G.js";import"./product-select-ChEyoJqJ.js";import"./uploader-CsQNHG4I.js";import"./tax-code-select-TS07I0rB.js";import"./collapse-BvbJGg1V.js";import"./assign-0vMUDW_C.js";import"./edit-Bkj-OTJh.js";const Je=c=>_.post("/api/meter-events",{event_name:c.event_name,payload:{customer_id:c.customer_id,value:c.value,subscription_id:c.subscription_id||void 0},timestamp:c.timestamp,identifier:`manual_${Date.now()}`,metadata:{source:"manual",created_by:"admin"},source_data:[{key:"origin",label:"created_by",value:"Admin",type:"text"}]}).then(a=>a.data);function Qe({open:c,onClose:a,meterId:d,customers:r,onSuccess:C}){const{t:n}=G(),{isMobile:m}=Q("md"),[i,g]=J({loading:!1,form:{customer_id:"",value:"",subscription_id:"",timestamp:new Date}}),k=l=>l.name||l.email||l.did||l.id,s=()=>{g({form:{customer_id:"",value:"",subscription_id:"",timestamp:new Date}}),a()},o=async()=>{if(!i.form.customer_id||!i.form.value){Y.error(n("admin.meterEvent.add.validation"));return}g({loading:!0});try{const p=(await _.get(`/api/meters/${d}`)).data;await Je({event_name:p.event_name,customer_id:i.form.customer_id,value:i.form.value,subscription_id:i.form.subscription_id,timestamp:y(i.form.timestamp).unix()}),Y.success(n("admin.meterEvent.add.success")),s(),C()}catch(l){console.error("Failed to add usage:",l),Y.error(Z(l))}finally{g({loading:!1})}};return e.jsx(_e,{open:c,onClose:s,maxWidth:"sm",fullWidth:!0,fullScreen:m,title:n("admin.meterEvent.add.title"),actions:e.jsxs(e.Fragment,{children:[e.jsx(T,{onClick:s,variant:"outlined",disabled:i.loading,children:n("common.cancel")}),e.jsx(T,{onClick:o,variant:"contained",disabled:i.loading,children:n("admin.meterEvent.add.submit")})]}),children:e.jsx(x,{children:e.jsxs(w,{spacing:3,children:[e.jsxs(x,{children:[e.jsx(H,{sx:{color:"text.primary"},children:n("admin.meterEvent.add.customerId")}),e.jsx(re,{options:r,getOptionLabel:k,value:r.find(l=>l.id===i.form.customer_id)||null,onChange:(l,p)=>g({form:{...i.form,customer_id:p?.id||""}}),renderOption:(l,p)=>e.jsxs(x,{component:"li",...l,sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(se,{src:oe(p.did,p?.updated_at?new Date(p.updated_at).toISOString():void 0,24),sx:{width:24,height:24},alt:k(p)}),k(p)]}),renderInput:l=>e.jsx(F,{...l,placeholder:n("admin.meterEvent.add.customerIdPlaceholder"),fullWidth:!0})})]}),e.jsxs(x,{children:[e.jsx(H,{sx:{color:"text.primary"},children:n("admin.meterEvent.add.value")}),e.jsx(F,{type:"number",fullWidth:!0,value:i.form.value,onChange:l=>g({form:{...i.form,value:l.target.value}}),placeholder:n("admin.meterEvent.add.valuePlaceholder")})]}),e.jsxs(x,{children:[e.jsx(H,{sx:{color:"text.primary"},children:n("admin.meterEvent.add.subscriptionId")}),e.jsx(F,{fullWidth:!0,value:i.form.subscription_id,onChange:l=>g({form:{...i.form,subscription_id:l.target.value}}),placeholder:n("admin.meterEvent.add.subscriptionIdPlaceholder")}),e.jsx(A,{variant:"caption",sx:{color:"text.secondary",mt:.5,display:"block"},children:n("admin.meterEvent.add.subscriptionIdHint")})]}),e.jsxs(x,{children:[e.jsx(H,{sx:{color:"text.primary"},children:n("admin.meterEvent.add.timestamp")}),e.jsx(F,{type:"datetime-local",fullWidth:!0,value:y(i.form.timestamp).format("YYYY-MM-DDTHH:mm"),onChange:l=>g({form:{...i.form,timestamp:new Date(l.target.value)}}),InputLabelProps:{shrink:!0}}),e.jsx(A,{variant:"caption",sx:{color:"text.secondary",mt:.5,display:"block"},children:n("admin.meterEvent.add.timestampHint")})]})]})})})}const et=(c,a={})=>{const d=new URLSearchParams;return d.append("meter_id",c),a.page!==void 0&&d.append("page",String(a.page)),a.pageSize!==void 0&&d.append("pageSize",String(a.pageSize)),a.start!==void 0&&d.append("start",String(a.start)),a.end!==void 0&&d.append("end",String(a.end)),a.customer_id&&d.append("customer_id",a.customer_id),_.get(`/api/meter-events?${d.toString()}`).then(r=>r.data)},tt=(c,a,d,r,C)=>{const n=new URLSearchParams;return n.append("meter_id",c),n.append("start",a.toString()),n.append("end",d.toString()),r&&n.append("customer_id",r),C&&n.append("granularity",C),_.get(`/api/meter-events/stats?${n.toString()}`).then(m=>m.data)},at=()=>_.get("/api/customers?limit=100").then(c=>c.data),nt=(c,a,d)=>{const r=[],C=y(c),n=y(a),m=y();if(d==="hour"){let i=C.startOf("hour");const g=n.isAfter(m)?m:n;for(;i.isBefore(g)||i.isSame(g,"hour");)r.push({date:i.format("HH:mm"),fullDate:i.format("YYYY-MM-DD HH:mm"),timestamp:i.unix().toString(),event_count:0,total_value:0}),i=i.add(1,"hour")}else{let i=C.startOf("day");const g=n.isAfter(m,"day")?m.startOf("day"):n;for(;i.isBefore(g)||i.isSame(g,"day");)r.push({date:i.format("MM/DD"),fullDate:i.format("YYYY-MM-DD"),timestamp:i.unix().toString(),event_count:0,total_value:0}),i=i.add(1,"day")}return r};function rt({meterId:c,paymentCurrency:a}){const{t:d}=G(),{isMobile:r}=Q("md"),{livemode:C}=de(),n=y().endOf("day").toDate(),[m,i]=De(`meter-events-${c}`,{defaultValue:{pageSize:10,page:1,start:y().subtract(30,"day").startOf("day").unix(),end:y().endOf("day").unix()}}),{data:g={list:[],count:0},refresh:k,loading:s}=ie(()=>et(c,m),{refreshDeps:[m]}),[o,l]=J({stats:[],customers:[],statsLoading:!1,anchorEl:null,startDate:y().subtract(30,"day").startOf("day").toDate(),endDate:n,selectedCustomer:null,chartType:"event_count",addUsageDialog:!1}),p=M.useMemo(()=>{const t=y(o.startDate);return y(o.endDate).diff(t,"day")===0?"hour":"day"},[o.startDate,o.endDate]),P=M.useMemo(()=>{if(o.statsLoading)return[];const t=nt(o.startDate,o.endDate,p);if(!o.stats.length)return t;const u=new Map;return o.stats.forEach(f=>{let D,q;p==="hour"?(D=y(f.timestamp).format("HH:mm"),q=y(f.timestamp).format("YYYY-MM-DD HH:mm")):(D=y(f.timestamp).format("MM/DD"),q=y(f.timestamp).format("YYYY-MM-DD")),u.set(D,{...f,date:D,fullDate:q})}),t.map(f=>u.get(f.date)||f)},[o.stats,o.statsLoading,o.startDate,o.endDate,p]),I=async()=>{l({statsLoading:!0});try{const t=await tt(c,y(o.startDate).unix(),y(o.endDate).unix(),o.selectedCustomer?.id,p);l({stats:t.list,statsLoading:!1})}catch(t){console.error("Failed to fetch stats:",t),l({statsLoading:!1})}},N=async()=>{try{const t=await at();if(l({customers:t.list}),m.customer_id&&t.list.length>0){const u=t.list.find(f=>f.id===m.customer_id);u&&l({selectedCustomer:u})}}catch(t){console.error("Failed to fetch customers:",t)}};M.useEffect(()=>{N()},[c]),M.useEffect(()=>{m?.start&&m?.end&&l({startDate:y.unix(m.start).toDate(),endDate:y.unix(m.end).toDate()})},[m?.start,m?.end]),M.useEffect(()=>{I()},[o.startDate,o.endDate,o.selectedCustomer,p]);const h=({page:t,rowsPerPage:u})=>{m.pageSize!==u?i(f=>({...f,pageSize:u,page:1})):m.page!==t+1&&i(f=>({...f,page:t+1}))},v=t=>{o.anchorEl?l({anchorEl:null}):l({anchorEl:t.currentTarget})},L=t=>{const u=y(t.startDate).startOf("day").unix(),f=y(t.endDate).endOf("day").unix();i(D=>({...D,start:u,end:f,page:1})),l({startDate:t.startDate,endDate:y(t.endDate).endOf("day").toDate(),anchorEl:null})},S=(t,u)=>{u!==null&&l({chartType:u})},O=t=>{i(u=>({...u,customer_id:t?.id,page:1})),l({selectedCustomer:t})},E=t=>t.name||t.email||t.did||t.id,b=()=>{l({addUsageDialog:!0})},j=()=>{l({addUsageDialog:!1})},V=()=>{k(),I()},ee=!!o.anchorEl,ce=ee?"date-range-picker-popover":void 0,me=[{label:d("admin.meter.events.value"),name:"value",options:{filter:!1,sort:!1,customBodyRenderLite:(t,u)=>{const f=g.list[u];if(!f)return null;const D=ne(f.payload.value||"0",a.decimal);return e.jsx(R,{to:`/admin/billing/${f.id}`,children:`${D} ${a.symbol}`})}}},{label:d("admin.meter.events.customer"),name:"customer",options:{filter:!1,sort:!1,customBodyRenderLite:(t,u)=>{const f=g.list[u];return!f||!f?.customer?"-":e.jsx(He,{customer:f.customer,size:"small"})}}},{label:d("admin.meter.events.subscription"),name:"subscription",options:{filter:!1,sort:!1,customBodyRenderLite:(t,u)=>{const f=g.list[u];if(!f)return"-";const D=f.payload?.subscription_id;return D?e.jsx(R,{to:`/admin/billing/${D}`,children:e.jsx(A,{variant:"body2",sx:{color:"text.link"},children:f?.subscription?.description||D})}):"-"}}},{label:d("admin.meter.events.reportTime"),name:"created_at",options:{filter:!1,sort:!1,customBodyRenderLite:(t,u)=>{const f=g.list[u];return e.jsx(R,{to:`/admin/billing/${f?.id}`,children:f?U(f.created_at):"-"})}}}];return e.jsxs(x,{children:[e.jsxs(x,{sx:{mb:3},children:[e.jsxs(w,{direction:r?"column":"row",spacing:2,sx:{alignItems:r?"stretch":"center",flexWrap:"wrap"},children:[e.jsxs(T,{variant:"outlined",startIcon:e.jsx(ue,{}),onClick:v,size:"large",sx:{minWidth:r?"100%":200,justifyContent:r?"flex-start":"center",color:"text.secondary",borderColor:"grey.300","&:hover":{borderColor:"primary.main"},backgroundColor:"grey.50"},children:[y(o.startDate).format("YYYY-MM-DD")," - ",y(o.endDate).format("YYYY-MM-DD")]}),e.jsx(re,{options:o.customers,getOptionLabel:E,value:o.selectedCustomer,onChange:(t,u)=>O(u),sx:{minWidth:r?"100%":200,flex:r?1:"none"},renderInput:t=>e.jsx(F,{...t,label:d("admin.meter.events.filterByCustomer"),size:"small"}),renderOption:(t,u)=>e.jsxs(x,{component:"li",...t,sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(se,{src:oe(u.did,u?.updated_at?new Date(u.updated_at).toISOString():void 0,24),sx:{width:24,height:24},alt:E(u)}),E(u)]})}),!C&&e.jsx(T,{variant:"outlined",startIcon:e.jsx(X,{}),onClick:b,sx:{minWidth:r?"100%":"auto",color:"text.link"},children:d("admin.meterEvent.add.button")})]}),e.jsx(x,{sx:{mt:2,display:"flex",justifyContent:r?"center":"flex-end"},children:e.jsxs(fe,{value:o.chartType,exclusive:!0,onChange:S,size:"small",sx:{width:r?"100%":"auto","& .MuiToggleButton-root":{flex:r?1:"none"}},children:[e.jsx(te,{value:"event_count",children:d("admin.meter.events.eventCount")}),e.jsx(te,{value:"total_value",children:d("admin.meter.events.totalValue")})]})})]}),e.jsx(pe,{sx:{mb:3},children:e.jsx(x,{sx:{height:r?250:300,position:"relative",pr:r?1:2,pl:r?.5:1},children:o.statsLoading?e.jsx(x,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0},children:e.jsx(xe,{variant:"rectangular",width:"100%",height:"100%"})}):e.jsx(ze,{width:"100%",height:"100%",children:e.jsxs(Re,{data:P,margin:{top:10,right:r?10:30,left:r?5:10,bottom:p==="hour"?r?50:60:r?30:40},children:[e.jsx(Ne,{strokeDasharray:"3 3"}),e.jsx(We,{dataKey:"date",tick:{fontSize:r?10:11},angle:p==="hour"?-45:0,textAnchor:p==="hour"?"end":"middle",height:p==="hour"?r?50:60:r?30:40,interval:(()=>{const t=P.length;return r?t>20?Math.floor(t/6):t>10?Math.floor(t/4):t>5?1:0:p==="hour"?t>24?Math.floor(t/12):t>12?1:0:t>30?Math.floor(t/15):t>15?1:0})()}),e.jsx(Ue,{tick:{fontSize:r?9:11},width:r?35:40,tickFormatter:t=>r&&t>=1e3?`${(t/1e3).toFixed(1)}k`:t.toString()}),e.jsx(Ge,{labelFormatter:t=>P.find(f=>f.date===t)?.fullDate||t,formatter:(t,u)=>[u==="event_count"?t:ne(t,a.decimal),d(u==="event_count"?"admin.meter.events.eventCount":"admin.meter.events.totalValue")],contentStyle:{fontSize:r?"12px":"14px",padding:r?"8px":"10px"}}),e.jsx($e,{type:"monotone",dataKey:o.chartType,stroke:o.chartType==="event_count"?"#8884d8":"#82ca9d",fill:o.chartType==="event_count"?"#8884d8":"#82ca9d",fillOpacity:.6,strokeWidth:r?1.5:2})]})})})}),e.jsx(x,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:e.jsx(A,{variant:"body2",sx:{color:"text.secondary"},children:d("admin.meter.events.count",{count:g.count})})}),e.jsx(le,{data:g.list,columns:me,onChange:h,options:{count:g.count,page:m.page-1,rowsPerPage:m.pageSize,responsive:r?"vertical":"standard"},loading:s,emptyNodeText:d("admin.meter.events.empty")}),e.jsx(ge,{id:ce,open:ee,anchorEl:o.anchorEl,onClose:()=>l({anchorEl:null}),anchorOrigin:{vertical:"bottom",horizontal:"right"},children:e.jsx(Be,{open:!0,toggle:v,maxDate:n,definedRanges:Fe(n.toISOString()),onChange:L})}),e.jsx(Qe,{open:o.addUsageDialog,onClose:j,meterId:c,customers:o.customers,paymentCurrency:a,onSuccess:V})]})}const st=c=>_.get(`/api/products?meter_id=${c}`).then(a=>a.data),it=c=>_.get(`/api/products?type=credit&meter_id=${c}`).then(a=>a.data);function ot({meterId:c,meter:a=void 0}){const{t:d,locale:r}=G(),{settings:C}=de(),[n,m]=M.useState([]),[i,g]=M.useState(!1),[k,s]=M.useState(!1),[o,l]=M.useState(null),[p,P]=M.useState("credit"),I=async(E=p)=>{g(!0),l(null);try{const b=E==="meter"?await st(c):await it(c);m(b.list)}catch(b){console.error("Failed to fetch products:",b),l("Failed to load products")}finally{g(!1)}};M.useEffect(()=>{I()},[c,p]);const N=(E,b)=>{P(b)},h=()=>{s(!0)},v=()=>{s(!1),I()};if(o)return e.jsx(W,{severity:"error",sx:{mt:1},children:o});const L=[{label:d("admin.product.name.label"),name:"name",options:{filter:!1,customBodyRenderLite:(E,b)=>{const j=n[b];if(!j)return null;const V=we(C.paymentMethods,j.prices[0]?.currency_id??"")||C.baseCurrency;return e.jsx(R,{to:`/admin/products/${j.id}`,children:e.jsx(qe,{name:j.name,description:Ye(j,V,r),logo:j.images[0]})})}}},{label:d("common.status"),name:"active",options:{filter:!1,customBodyRenderLite:(E,b)=>{const j=n[b];return j?e.jsx(R,{to:`/admin/products/${j.id}`,children:e.jsx(ke,{label:j?.active?"Active":"Archived",color:j?.active?"success":"default"})}):null}}},{label:d("common.createdAt"),name:"created_at",options:{sort:!1,customBodyRenderLite:(E,b)=>{const j=n[b];return j?e.jsx(R,{to:`/admin/products/${j.id}`,children:U(j.created_at)}):null}}},{label:d("common.actions"),name:"id",width:100,align:"center",options:{sort:!1,customBodyRenderLite:(E,b)=>{const j=n[b];return j?e.jsx(Ke,{data:j,onChange:()=>I()}):null}}}],O=p==="meter"?{text:d("admin.meter.products.emptyTip"),buttonText:d("admin.meter.products.create")}:{text:d("admin.meter.creditProducts.emptyTip"),buttonText:d("admin.creditProduct.create")};return e.jsxs(x,{children:[e.jsx(w,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(he,{value:p,onChange:N,sx:{flex:"1 0 auto",maxWidth:"100%",fontSize:14,borderBottom:1,borderColor:"divider",".Mui-selected":{fontSize:"14px !important",color:"primary.main"}},children:[e.jsx(ae,{label:d("admin.meter.products.creditCharge"),value:"credit"}),e.jsx(ae,{label:d("admin.meter.products.meterService"),value:"meter"})]})}),e.jsx(w,{direction:"row",sx:{justifyContent:"flex-end",mb:2},children:e.jsx(T,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link",float:"right"},startIcon:e.jsx(X,{}),onClick:h,children:d(p==="meter"?"admin.meter.products.create":"admin.creditProduct.create")})}),e.jsx(le,{hasRowLink:!0,data:n,columns:L,options:{count:n.length,page:0,rowsPerPage:n.length,pagination:!1,search:!1,filter:!1,sort:!1,viewColumns:!1,download:!1,print:!1,selectableRows:"none"},loading:i,emptyNodeText:e.jsxs(x,{children:[e.jsx(A,{children:O.text}),e.jsx(T,{size:"small",variant:"text",startIcon:e.jsx(X,{}),onClick:h,sx:{mt:1,color:"text.link"},children:O.buttonText})]})}),k&&e.jsx(Ve,{open:k,onClose:v,onSubmit:()=>I(p),mode:p==="credit"?"credit":"standard",meterId:c,initialPrice:p==="meter"?{currency_id:a?.currency_id||"",priceModel:"credit_metered"}:{metadata:{credit_config:{currency_id:a?.currency_id||""}},name:a?.unit||""}})]})}const dt=c=>_.get(`/api/meters/${c}`).then(a=>a.data);function Ut(c){const{t:a}=G(),{isMobile:d}=Q(),r=Oe(),C=h=>{switch(h){case"sum":return a("admin.meter.aggregationMethod.sumHint");case"count":return a("admin.meter.aggregationMethod.countHint");case"last":return a("admin.meter.aggregationMethod.lastHint");default:return""}},[n,m]=J({editing:{metadata:!1,meter:!1},loading:{metadata:!1,meter:!1},creating:{product:!1,creditProduct:!1},tokenConfig:{name:"",symbol:"",tokenFactoryAddress:""}}),i=Se({defaultValues:{name:"",event_name:"",aggregation_method:"sum",unit:"",description:"",metadata:{},mode:"OffChain"}}),{loading:g,error:k,data:s,runAsync:o}=ie(()=>dt(c.id));if(k)return e.jsx(W,{severity:"error",children:k.message});if(g||!s)return e.jsx(ye,{});const l=async h=>{try{m(v=>({loading:{...v.loading,metadata:!0}})),await _.put(`/api/meters/${c.id}`,h),Y.success(a("common.saved")),o()}catch(v){console.error(v),Y.error(Z(v))}finally{m(v=>({loading:{...v.loading,metadata:!1}}))}},p=h=>{h==="delete"?r("/admin/billing/meters"):o()},P=()=>{m(h=>({editing:{...h.editing,metadata:!0}}))},I=()=>{const h=!!s.paymentCurrency?.token_config;i.reset({name:s.name,event_name:s.event_name,aggregation_method:s.aggregation_method,unit:s.unit,description:s.description||"",metadata:s.metadata||{},mode:h?"OnChain":"OffChain"}),m(v=>({editing:{...v.editing,meter:!0},tokenConfig:{name:"",symbol:"",tokenFactoryAddress:""}}))},N=async h=>{try{m(S=>({loading:{...S.loading,meter:!0}}));const v=s.paymentCurrency?.id,L=!!s.paymentCurrency?.token_config;if(v&&!L&&h.mode==="OnChain"){let{tokenFactoryAddress:S}=n.tokenConfig;if(!S&&n.tokenConfig.symbol){const{data:O}=await _.post("/api/credit-tokens",{name:n.tokenConfig.name,symbol:n.tokenConfig.symbol});S=O.address}S&&await _.put(`/api/payment-currencies/${v}/token-config`,{token_factory_address:S})}v&&L&&h.mode==="OffChain"&&await _.delete(`/api/payment-currencies/${v}/token-config`),delete h.mode,await _.put(`/api/meters/${c.id}`,h),Y.success(a("admin.meter.saved")),m(S=>({editing:{...S.editing,meter:!1}})),o()}catch(v){console.error(v),Y.error(Z(v))}finally{m(v=>({loading:{...v.loading,meter:!1}}))}};return e.jsxs(lt,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(x,{children:[s.status==="inactive"&&e.jsxs(W,{severity:"warning",sx:{mb:2},children:[e.jsx(ve,{children:a("admin.meter.inactive")}),a("admin.meter.inactiveTip")]}),e.jsxs(w,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(w,{direction:"row",onClick:()=>Le("/admin/meters"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(je,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(A,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:a("admin.meters")})]}),e.jsx(Pe,{data:s,variant:"normal",onChange:p})]}),e.jsxs(x,{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(w,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsx(w,{direction:"row",spacing:1,sx:{alignItems:"center"},children:e.jsxs(w,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:[e.jsx(A,{variant:"h2",sx:{color:"text.primary"},children:s.name}),e.jsxs(A,{variant:"subtitle1",sx:{color:"text.lighter"},children:[s.event_name," • ",s.unit]})]})})}),e.jsxs(w,{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(K,{label:a("common.id"),value:e.jsx(Ee,{text:c.id,style:{marginLeft:4}}),divider:!0}),e.jsx(K,{label:a("common.createdAt"),value:U(s.created_at),divider:!0}),s.paymentCurrency?.recharge_config?.base_price_id&&e.jsx(K,{label:a("admin.meter.rechargePackage.priceId"),tip:a("admin.meter.rechargePackage.tooltip",{name:s.paymentCurrency.name}),value:e.jsx(T,{variant:"text",size:"small",onClick:()=>r(`/admin/products/${s.paymentCurrency.recharge_config.base_price_id}`),sx:{p:0,minWidth:"auto",textAlign:"left",ml:.5,color:"text.link"},children:s.paymentCurrency.recharge_config.base_price_id}),divider:!0})]})]}),e.jsx($,{})]}),e.jsxs(w,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".meter-column-1":{minWidth:{xs:"100%",lg:"600px"}},".meter-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(x,{className:"meter-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(x,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(B,{title:a("admin.details"),children:e.jsx(T,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:n.editing.meter,onClick:I,children:a("common.edit")})}),e.jsxs(Te,{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(z,{label:a("admin.meter.name.label"),value:s.name}),e.jsx(z,{label:a("admin.meter.eventName.label"),value:s.event_name}),e.jsx(z,{label:a("admin.meter.aggregationMethod.label"),value:s.aggregation_method}),e.jsx(z,{label:a("admin.meter.unit.label"),value:s.unit}),e.jsx(z,{label:a("admin.meter.description.label"),value:s.description||"-"}),e.jsx(z,{label:a("common.updatedAt"),value:U(s.updated_at)})]})]}),e.jsx($,{}),e.jsxs(x,{className:"section",children:[e.jsx(B,{title:a("admin.meter.events.title")}),e.jsx(x,{className:"section-body",children:e.jsx(rt,{meterId:s.id,paymentCurrency:s.paymentCurrency})})]}),e.jsx($,{}),e.jsxs(x,{className:"section",children:[e.jsx(x,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:e.jsx(B,{title:a("admin.meter.products.title")})}),e.jsx(x,{className:"section-body",children:e.jsx(ot,{meterId:s.id,meter:s})})]})]}),d&&e.jsx($,{}),e.jsxs(x,{className:"meter-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(x,{className:"section",children:[e.jsx(B,{title:a("admin.meter.usageGuide.title")}),e.jsx(x,{className:"section-body",children:e.jsx(W,{severity:"info",sx:{mb:2},children:e.jsx(A,{variant:"body2",children:a("admin.meter.usageGuide.tip",{eventName:s.event_name,aggregationMethodHint:C(s.aggregation_method),unit:s.unit})})})})]}),e.jsx($,{}),e.jsxs(x,{className:"section",children:[e.jsx(B,{title:a("common.metadata.label"),children:e.jsx(T,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:n.editing.metadata,onClick:P,children:a("common.edit")})}),e.jsxs(x,{className:"section-body",children:[e.jsx(Ae,{data:s.metadata,handleEditMetadata:P}),n.editing.metadata&&e.jsx(Ie,{data:s,loading:n.loading.metadata,onSave:l,onCancel:()=>m(h=>({editing:{...h.editing,metadata:!1}}))})]})]})]})]}),n.editing.meter&&e.jsx(Ze,{icon:e.jsx(be,{}),text:a("admin.meter.edit"),open:n.editing.meter,onClose:()=>m(h=>({editing:{...h.editing,meter:!1}})),width:640,addons:e.jsx(T,{variant:"contained",size:"small",disabled:n.loading.meter,onClick:i.handleSubmit(N),children:a("admin.meter.save")}),children:e.jsx(Me,{...i,children:e.jsx(Xe,{mode:"edit",paymentCurrency:s.paymentCurrency,tokenConfig:n.tokenConfig,onTokenConfigChange:h=>m({tokenConfig:h})})})})]})}const lt=Ce(w)``;export{Ut as default};
|
|
1
|
+
import{j as e,B as x,a3 as w,ck as re,a2 as F,N as se,q as A,x as T,r as M,cD as ue,bp as X,bs as fe,bt as te,bg as pe,a1 as xe,aF as ge,A as W,aN as he,aM as ae,w as ye,z as ve,bv as je,Y as $,cA as be,bf as Ce}from"./vendor-mui-BXZut9Pz.js";import{V as G,Y as J,$ as _e,B as y,Z as Y,O as De,P as ie,H as ne}from"./vendor-blocklet-B67R14so.js";import{d as Q,aW as H,N as oe,e as _,k as Z,a as de,j as U,T as le,Y as we,n as ke,h as Se,F as Me}from"./index-B4yaPb7B.js";import{C as Ee}from"./copyable-CprMHdhV.js";import{I as K}from"./info-metric-ukWq8INi.js";import{I as z}from"./info-row-CaPaNF4L.js";import{I as Te}from"./info-row-group-Cxo-4Gk5.js";import{M as Ie}from"./editor-vZvxDUTl.js";import{M as Ae}from"./list-B2b-s8wM.js";import{M as Pe}from"./actions-DXMceTgd.js";import{S as B}from"./header-ivXuPt06.js";import{n as Ye,g as Le}from"./util-B8B3fsMa.js";import{L as R,a as Oe}from"./vendor-react-BPknnnEA.js";import{R as ze,A as Re,C as Ne,a as $e,D as Be,g as Fe}from"./overview-CGdVIJrJ.js";import{C as He}from"./link-DsltSF2Q.js";import{X as We,Y as Ue,T as Ge}from"./generateCategoricalChart-BCpuUeC_.js";import Ve from"./create-B-Ubepl_.js";import{I as qe}from"./info-card-C9dRgztS.js";import{P as Ke}from"./actions-C9AfME83.js";import{M as Xe}from"./form-Bro99BjK.js";import{D as Ze}from"./drawer-form-CQjNFFWk.js";import"./lodash-B4Ozcv0x.js";import"./form-CnrBCyTJ.js";import"./actions-BEUwbsq1.js";import"./click-boundary-Bi28Y0Fq.js";import"./currency-select-C8j7QQMP.js";import"./currency-GstdXsJf.js";import"./collapse-CSrlJ0eG.js";import"./form-AFzUvoFE.js";import"./product-select-_72p-5lF.js";import"./uploader-BLdAbLR6.js";import"./tax-code-select-j2arPbaE.js";import"./collapse-BvbJGg1V.js";import"./assign-DKRfmN7W.js";import"./edit-DAU8AWzT.js";const Je=c=>_.post("/api/meter-events",{event_name:c.event_name,payload:{customer_id:c.customer_id,value:c.value,subscription_id:c.subscription_id||void 0},timestamp:c.timestamp,identifier:`manual_${Date.now()}`,metadata:{source:"manual",created_by:"admin"},source_data:[{key:"origin",label:"created_by",value:"Admin",type:"text"}]}).then(a=>a.data);function Qe({open:c,onClose:a,meterId:d,customers:r,onSuccess:C}){const{t:n}=G(),{isMobile:m}=Q("md"),[i,g]=J({loading:!1,form:{customer_id:"",value:"",subscription_id:"",timestamp:new Date}}),k=l=>l.name||l.email||l.did||l.id,s=()=>{g({form:{customer_id:"",value:"",subscription_id:"",timestamp:new Date}}),a()},o=async()=>{if(!i.form.customer_id||!i.form.value){Y.error(n("admin.meterEvent.add.validation"));return}g({loading:!0});try{const p=(await _.get(`/api/meters/${d}`)).data;await Je({event_name:p.event_name,customer_id:i.form.customer_id,value:i.form.value,subscription_id:i.form.subscription_id,timestamp:y(i.form.timestamp).unix()}),Y.success(n("admin.meterEvent.add.success")),s(),C()}catch(l){console.error("Failed to add usage:",l),Y.error(Z(l))}finally{g({loading:!1})}};return e.jsx(_e,{open:c,onClose:s,maxWidth:"sm",fullWidth:!0,fullScreen:m,title:n("admin.meterEvent.add.title"),actions:e.jsxs(e.Fragment,{children:[e.jsx(T,{onClick:s,variant:"outlined",disabled:i.loading,children:n("common.cancel")}),e.jsx(T,{onClick:o,variant:"contained",disabled:i.loading,children:n("admin.meterEvent.add.submit")})]}),children:e.jsx(x,{children:e.jsxs(w,{spacing:3,children:[e.jsxs(x,{children:[e.jsx(H,{sx:{color:"text.primary"},children:n("admin.meterEvent.add.customerId")}),e.jsx(re,{options:r,getOptionLabel:k,value:r.find(l=>l.id===i.form.customer_id)||null,onChange:(l,p)=>g({form:{...i.form,customer_id:p?.id||""}}),renderOption:(l,p)=>e.jsxs(x,{component:"li",...l,sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(se,{src:oe(p.did,p?.updated_at?new Date(p.updated_at).toISOString():void 0,24),sx:{width:24,height:24},alt:k(p)}),k(p)]}),renderInput:l=>e.jsx(F,{...l,placeholder:n("admin.meterEvent.add.customerIdPlaceholder"),fullWidth:!0})})]}),e.jsxs(x,{children:[e.jsx(H,{sx:{color:"text.primary"},children:n("admin.meterEvent.add.value")}),e.jsx(F,{type:"number",fullWidth:!0,value:i.form.value,onChange:l=>g({form:{...i.form,value:l.target.value}}),placeholder:n("admin.meterEvent.add.valuePlaceholder")})]}),e.jsxs(x,{children:[e.jsx(H,{sx:{color:"text.primary"},children:n("admin.meterEvent.add.subscriptionId")}),e.jsx(F,{fullWidth:!0,value:i.form.subscription_id,onChange:l=>g({form:{...i.form,subscription_id:l.target.value}}),placeholder:n("admin.meterEvent.add.subscriptionIdPlaceholder")}),e.jsx(A,{variant:"caption",sx:{color:"text.secondary",mt:.5,display:"block"},children:n("admin.meterEvent.add.subscriptionIdHint")})]}),e.jsxs(x,{children:[e.jsx(H,{sx:{color:"text.primary"},children:n("admin.meterEvent.add.timestamp")}),e.jsx(F,{type:"datetime-local",fullWidth:!0,value:y(i.form.timestamp).format("YYYY-MM-DDTHH:mm"),onChange:l=>g({form:{...i.form,timestamp:new Date(l.target.value)}}),InputLabelProps:{shrink:!0}}),e.jsx(A,{variant:"caption",sx:{color:"text.secondary",mt:.5,display:"block"},children:n("admin.meterEvent.add.timestampHint")})]})]})})})}const et=(c,a={})=>{const d=new URLSearchParams;return d.append("meter_id",c),a.page!==void 0&&d.append("page",String(a.page)),a.pageSize!==void 0&&d.append("pageSize",String(a.pageSize)),a.start!==void 0&&d.append("start",String(a.start)),a.end!==void 0&&d.append("end",String(a.end)),a.customer_id&&d.append("customer_id",a.customer_id),_.get(`/api/meter-events?${d.toString()}`).then(r=>r.data)},tt=(c,a,d,r,C)=>{const n=new URLSearchParams;return n.append("meter_id",c),n.append("start",a.toString()),n.append("end",d.toString()),r&&n.append("customer_id",r),C&&n.append("granularity",C),_.get(`/api/meter-events/stats?${n.toString()}`).then(m=>m.data)},at=()=>_.get("/api/customers?limit=100").then(c=>c.data),nt=(c,a,d)=>{const r=[],C=y(c),n=y(a),m=y();if(d==="hour"){let i=C.startOf("hour");const g=n.isAfter(m)?m:n;for(;i.isBefore(g)||i.isSame(g,"hour");)r.push({date:i.format("HH:mm"),fullDate:i.format("YYYY-MM-DD HH:mm"),timestamp:i.unix().toString(),event_count:0,total_value:0}),i=i.add(1,"hour")}else{let i=C.startOf("day");const g=n.isAfter(m,"day")?m.startOf("day"):n;for(;i.isBefore(g)||i.isSame(g,"day");)r.push({date:i.format("MM/DD"),fullDate:i.format("YYYY-MM-DD"),timestamp:i.unix().toString(),event_count:0,total_value:0}),i=i.add(1,"day")}return r};function rt({meterId:c,paymentCurrency:a}){const{t:d}=G(),{isMobile:r}=Q("md"),{livemode:C}=de(),n=y().endOf("day").toDate(),[m,i]=De(`meter-events-${c}`,{defaultValue:{pageSize:10,page:1,start:y().subtract(30,"day").startOf("day").unix(),end:y().endOf("day").unix()}}),{data:g={list:[],count:0},refresh:k,loading:s}=ie(()=>et(c,m),{refreshDeps:[m]}),[o,l]=J({stats:[],customers:[],statsLoading:!1,anchorEl:null,startDate:y().subtract(30,"day").startOf("day").toDate(),endDate:n,selectedCustomer:null,chartType:"event_count",addUsageDialog:!1}),p=M.useMemo(()=>{const t=y(o.startDate);return y(o.endDate).diff(t,"day")===0?"hour":"day"},[o.startDate,o.endDate]),P=M.useMemo(()=>{if(o.statsLoading)return[];const t=nt(o.startDate,o.endDate,p);if(!o.stats.length)return t;const u=new Map;return o.stats.forEach(f=>{let D,q;p==="hour"?(D=y(f.timestamp).format("HH:mm"),q=y(f.timestamp).format("YYYY-MM-DD HH:mm")):(D=y(f.timestamp).format("MM/DD"),q=y(f.timestamp).format("YYYY-MM-DD")),u.set(D,{...f,date:D,fullDate:q})}),t.map(f=>u.get(f.date)||f)},[o.stats,o.statsLoading,o.startDate,o.endDate,p]),I=async()=>{l({statsLoading:!0});try{const t=await tt(c,y(o.startDate).unix(),y(o.endDate).unix(),o.selectedCustomer?.id,p);l({stats:t.list,statsLoading:!1})}catch(t){console.error("Failed to fetch stats:",t),l({statsLoading:!1})}},N=async()=>{try{const t=await at();if(l({customers:t.list}),m.customer_id&&t.list.length>0){const u=t.list.find(f=>f.id===m.customer_id);u&&l({selectedCustomer:u})}}catch(t){console.error("Failed to fetch customers:",t)}};M.useEffect(()=>{N()},[c]),M.useEffect(()=>{m?.start&&m?.end&&l({startDate:y.unix(m.start).toDate(),endDate:y.unix(m.end).toDate()})},[m?.start,m?.end]),M.useEffect(()=>{I()},[o.startDate,o.endDate,o.selectedCustomer,p]);const h=({page:t,rowsPerPage:u})=>{m.pageSize!==u?i(f=>({...f,pageSize:u,page:1})):m.page!==t+1&&i(f=>({...f,page:t+1}))},v=t=>{o.anchorEl?l({anchorEl:null}):l({anchorEl:t.currentTarget})},L=t=>{const u=y(t.startDate).startOf("day").unix(),f=y(t.endDate).endOf("day").unix();i(D=>({...D,start:u,end:f,page:1})),l({startDate:t.startDate,endDate:y(t.endDate).endOf("day").toDate(),anchorEl:null})},S=(t,u)=>{u!==null&&l({chartType:u})},O=t=>{i(u=>({...u,customer_id:t?.id,page:1})),l({selectedCustomer:t})},E=t=>t.name||t.email||t.did||t.id,b=()=>{l({addUsageDialog:!0})},j=()=>{l({addUsageDialog:!1})},V=()=>{k(),I()},ee=!!o.anchorEl,ce=ee?"date-range-picker-popover":void 0,me=[{label:d("admin.meter.events.value"),name:"value",options:{filter:!1,sort:!1,customBodyRenderLite:(t,u)=>{const f=g.list[u];if(!f)return null;const D=ne(f.payload.value||"0",a.decimal);return e.jsx(R,{to:`/admin/billing/${f.id}`,children:`${D} ${a.symbol}`})}}},{label:d("admin.meter.events.customer"),name:"customer",options:{filter:!1,sort:!1,customBodyRenderLite:(t,u)=>{const f=g.list[u];return!f||!f?.customer?"-":e.jsx(He,{customer:f.customer,size:"small"})}}},{label:d("admin.meter.events.subscription"),name:"subscription",options:{filter:!1,sort:!1,customBodyRenderLite:(t,u)=>{const f=g.list[u];if(!f)return"-";const D=f.payload?.subscription_id;return D?e.jsx(R,{to:`/admin/billing/${D}`,children:e.jsx(A,{variant:"body2",sx:{color:"text.link"},children:f?.subscription?.description||D})}):"-"}}},{label:d("admin.meter.events.reportTime"),name:"created_at",options:{filter:!1,sort:!1,customBodyRenderLite:(t,u)=>{const f=g.list[u];return e.jsx(R,{to:`/admin/billing/${f?.id}`,children:f?U(f.created_at):"-"})}}}];return e.jsxs(x,{children:[e.jsxs(x,{sx:{mb:3},children:[e.jsxs(w,{direction:r?"column":"row",spacing:2,sx:{alignItems:r?"stretch":"center",flexWrap:"wrap"},children:[e.jsxs(T,{variant:"outlined",startIcon:e.jsx(ue,{}),onClick:v,size:"large",sx:{minWidth:r?"100%":200,justifyContent:r?"flex-start":"center",color:"text.secondary",borderColor:"grey.300","&:hover":{borderColor:"primary.main"},backgroundColor:"grey.50"},children:[y(o.startDate).format("YYYY-MM-DD")," - ",y(o.endDate).format("YYYY-MM-DD")]}),e.jsx(re,{options:o.customers,getOptionLabel:E,value:o.selectedCustomer,onChange:(t,u)=>O(u),sx:{minWidth:r?"100%":200,flex:r?1:"none"},renderInput:t=>e.jsx(F,{...t,label:d("admin.meter.events.filterByCustomer"),size:"small"}),renderOption:(t,u)=>e.jsxs(x,{component:"li",...t,sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(se,{src:oe(u.did,u?.updated_at?new Date(u.updated_at).toISOString():void 0,24),sx:{width:24,height:24},alt:E(u)}),E(u)]})}),!C&&e.jsx(T,{variant:"outlined",startIcon:e.jsx(X,{}),onClick:b,sx:{minWidth:r?"100%":"auto",color:"text.link"},children:d("admin.meterEvent.add.button")})]}),e.jsx(x,{sx:{mt:2,display:"flex",justifyContent:r?"center":"flex-end"},children:e.jsxs(fe,{value:o.chartType,exclusive:!0,onChange:S,size:"small",sx:{width:r?"100%":"auto","& .MuiToggleButton-root":{flex:r?1:"none"}},children:[e.jsx(te,{value:"event_count",children:d("admin.meter.events.eventCount")}),e.jsx(te,{value:"total_value",children:d("admin.meter.events.totalValue")})]})})]}),e.jsx(pe,{sx:{mb:3},children:e.jsx(x,{sx:{height:r?250:300,position:"relative",pr:r?1:2,pl:r?.5:1},children:o.statsLoading?e.jsx(x,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0},children:e.jsx(xe,{variant:"rectangular",width:"100%",height:"100%"})}):e.jsx(ze,{width:"100%",height:"100%",children:e.jsxs(Re,{data:P,margin:{top:10,right:r?10:30,left:r?5:10,bottom:p==="hour"?r?50:60:r?30:40},children:[e.jsx(Ne,{strokeDasharray:"3 3"}),e.jsx(We,{dataKey:"date",tick:{fontSize:r?10:11},angle:p==="hour"?-45:0,textAnchor:p==="hour"?"end":"middle",height:p==="hour"?r?50:60:r?30:40,interval:(()=>{const t=P.length;return r?t>20?Math.floor(t/6):t>10?Math.floor(t/4):t>5?1:0:p==="hour"?t>24?Math.floor(t/12):t>12?1:0:t>30?Math.floor(t/15):t>15?1:0})()}),e.jsx(Ue,{tick:{fontSize:r?9:11},width:r?35:40,tickFormatter:t=>r&&t>=1e3?`${(t/1e3).toFixed(1)}k`:t.toString()}),e.jsx(Ge,{labelFormatter:t=>P.find(f=>f.date===t)?.fullDate||t,formatter:(t,u)=>[u==="event_count"?t:ne(t,a.decimal),d(u==="event_count"?"admin.meter.events.eventCount":"admin.meter.events.totalValue")],contentStyle:{fontSize:r?"12px":"14px",padding:r?"8px":"10px"}}),e.jsx($e,{type:"monotone",dataKey:o.chartType,stroke:o.chartType==="event_count"?"#8884d8":"#82ca9d",fill:o.chartType==="event_count"?"#8884d8":"#82ca9d",fillOpacity:.6,strokeWidth:r?1.5:2})]})})})}),e.jsx(x,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:e.jsx(A,{variant:"body2",sx:{color:"text.secondary"},children:d("admin.meter.events.count",{count:g.count})})}),e.jsx(le,{data:g.list,columns:me,onChange:h,options:{count:g.count,page:m.page-1,rowsPerPage:m.pageSize,responsive:r?"vertical":"standard"},loading:s,emptyNodeText:d("admin.meter.events.empty")}),e.jsx(ge,{id:ce,open:ee,anchorEl:o.anchorEl,onClose:()=>l({anchorEl:null}),anchorOrigin:{vertical:"bottom",horizontal:"right"},children:e.jsx(Be,{open:!0,toggle:v,maxDate:n,definedRanges:Fe(n.toISOString()),onChange:L})}),e.jsx(Qe,{open:o.addUsageDialog,onClose:j,meterId:c,customers:o.customers,paymentCurrency:a,onSuccess:V})]})}const st=c=>_.get(`/api/products?meter_id=${c}`).then(a=>a.data),it=c=>_.get(`/api/products?type=credit&meter_id=${c}`).then(a=>a.data);function ot({meterId:c,meter:a=void 0}){const{t:d,locale:r}=G(),{settings:C}=de(),[n,m]=M.useState([]),[i,g]=M.useState(!1),[k,s]=M.useState(!1),[o,l]=M.useState(null),[p,P]=M.useState("credit"),I=async(E=p)=>{g(!0),l(null);try{const b=E==="meter"?await st(c):await it(c);m(b.list)}catch(b){console.error("Failed to fetch products:",b),l("Failed to load products")}finally{g(!1)}};M.useEffect(()=>{I()},[c,p]);const N=(E,b)=>{P(b)},h=()=>{s(!0)},v=()=>{s(!1),I()};if(o)return e.jsx(W,{severity:"error",sx:{mt:1},children:o});const L=[{label:d("admin.product.name.label"),name:"name",options:{filter:!1,customBodyRenderLite:(E,b)=>{const j=n[b];if(!j)return null;const V=we(C.paymentMethods,j.prices[0]?.currency_id??"")||C.baseCurrency;return e.jsx(R,{to:`/admin/products/${j.id}`,children:e.jsx(qe,{name:j.name,description:Ye(j,V,r),logo:j.images[0]})})}}},{label:d("common.status"),name:"active",options:{filter:!1,customBodyRenderLite:(E,b)=>{const j=n[b];return j?e.jsx(R,{to:`/admin/products/${j.id}`,children:e.jsx(ke,{label:j?.active?"Active":"Archived",color:j?.active?"success":"default"})}):null}}},{label:d("common.createdAt"),name:"created_at",options:{sort:!1,customBodyRenderLite:(E,b)=>{const j=n[b];return j?e.jsx(R,{to:`/admin/products/${j.id}`,children:U(j.created_at)}):null}}},{label:d("common.actions"),name:"id",width:100,align:"center",options:{sort:!1,customBodyRenderLite:(E,b)=>{const j=n[b];return j?e.jsx(Ke,{data:j,onChange:()=>I()}):null}}}],O=p==="meter"?{text:d("admin.meter.products.emptyTip"),buttonText:d("admin.meter.products.create")}:{text:d("admin.meter.creditProducts.emptyTip"),buttonText:d("admin.creditProduct.create")};return e.jsxs(x,{children:[e.jsx(w,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(he,{value:p,onChange:N,sx:{flex:"1 0 auto",maxWidth:"100%",fontSize:14,borderBottom:1,borderColor:"divider",".Mui-selected":{fontSize:"14px !important",color:"primary.main"}},children:[e.jsx(ae,{label:d("admin.meter.products.creditCharge"),value:"credit"}),e.jsx(ae,{label:d("admin.meter.products.meterService"),value:"meter"})]})}),e.jsx(w,{direction:"row",sx:{justifyContent:"flex-end",mb:2},children:e.jsx(T,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link",float:"right"},startIcon:e.jsx(X,{}),onClick:h,children:d(p==="meter"?"admin.meter.products.create":"admin.creditProduct.create")})}),e.jsx(le,{hasRowLink:!0,data:n,columns:L,options:{count:n.length,page:0,rowsPerPage:n.length,pagination:!1,search:!1,filter:!1,sort:!1,viewColumns:!1,download:!1,print:!1,selectableRows:"none"},loading:i,emptyNodeText:e.jsxs(x,{children:[e.jsx(A,{children:O.text}),e.jsx(T,{size:"small",variant:"text",startIcon:e.jsx(X,{}),onClick:h,sx:{mt:1,color:"text.link"},children:O.buttonText})]})}),k&&e.jsx(Ve,{open:k,onClose:v,onSubmit:()=>I(p),mode:p==="credit"?"credit":"standard",meterId:c,initialPrice:p==="meter"?{currency_id:a?.currency_id||"",priceModel:"credit_metered"}:{metadata:{credit_config:{currency_id:a?.currency_id||""}},name:a?.unit||""}})]})}const dt=c=>_.get(`/api/meters/${c}`).then(a=>a.data);function Ut(c){const{t:a}=G(),{isMobile:d}=Q(),r=Oe(),C=h=>{switch(h){case"sum":return a("admin.meter.aggregationMethod.sumHint");case"count":return a("admin.meter.aggregationMethod.countHint");case"last":return a("admin.meter.aggregationMethod.lastHint");default:return""}},[n,m]=J({editing:{metadata:!1,meter:!1},loading:{metadata:!1,meter:!1},creating:{product:!1,creditProduct:!1},tokenConfig:{name:"",symbol:"",tokenFactoryAddress:""}}),i=Se({defaultValues:{name:"",event_name:"",aggregation_method:"sum",unit:"",description:"",metadata:{},mode:"OffChain"}}),{loading:g,error:k,data:s,runAsync:o}=ie(()=>dt(c.id));if(k)return e.jsx(W,{severity:"error",children:k.message});if(g||!s)return e.jsx(ye,{});const l=async h=>{try{m(v=>({loading:{...v.loading,metadata:!0}})),await _.put(`/api/meters/${c.id}`,h),Y.success(a("common.saved")),o()}catch(v){console.error(v),Y.error(Z(v))}finally{m(v=>({loading:{...v.loading,metadata:!1}}))}},p=h=>{h==="delete"?r("/admin/billing/meters"):o()},P=()=>{m(h=>({editing:{...h.editing,metadata:!0}}))},I=()=>{const h=!!s.paymentCurrency?.token_config;i.reset({name:s.name,event_name:s.event_name,aggregation_method:s.aggregation_method,unit:s.unit,description:s.description||"",metadata:s.metadata||{},mode:h?"OnChain":"OffChain"}),m(v=>({editing:{...v.editing,meter:!0},tokenConfig:{name:"",symbol:"",tokenFactoryAddress:""}}))},N=async h=>{try{m(S=>({loading:{...S.loading,meter:!0}}));const v=s.paymentCurrency?.id,L=!!s.paymentCurrency?.token_config;if(v&&!L&&h.mode==="OnChain"){let{tokenFactoryAddress:S}=n.tokenConfig;if(!S&&n.tokenConfig.symbol){const{data:O}=await _.post("/api/credit-tokens",{name:n.tokenConfig.name,symbol:n.tokenConfig.symbol});S=O.address}S&&await _.put(`/api/payment-currencies/${v}/token-config`,{token_factory_address:S})}v&&L&&h.mode==="OffChain"&&await _.delete(`/api/payment-currencies/${v}/token-config`),delete h.mode,await _.put(`/api/meters/${c.id}`,h),Y.success(a("admin.meter.saved")),m(S=>({editing:{...S.editing,meter:!1}})),o()}catch(v){console.error(v),Y.error(Z(v))}finally{m(v=>({loading:{...v.loading,meter:!1}}))}};return e.jsxs(lt,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(x,{children:[s.status==="inactive"&&e.jsxs(W,{severity:"warning",sx:{mb:2},children:[e.jsx(ve,{children:a("admin.meter.inactive")}),a("admin.meter.inactiveTip")]}),e.jsxs(w,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(w,{direction:"row",onClick:()=>Le("/admin/meters"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(je,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(A,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:a("admin.meters")})]}),e.jsx(Pe,{data:s,variant:"normal",onChange:p})]}),e.jsxs(x,{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(w,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsx(w,{direction:"row",spacing:1,sx:{alignItems:"center"},children:e.jsxs(w,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:[e.jsx(A,{variant:"h2",sx:{color:"text.primary"},children:s.name}),e.jsxs(A,{variant:"subtitle1",sx:{color:"text.lighter"},children:[s.event_name," • ",s.unit]})]})})}),e.jsxs(w,{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(K,{label:a("common.id"),value:e.jsx(Ee,{text:c.id,style:{marginLeft:4}}),divider:!0}),e.jsx(K,{label:a("common.createdAt"),value:U(s.created_at),divider:!0}),s.paymentCurrency?.recharge_config?.base_price_id&&e.jsx(K,{label:a("admin.meter.rechargePackage.priceId"),tip:a("admin.meter.rechargePackage.tooltip",{name:s.paymentCurrency.name}),value:e.jsx(T,{variant:"text",size:"small",onClick:()=>r(`/admin/products/${s.paymentCurrency.recharge_config.base_price_id}`),sx:{p:0,minWidth:"auto",textAlign:"left",ml:.5,color:"text.link"},children:s.paymentCurrency.recharge_config.base_price_id}),divider:!0})]})]}),e.jsx($,{})]}),e.jsxs(w,{sx:{flexDirection:{xs:"column",lg:"row"},gap:{xs:2.5,md:4},".meter-column-1":{minWidth:{xs:"100%",lg:"600px"}},".meter-column-2":{width:{xs:"100%",md:"100%",lg:"320px"},maxWidth:{xs:"100%",md:"33%"}}},children:[e.jsxs(x,{className:"meter-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(x,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(B,{title:a("admin.details"),children:e.jsx(T,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:n.editing.meter,onClick:I,children:a("common.edit")})}),e.jsxs(Te,{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(z,{label:a("admin.meter.name.label"),value:s.name}),e.jsx(z,{label:a("admin.meter.eventName.label"),value:s.event_name}),e.jsx(z,{label:a("admin.meter.aggregationMethod.label"),value:s.aggregation_method}),e.jsx(z,{label:a("admin.meter.unit.label"),value:s.unit}),e.jsx(z,{label:a("admin.meter.description.label"),value:s.description||"-"}),e.jsx(z,{label:a("common.updatedAt"),value:U(s.updated_at)})]})]}),e.jsx($,{}),e.jsxs(x,{className:"section",children:[e.jsx(B,{title:a("admin.meter.events.title")}),e.jsx(x,{className:"section-body",children:e.jsx(rt,{meterId:s.id,paymentCurrency:s.paymentCurrency})})]}),e.jsx($,{}),e.jsxs(x,{className:"section",children:[e.jsx(x,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:e.jsx(B,{title:a("admin.meter.products.title")})}),e.jsx(x,{className:"section-body",children:e.jsx(ot,{meterId:s.id,meter:s})})]})]}),d&&e.jsx($,{}),e.jsxs(x,{className:"meter-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(x,{className:"section",children:[e.jsx(B,{title:a("admin.meter.usageGuide.title")}),e.jsx(x,{className:"section-body",children:e.jsx(W,{severity:"info",sx:{mb:2},children:e.jsx(A,{variant:"body2",children:a("admin.meter.usageGuide.tip",{eventName:s.event_name,aggregationMethodHint:C(s.aggregation_method),unit:s.unit})})})})]}),e.jsx($,{}),e.jsxs(x,{className:"section",children:[e.jsx(B,{title:a("common.metadata.label"),children:e.jsx(T,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:n.editing.metadata,onClick:P,children:a("common.edit")})}),e.jsxs(x,{className:"section-body",children:[e.jsx(Ae,{data:s.metadata,handleEditMetadata:P}),n.editing.metadata&&e.jsx(Ie,{data:s,loading:n.loading.metadata,onSave:l,onCancel:()=>m(h=>({editing:{...h.editing,metadata:!1}}))})]})]})]})]}),n.editing.meter&&e.jsx(Ze,{icon:e.jsx(be,{}),text:a("admin.meter.edit"),open:n.editing.meter,onClose:()=>m(h=>({editing:{...h.editing,meter:!1}})),width:640,addons:e.jsx(T,{variant:"contained",size:"small",disabled:n.loading.meter,onClick:i.handleSubmit(N),children:a("admin.meter.save")}),children:e.jsx(Me,{...i,children:e.jsx(Xe,{mode:"edit",paymentCurrency:s.paymentCurrency,tokenConfig:n.tokenConfig,onTokenConfigChange:h=>m({tokenConfig:h})})})})]})}const lt=Ce(w)``;export{Ut as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as F,j as e,aQ as ee,aT as te,ad as R,a3 as m,q as x,$ as z,w as O,I as ie,ci as se,u as re,O as U,bX as ne,A as E,B as c,z as ae,bv as oe,N as B,Y as C,x as I,be as ce,bf as le}from"./vendor-mui-BXZut9Pz.js";import{V as M,Y as H,Z as k,P as de}from"./vendor-blocklet-DcLR2Cyf.js";import{a as L,Y as q,e as S,k as A,x as me,f as xe,n as pe,j as N,T as ue,d as ge,b8 as D}from"./index-BarN7DfU.js";import{l as he}from"./lodash-B4Ozcv0x.js";import{C as Y}from"./copyable-QrCyyiou.js";import{E as fe}from"./list-DaK9287Y.js";import{I as $}from"./info-metric-Dl4ZDm0Z.js";import{I as _}from"./info-row-jI0h_hv4.js";import{I as je}from"./info-row-group-CFuMWJf1.js";import{M as ye}from"./editor-AmthipP2.js";import{M as be}from"./list-CkHExntK.js";import{P as ve}from"./actions-CSpJGOX7.js";import{A as _e}from"./add-price-BpnICuHO.js";import{u as G,P as Ce}from"./product-select-ChEyoJqJ.js";import{m as Q,n as T,g as we}from"./util-DxXTXkeY.js";import{I as V}from"./info-card-BvIMFQo5.js";import{E as ke}from"./edit-Bkj-OTJh.js";import{S as w}from"./header-ivXuPt06.js";import{L as Pe,a as Se}from"./vendor-react-BPknnnEA.js";import{P as Ie}from"./actions-BD9BAp3M.js";import"./table-BrtHemkA.js";import"./form-CAPjlw7l.js";import"./actions-BJDN6Op2.js";import"./click-boundary-CafubiPp.js";import"./assign-0vMUDW_C.js";import"./form-cX026J4G.js";import"./collapse-CSrlJ0eG.js";import"./currency-select-B4ieQBvv.js";import"./currency-GstdXsJf.js";import"./uploader-CsQNHG4I.js";import"./tax-code-select-TS07I0rB.js";import"./collapse-BvbJGg1V.js";function Ae({data:r,onSelect:i,valid:o}){const{t:b,locale:j}=M(),{products:y}=G(),{settings:d}=L(),[p,n]=F.useState("empty"),g=t=>{t.target.value&&t.target.value!=="empty"&&(n(t.target.value),i(t.target.value))},a=q(d.paymentMethods,r?.default_price?.currency_id||"")||d.baseCurrency;return e.jsx(ee,{error:!o,sx:{width:"100%"},children:e.jsxs(te,{value:p,sx:{minWidth:300},size:"small",onChange:g,MenuProps:{style:{maxHeight:480}},children:[e.jsx(R,{value:"empty",children:e.jsx(m,{direction:"row",sx:{alignItems:"center"},children:e.jsx(x,{children:b("admin.product.find")})})}),y.filter(t=>t.id!==r.id&&Q(t,r)).map(t=>e.jsx(R,{value:t.id,children:e.jsx(V,{name:t.name,description:T(t,a,j),logo:t.images[0]})},t.id))]})})}function Ne({data:r,onChange:i}){const{locale:o,t:b}=M(),{settings:j}=L(),[y,d]=H({loading:!1}),{products:p}=G(),[n,g]=F.useState(!1),a=async()=>{try{d({loading:!0}),await S.put(`/api/products/${r.id}`,{cross_sell:{cross_sells_to_id:""}}).then(l=>l.data),d({loading:!1}),i()}catch(l){console.error(l),k.error(A(l)),d({loading:!1})}},t=async l=>{try{const v=p.find(P=>P.id===l);if(!v)throw new Error("no product found");if(!Q(v,r)){g(!0);return}d({loading:!0}),await S.put(`/api/products/${r.id}`,{cross_sell:{cross_sells_to_id:l}}).then(P=>P.data),d({loading:!1}),i()}catch(v){console.error(v),k.error(A(v)),d({loading:!1})}};if(y.loading)return e.jsx(O,{});const f=q(j.paymentMethods,r?.default_price?.currency_id||"")||j.baseCurrency;if(r.cross_sell?.cross_sells_to_id){const l=r.cross_sell.cross_sells_to;return e.jsxs(m,{spacing:1,direction:"row",sx:{alignItems:"center"},children:[e.jsx(V,{name:l.name,description:T(l,f,o),logo:l.images[0]}),e.jsx(ie,{size:"small",sx:{ml:1},onClick:a,children:e.jsx(se,{color:"error",sx:{opacity:.75}})})]})}return e.jsxs(e.Fragment,{children:[e.jsx(Ae,{data:r,onSelect:t,valid:!n}),n&&e.jsx(x,{color:"error",children:b("admin.product.currencyNotAligned")})]})}function Me({data:r,onChange:i}){return e.jsx(Ce,{children:e.jsx(z,{container:!0,children:e.jsx(z,{size:{xs:12},children:e.jsx(Ne,{data:r,onChange:i})})})})}function Le({product:r,onChange:i}){const{t:o,locale:b}=M(),{settings:j}=L(),y=re(),d=me(window.location.href),p=[{label:o("admin.price.name"),name:"name",minWidth:180,options:{sort:!1,customBodyRenderLite:(n,g)=>{const a=r.prices[g],t=d.price_id===a.id&&d.currency_id,f=t?q(j.paymentMethods,d.currency_id||""):a.currency,l=y.palette.mode==="dark"?"#2e3035":"#FFF9C4";return e.jsx(Pe,{to:`/admin/products/${a.id}`,color:"text.primary",children:e.jsxs(m,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[a.locked&&e.jsx(U,{title:o("admin.price.locked"),children:e.jsx(ne,{sx:{color:"text.secondary"}})}),e.jsx(x,{component:"span",sx:{backgroundColor:t?l:"transparent",whiteSpace:"nowrap"},children:xe(a,f||a.currency,"",1,!0,b)}),e.jsx(x,{component:"span",children:a.id===r.default_price_id&&e.jsx(pe,{label:"default",color:"info",sx:{height:18}})})]})})}}},{label:o("common.id"),name:"id",options:{sort:!1,customBodyRender:n=>e.jsx(Y,{text:n})}},{label:o("common.createdAt"),name:"created_at",minWidth:120,options:{sort:!0,customBodyRender:n=>N(n)}},{label:o("common.updatedAt"),name:"updated_at",minWidth:120,options:{customBodyRender:n=>N(n)}},{label:o("admin.price.inventory"),name:"id",minWidth:120,options:{sort:!1,customBodyRenderLite:(n,g)=>{const a=r.prices[g];let t="";return a.nickname&&(t=`${a.nickname}:`),t+=`${a.quantity_available?o("admin.price.quantityAvailable.format",{num:a.quantity_available}):o("admin.price.quantityAvailable.noLimit")}`,t+=` / ${o("admin.price.quantitySold.format",{num:a.quantity_sold})}`,t+=` / ${a.quantity_limit_per_checkout?o("admin.price.quantityLimitPerCheckout.format",{num:a.quantity_limit_per_checkout}):o("admin.price.quantityLimitPerCheckout.noLimit")}`,t}}},{label:o("common.actions"),name:"id",width:100,align:"center",options:{sort:!1,customBodyRenderLite:(n,g)=>{const a=r.prices[g];return e.jsx(Ie,{data:a,onChange:i,setAsDefault:a.id===r.default_price_id,product:r})}}}];return e.jsx(ue,{toolbar:!1,footer:!1,data:r.prices,columns:p,options:{count:r.prices.length,page:0,rowsPerPage:20},emptyNodeText:o("empty.pricing")})}const qe=r=>S.get(`/api/products/${r}`).then(i=>i.data);function pt(r){const{t:i,locale:o}=M(),{isMobile:b}=ge(),j=Se(),{settings:y,setLivemode:d}=L(),[p,n]=H({adding:{price:!1},editing:{metadata:!1,product:!1},loading:{metadata:!1,price:!1,product:!1}}),{loading:g,error:a,data:t,runAsync:f}=de(()=>qe(r.id),{onSuccess:s=>{d(!!s.livemode)}});if(a)return e.jsx(E,{severity:"error",children:a.message});if(g||!t)return e.jsx(O,{});const l=s=>async u=>{try{n(h=>({loading:{...h.loading,[s]:!0}})),await S.put(`/api/products/${r.id}`,u).then(h=>h.data),k.success(i("common.saved")),D("product.updated"),f()}catch(h){console.error(h),k.error(A(h))}finally{n(h=>({loading:{...h.loading,[s]:!1}}))}},v=async s=>{try{n(u=>({loading:{...u.loading,price:!0}})),await S.post("/api/prices",{...s,product_id:r.id}),k.success(i("common.saved")),D("price.created"),f()}catch(u){throw console.error(u),k.error(A(u)),u}finally{n(u=>({loading:{...u.loading,price:!1}}))}},P=l("metadata"),X=l("product"),Z=s=>{s==="remove"?j("/admin/products"):f()},J=t.locked||!he.isEmpty(t.prices)&&t.prices.some(s=>s.locked),W=()=>{n(s=>({editing:{...s.editing,metadata:!0}}))},K=q(y.paymentMethods,t?.default_price?.currency_id)||y.baseCurrency;return e.jsxs(Ee,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(c,{children:[t.active===!1&&e.jsxs(E,{severity:"warning",children:[e.jsx(ae,{children:i("admin.product.archived")}),i("admin.product.archivedTip")]}),J&&e.jsx(E,{severity:"warning",sx:{mb:1},children:i("admin.product.locked")}),e.jsxs(m,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(m,{direction:"row",onClick:()=>we("/admin/products"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(oe,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(x,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:i("admin.products")})]}),e.jsx(ve,{data:t,onChange:Z,variant:"normal"})]}),e.jsxs(c,{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(m,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(m,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[t.images.length>0&&e.jsx(B,{src:t.images[0],alt:t.name,variant:"square",sx:{width:"52px",height:"52px"}}),e.jsxs(m,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:[e.jsx(x,{variant:"h2",sx:{color:"text.primary"},children:t.name}),e.jsx(x,{variant:"subtitle1",sx:{color:"text.lighter"},children:T(t,K,o)})]})]})}),e.jsxs(m,{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($,{label:i("common.id"),value:e.jsx(Y,{text:r.id,style:{marginLeft:4}}),divider:!0}),e.jsx($,{label:i("common.createdAt"),value:N(t.created_at),divider:!0})]})]}),e.jsx(C,{})]}),e.jsxs(m,{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(c,{className:"payment-link-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(c,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(w,{title:i("admin.details"),children:e.jsx(I,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},onClick:()=>n(s=>({editing:{...s.editing,product:!0}})),children:i("common.edit")})}),e.jsxs(je,{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(_,{label:i("admin.product.name.label"),value:t.name}),e.jsx(_,{label:i("admin.product.description.label"),value:t.description}),e.jsx(_,{label:i("admin.product.statement_descriptor.label"),value:t.statement_descriptor}),e.jsx(_,{label:i("admin.product.unit_label.label"),value:t.unit_label}),e.jsx(_,{label:i("admin.product.features.label"),value:t.features.map(s=>s.name).join(",")}),e.jsx(_,{label:i("common.updatedAt"),value:N(t.updated_at)}),e.jsx(_,{label:i("admin.product.image.label"),value:t.images.length?e.jsx(B,{src:t.images[0],alt:t.name,variant:"square",sx:{width:"160px",height:"160px"}}):e.jsx(x,{variant:"body2",sx:{color:"text.lighter"},children:i("empty.image")})}),p.editing.product&&e.jsx(ke,{product:t,loading:p.loading.product,onSave:X,onCancel:()=>n(s=>({editing:{...s.editing,product:!1}}))})]})]}),e.jsx(C,{}),e.jsxs(c,{className:"section",children:[e.jsx(w,{title:i("admin.product.pricing"),children:e.jsx(I,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},onClick:()=>n(s=>({adding:{...s.adding,price:!0}})),children:i("admin.price.add")})}),e.jsxs(c,{className:"section-body",children:[e.jsx(Le,{product:t,onChange:f}),p.adding.price&&e.jsx(_e,{loading:p.loading.price,onSave:v,productType:t.type,onCancel:()=>n(s=>({adding:{...s.adding,price:!1}}))})]})]}),e.jsx(C,{}),t.type==="service"&&e.jsxs(e.Fragment,{children:[e.jsxs(c,{className:"section",children:[e.jsx(w,{title:i("admin.product.vendorConfig.title"),children:e.jsx(I,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},onClick:()=>n(s=>({editing:{...s.editing,product:!0}})),children:i("common.edit")})}),e.jsx(c,{className:"section-body",children:t.vendor_config&&t.vendor_config.length>0?e.jsxs(m,{spacing:2,children:[(()=>{const s=t.vendor_config.filter(u=>u.commission_type==="percentage").reduce((u,h)=>u+(h.commission_rate||0),0);return e.jsx(x,{variant:"body2",sx:{color:"text.secondary",mb:1},children:i("admin.product.vendorConfig.totalCommission",{total:s.toFixed(0)})})})(),t.vendor_config.map(s=>e.jsx(c,{sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:1,backgroundColor:"background.paper",maxWidth:"600px"},children:e.jsxs(m,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(c,{children:[e.jsx(x,{variant:"body1",sx:{color:"text.primary",fontWeight:500},children:s.name||s.vendor_key||s.vendor_id}),s.description&&e.jsx(x,{variant:"body2",sx:{color:"text.secondary",mt:.5},children:s.description})]}),e.jsxs(m,{direction:"row",spacing:3,sx:{alignItems:"center"},children:[e.jsx(x,{variant:"body2",sx:{color:"text.secondary"},children:s.commission_type==="percentage"?i("admin.vendor.commission"):i("admin.vendor.fixedAmount")}),e.jsxs(x,{variant:"body1",sx:{color:"text.primary",fontWeight:600},children:[s.commission_rate,s.commission_type==="percentage"?"%":""]})]})]})},`vendor-${s.vendor_id}`))]}):e.jsx(x,{variant:"body2",sx:{color:"text.secondary",textAlign:"center",py:2},children:i("admin.product.vendorConfig.empty")})})]}),e.jsx(C,{})]}),e.jsxs(c,{className:"section",children:[e.jsx(w,{title:i("admin.events.title")}),e.jsx(c,{className:"section-body",children:e.jsx(fe,{features:{toolbar:!1},object_id:[t.id,...t.prices.map(s=>s.id)].join(",")})})]})]}),b&&e.jsx(C,{}),e.jsxs(c,{className:"payment-link-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(c,{className:"section",children:[e.jsx(w,{title:e.jsxs(m,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(x,{variant:"h3",sx:{fontSize:{xs:"18px",md:"1.09375rem"}},children:i("admin.product.cross_sell.title")}),e.jsx(U,{title:i("admin.product.currencyNotAligned"),children:e.jsx(ce,{sx:{color:"text.lighter"},fontSize:"small"})})]})}),e.jsx(c,{className:"section-body",children:e.jsx(Me,{data:t,onChange:f})})]}),e.jsx(C,{}),e.jsxs(c,{className:"section",children:[e.jsx(w,{title:i("common.metadata.label"),children:e.jsx(I,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:p.editing.metadata,onClick:W,children:i("common.edit")})}),e.jsxs(c,{className:"section-body",children:[e.jsx(be,{data:t.metadata,handleEditMetadata:W}),p.editing.metadata&&e.jsx(ye,{data:t,loading:p.loading.metadata,onSave:P,onCancel:()=>n(s=>({editing:{...s.editing,metadata:!1}}))})]})]})]})]})]})}const Ee=le(m)``;export{pt as default};
|
|
1
|
+
import{r as F,j as e,aQ as ee,aT as te,ad as R,a3 as m,q as x,$ as z,w as O,I as ie,ci as se,u as re,O as U,bX as ne,A as E,B as c,z as ae,bv as oe,N as B,Y as C,x as I,be as ce,bf as le}from"./vendor-mui-BXZut9Pz.js";import{V as M,Y as H,Z as k,P as de}from"./vendor-blocklet-B67R14so.js";import{a as L,Y as q,e as S,k as A,x as me,f as xe,n as pe,j as N,T as ue,d as ge,b8 as D}from"./index-B4yaPb7B.js";import{l as he}from"./lodash-B4Ozcv0x.js";import{C as Y}from"./copyable-CprMHdhV.js";import{E as fe}from"./list-CvM46TsP.js";import{I as $}from"./info-metric-ukWq8INi.js";import{I as _}from"./info-row-CaPaNF4L.js";import{I as je}from"./info-row-group-Cxo-4Gk5.js";import{M as ye}from"./editor-vZvxDUTl.js";import{M as be}from"./list-B2b-s8wM.js";import{P as ve}from"./actions-C9AfME83.js";import{A as _e}from"./add-price-TdXAR3NW.js";import{u as G,P as Ce}from"./product-select-_72p-5lF.js";import{m as Q,n as T,g as we}from"./util-B8B3fsMa.js";import{I as V}from"./info-card-C9dRgztS.js";import{E as ke}from"./edit-DAU8AWzT.js";import{S as w}from"./header-ivXuPt06.js";import{L as Pe,a as Se}from"./vendor-react-BPknnnEA.js";import{P as Ie}from"./actions-D2-s31n3.js";import"./table-BN3WBnr3.js";import"./form-CnrBCyTJ.js";import"./actions-BEUwbsq1.js";import"./click-boundary-Bi28Y0Fq.js";import"./assign-DKRfmN7W.js";import"./form-AFzUvoFE.js";import"./collapse-CSrlJ0eG.js";import"./currency-select-C8j7QQMP.js";import"./currency-GstdXsJf.js";import"./uploader-BLdAbLR6.js";import"./tax-code-select-j2arPbaE.js";import"./collapse-BvbJGg1V.js";function Ae({data:r,onSelect:i,valid:o}){const{t:b,locale:j}=M(),{products:y}=G(),{settings:d}=L(),[p,n]=F.useState("empty"),g=t=>{t.target.value&&t.target.value!=="empty"&&(n(t.target.value),i(t.target.value))},a=q(d.paymentMethods,r?.default_price?.currency_id||"")||d.baseCurrency;return e.jsx(ee,{error:!o,sx:{width:"100%"},children:e.jsxs(te,{value:p,sx:{minWidth:300},size:"small",onChange:g,MenuProps:{style:{maxHeight:480}},children:[e.jsx(R,{value:"empty",children:e.jsx(m,{direction:"row",sx:{alignItems:"center"},children:e.jsx(x,{children:b("admin.product.find")})})}),y.filter(t=>t.id!==r.id&&Q(t,r)).map(t=>e.jsx(R,{value:t.id,children:e.jsx(V,{name:t.name,description:T(t,a,j),logo:t.images[0]})},t.id))]})})}function Ne({data:r,onChange:i}){const{locale:o,t:b}=M(),{settings:j}=L(),[y,d]=H({loading:!1}),{products:p}=G(),[n,g]=F.useState(!1),a=async()=>{try{d({loading:!0}),await S.put(`/api/products/${r.id}`,{cross_sell:{cross_sells_to_id:""}}).then(l=>l.data),d({loading:!1}),i()}catch(l){console.error(l),k.error(A(l)),d({loading:!1})}},t=async l=>{try{const v=p.find(P=>P.id===l);if(!v)throw new Error("no product found");if(!Q(v,r)){g(!0);return}d({loading:!0}),await S.put(`/api/products/${r.id}`,{cross_sell:{cross_sells_to_id:l}}).then(P=>P.data),d({loading:!1}),i()}catch(v){console.error(v),k.error(A(v)),d({loading:!1})}};if(y.loading)return e.jsx(O,{});const f=q(j.paymentMethods,r?.default_price?.currency_id||"")||j.baseCurrency;if(r.cross_sell?.cross_sells_to_id){const l=r.cross_sell.cross_sells_to;return e.jsxs(m,{spacing:1,direction:"row",sx:{alignItems:"center"},children:[e.jsx(V,{name:l.name,description:T(l,f,o),logo:l.images[0]}),e.jsx(ie,{size:"small",sx:{ml:1},onClick:a,children:e.jsx(se,{color:"error",sx:{opacity:.75}})})]})}return e.jsxs(e.Fragment,{children:[e.jsx(Ae,{data:r,onSelect:t,valid:!n}),n&&e.jsx(x,{color:"error",children:b("admin.product.currencyNotAligned")})]})}function Me({data:r,onChange:i}){return e.jsx(Ce,{children:e.jsx(z,{container:!0,children:e.jsx(z,{size:{xs:12},children:e.jsx(Ne,{data:r,onChange:i})})})})}function Le({product:r,onChange:i}){const{t:o,locale:b}=M(),{settings:j}=L(),y=re(),d=me(window.location.href),p=[{label:o("admin.price.name"),name:"name",minWidth:180,options:{sort:!1,customBodyRenderLite:(n,g)=>{const a=r.prices[g],t=d.price_id===a.id&&d.currency_id,f=t?q(j.paymentMethods,d.currency_id||""):a.currency,l=y.palette.mode==="dark"?"#2e3035":"#FFF9C4";return e.jsx(Pe,{to:`/admin/products/${a.id}`,color:"text.primary",children:e.jsxs(m,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[a.locked&&e.jsx(U,{title:o("admin.price.locked"),children:e.jsx(ne,{sx:{color:"text.secondary"}})}),e.jsx(x,{component:"span",sx:{backgroundColor:t?l:"transparent",whiteSpace:"nowrap"},children:xe(a,f||a.currency,"",1,!0,b)}),e.jsx(x,{component:"span",children:a.id===r.default_price_id&&e.jsx(pe,{label:"default",color:"info",sx:{height:18}})})]})})}}},{label:o("common.id"),name:"id",options:{sort:!1,customBodyRender:n=>e.jsx(Y,{text:n})}},{label:o("common.createdAt"),name:"created_at",minWidth:120,options:{sort:!0,customBodyRender:n=>N(n)}},{label:o("common.updatedAt"),name:"updated_at",minWidth:120,options:{customBodyRender:n=>N(n)}},{label:o("admin.price.inventory"),name:"id",minWidth:120,options:{sort:!1,customBodyRenderLite:(n,g)=>{const a=r.prices[g];let t="";return a.nickname&&(t=`${a.nickname}:`),t+=`${a.quantity_available?o("admin.price.quantityAvailable.format",{num:a.quantity_available}):o("admin.price.quantityAvailable.noLimit")}`,t+=` / ${o("admin.price.quantitySold.format",{num:a.quantity_sold})}`,t+=` / ${a.quantity_limit_per_checkout?o("admin.price.quantityLimitPerCheckout.format",{num:a.quantity_limit_per_checkout}):o("admin.price.quantityLimitPerCheckout.noLimit")}`,t}}},{label:o("common.actions"),name:"id",width:100,align:"center",options:{sort:!1,customBodyRenderLite:(n,g)=>{const a=r.prices[g];return e.jsx(Ie,{data:a,onChange:i,setAsDefault:a.id===r.default_price_id,product:r})}}}];return e.jsx(ue,{toolbar:!1,footer:!1,data:r.prices,columns:p,options:{count:r.prices.length,page:0,rowsPerPage:20},emptyNodeText:o("empty.pricing")})}const qe=r=>S.get(`/api/products/${r}`).then(i=>i.data);function pt(r){const{t:i,locale:o}=M(),{isMobile:b}=ge(),j=Se(),{settings:y,setLivemode:d}=L(),[p,n]=H({adding:{price:!1},editing:{metadata:!1,product:!1},loading:{metadata:!1,price:!1,product:!1}}),{loading:g,error:a,data:t,runAsync:f}=de(()=>qe(r.id),{onSuccess:s=>{d(!!s.livemode)}});if(a)return e.jsx(E,{severity:"error",children:a.message});if(g||!t)return e.jsx(O,{});const l=s=>async u=>{try{n(h=>({loading:{...h.loading,[s]:!0}})),await S.put(`/api/products/${r.id}`,u).then(h=>h.data),k.success(i("common.saved")),D("product.updated"),f()}catch(h){console.error(h),k.error(A(h))}finally{n(h=>({loading:{...h.loading,[s]:!1}}))}},v=async s=>{try{n(u=>({loading:{...u.loading,price:!0}})),await S.post("/api/prices",{...s,product_id:r.id}),k.success(i("common.saved")),D("price.created"),f()}catch(u){throw console.error(u),k.error(A(u)),u}finally{n(u=>({loading:{...u.loading,price:!1}}))}},P=l("metadata"),X=l("product"),Z=s=>{s==="remove"?j("/admin/products"):f()},J=t.locked||!he.isEmpty(t.prices)&&t.prices.some(s=>s.locked),W=()=>{n(s=>({editing:{...s.editing,metadata:!0}}))},K=q(y.paymentMethods,t?.default_price?.currency_id)||y.baseCurrency;return e.jsxs(Ee,{direction:"column",spacing:2.5,sx:{mb:4},children:[e.jsxs(c,{children:[t.active===!1&&e.jsxs(E,{severity:"warning",children:[e.jsx(ae,{children:i("admin.product.archived")}),i("admin.product.archivedTip")]}),J&&e.jsx(E,{severity:"warning",sx:{mb:1},children:i("admin.product.locked")}),e.jsxs(m,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(m,{direction:"row",onClick:()=>we("/admin/products"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(oe,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(x,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:i("admin.products")})]}),e.jsx(ve,{data:t,onChange:Z,variant:"normal"})]}),e.jsxs(c,{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(m,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsxs(m,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[t.images.length>0&&e.jsx(B,{src:t.images[0],alt:t.name,variant:"square",sx:{width:"52px",height:"52px"}}),e.jsxs(m,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:[e.jsx(x,{variant:"h2",sx:{color:"text.primary"},children:t.name}),e.jsx(x,{variant:"subtitle1",sx:{color:"text.lighter"},children:T(t,K,o)})]})]})}),e.jsxs(m,{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($,{label:i("common.id"),value:e.jsx(Y,{text:r.id,style:{marginLeft:4}}),divider:!0}),e.jsx($,{label:i("common.createdAt"),value:N(t.created_at),divider:!0})]})]}),e.jsx(C,{})]}),e.jsxs(m,{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(c,{className:"payment-link-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(c,{className:"section",sx:{containerType:"inline-size"},children:[e.jsx(w,{title:i("admin.details"),children:e.jsx(I,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},onClick:()=>n(s=>({editing:{...s.editing,product:!0}})),children:i("common.edit")})}),e.jsxs(je,{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(_,{label:i("admin.product.name.label"),value:t.name}),e.jsx(_,{label:i("admin.product.description.label"),value:t.description}),e.jsx(_,{label:i("admin.product.statement_descriptor.label"),value:t.statement_descriptor}),e.jsx(_,{label:i("admin.product.unit_label.label"),value:t.unit_label}),e.jsx(_,{label:i("admin.product.features.label"),value:t.features.map(s=>s.name).join(",")}),e.jsx(_,{label:i("common.updatedAt"),value:N(t.updated_at)}),e.jsx(_,{label:i("admin.product.image.label"),value:t.images.length?e.jsx(B,{src:t.images[0],alt:t.name,variant:"square",sx:{width:"160px",height:"160px"}}):e.jsx(x,{variant:"body2",sx:{color:"text.lighter"},children:i("empty.image")})}),p.editing.product&&e.jsx(ke,{product:t,loading:p.loading.product,onSave:X,onCancel:()=>n(s=>({editing:{...s.editing,product:!1}}))})]})]}),e.jsx(C,{}),e.jsxs(c,{className:"section",children:[e.jsx(w,{title:i("admin.product.pricing"),children:e.jsx(I,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},onClick:()=>n(s=>({adding:{...s.adding,price:!0}})),children:i("admin.price.add")})}),e.jsxs(c,{className:"section-body",children:[e.jsx(Le,{product:t,onChange:f}),p.adding.price&&e.jsx(_e,{loading:p.loading.price,onSave:v,productType:t.type,onCancel:()=>n(s=>({adding:{...s.adding,price:!1}}))})]})]}),e.jsx(C,{}),t.type==="service"&&e.jsxs(e.Fragment,{children:[e.jsxs(c,{className:"section",children:[e.jsx(w,{title:i("admin.product.vendorConfig.title"),children:e.jsx(I,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},onClick:()=>n(s=>({editing:{...s.editing,product:!0}})),children:i("common.edit")})}),e.jsx(c,{className:"section-body",children:t.vendor_config&&t.vendor_config.length>0?e.jsxs(m,{spacing:2,children:[(()=>{const s=t.vendor_config.filter(u=>u.commission_type==="percentage").reduce((u,h)=>u+(h.commission_rate||0),0);return e.jsx(x,{variant:"body2",sx:{color:"text.secondary",mb:1},children:i("admin.product.vendorConfig.totalCommission",{total:s.toFixed(0)})})})(),t.vendor_config.map(s=>e.jsx(c,{sx:{p:2,border:"1px solid",borderColor:"divider",borderRadius:1,backgroundColor:"background.paper",maxWidth:"600px"},children:e.jsxs(m,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(c,{children:[e.jsx(x,{variant:"body1",sx:{color:"text.primary",fontWeight:500},children:s.name||s.vendor_key||s.vendor_id}),s.description&&e.jsx(x,{variant:"body2",sx:{color:"text.secondary",mt:.5},children:s.description})]}),e.jsxs(m,{direction:"row",spacing:3,sx:{alignItems:"center"},children:[e.jsx(x,{variant:"body2",sx:{color:"text.secondary"},children:s.commission_type==="percentage"?i("admin.vendor.commission"):i("admin.vendor.fixedAmount")}),e.jsxs(x,{variant:"body1",sx:{color:"text.primary",fontWeight:600},children:[s.commission_rate,s.commission_type==="percentage"?"%":""]})]})]})},`vendor-${s.vendor_id}`))]}):e.jsx(x,{variant:"body2",sx:{color:"text.secondary",textAlign:"center",py:2},children:i("admin.product.vendorConfig.empty")})})]}),e.jsx(C,{})]}),e.jsxs(c,{className:"section",children:[e.jsx(w,{title:i("admin.events.title")}),e.jsx(c,{className:"section-body",children:e.jsx(fe,{features:{toolbar:!1},object_id:[t.id,...t.prices.map(s=>s.id)].join(",")})})]})]}),b&&e.jsx(C,{}),e.jsxs(c,{className:"payment-link-column-2",sx:{gap:2.5,display:"flex",flexDirection:"column"},children:[e.jsxs(c,{className:"section",children:[e.jsx(w,{title:e.jsxs(m,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(x,{variant:"h3",sx:{fontSize:{xs:"18px",md:"1.09375rem"}},children:i("admin.product.cross_sell.title")}),e.jsx(U,{title:i("admin.product.currencyNotAligned"),children:e.jsx(ce,{sx:{color:"text.lighter"},fontSize:"small"})})]})}),e.jsx(c,{className:"section-body",children:e.jsx(Me,{data:t,onChange:f})})]}),e.jsx(C,{}),e.jsxs(c,{className:"section",children:[e.jsx(w,{title:i("common.metadata.label"),children:e.jsx(I,{variant:"text",color:"inherit",size:"small",sx:{color:"text.link"},disabled:p.editing.metadata,onClick:W,children:i("common.edit")})}),e.jsxs(c,{className:"section-body",children:[e.jsx(be,{data:t.metadata,handleEditMetadata:W}),p.editing.metadata&&e.jsx(ye,{data:t,loading:p.loading.metadata,onSave:P,onCancel:()=>n(s=>({editing:{...s.editing,metadata:!1}}))})]})]})]})]})]})}const Ee=le(m)``;export{pt as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,A as v,w as C,B as o,a3 as r,bv as I,q as p,x as A,N as D,Y as P,bf as N}from"./vendor-mui-BXZut9Pz.js";import{V as S,P as _}from"./vendor-blocklet-
|
|
1
|
+
import{j as e,A as v,w as C,B as o,a3 as r,bv as I,q as p,x as A,N as D,Y as P,bf as N}from"./vendor-mui-BXZut9Pz.js";import{V as S,P as _}from"./vendor-blocklet-B67R14so.js";import{d as R,i as B,a5 as W,n as M,a6 as T,a7 as f,j as L,p as q,e as z}from"./index-B4yaPb7B.js";import{I as y}from"./info-metric-ukWq8INi.js";import{I as l}from"./info-row-CaPaNF4L.js";import{S as H}from"./header-ivXuPt06.js";import{g as O}from"./util-B8B3fsMa.js";import{C as j}from"./link-DsltSF2Q.js";import{I as E}from"./info-row-group-Cxo-4Gk5.js";import{u as F}from"./browser-DF2vfpBa.js";import{e as G}from"./vendor-react-BPknnnEA.js";import"./lodash-B4Ozcv0x.js";const U=t=>z.get(`/api/payouts/${t}`).then(n=>n.data);function oe(){const{t,locale:n}=S(),{isMobile:g}=R(),h=F(),m=G(),{loading:w,error:c,data:s}=_(()=>U(m.id),{ready:!!m.id});if(c)return e.jsx(v,{severity:"error",children:c.message});if(w||!s)return e.jsx(C,{});const x=s.paymentCurrency,b=[B(s?.amount,x.decimal),x.symbol].join(" "),{paymentIntent:a,paymentLink:d}=s||{},i=a?.customer?.metadata?.anonymous;return e.jsxs(V,{direction:"column",spacing:2.5,mb:4,children:[e.jsxs(o,{children:[e.jsxs(r,{className:"page-header",direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:[h?e.jsx(o,{}):e.jsxs(r,{direction:"row",onClick:()=>O("/customer/payouts"),sx:{alignItems:"center",fontWeight:"normal",cursor:"pointer"},children:[e.jsx(I,{fontSize:"small",sx:{mr:.5,color:"text.secondary"}}),e.jsx(p,{variant:"h6",sx:{color:"text.secondary",fontWeight:"normal"},children:t("common.previous")})]}),d?.donation_settings?.reference&&e.jsx(A,{variant:"outlined",onClick:()=>{window.open(d?.donation_settings?.reference,"_blank")},children:t("customer.payout.viewReference")})]}),e.jsxs(o,{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(r,{direction:"row",sx:{justifyContent:"space-between",alignItems:"center"},children:e.jsx(r,{direction:"row",sx:{alignItems:"center"},children:e.jsxs(r,{direction:"row",spacing:1,sx:{alignItems:"center"},children:[e.jsx(D,{src:s.paymentCurrency.logo,alt:s.paymentCurrency.symbol,variant:"square",sx:{width:"52px",height:"52px",borderRadius:.5}}),e.jsx(r,{direction:"column",sx:{alignItems:"flex-start",justifyContent:"space-around"},children:e.jsx(W,{amount:b,sx:{my:0,fontSize:"1.75rem",lineHeight:"32px"}})})]})})}),e.jsxs(r,{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(y,{label:t("common.status"),value:e.jsx(M,{label:s.status,color:T(s.status)}),divider:!0}),e.jsx(y,{label:t("customer.payout.payer"),value:e.jsx(j,{customer:a.customer,cardProps:{onAvatarClick:()=>{i||window.open(f(a?.customer?.did,n),"_blank")},renderName:u=>e.jsx(p,{variant:"subtitle1",sx:{...i?{}:{cursor:"pointer","&:hover":{color:"text.link"}}},onClick:()=>{if(i)return;const k=f(u?.did,n);window.open(k,"_blank")},children:u.fullName})},linked:!1}),divider:!0})]})]}),e.jsx(P,{})]}),e.jsx(r,{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.jsx(o,{className:"payment-link-column-1",sx:{flex:1,gap:2.5,display:"flex",flexDirection:"column"},children:e.jsxs(o,{className:"section",children:[e.jsx(H,{title:t("common.detail")}),e.jsxs(E,{sx:{display:"grid",gridTemplateColumns:{xs:"repeat(1, 1fr)",lg:"repeat(2, 1fr)"},".info-row-wrapper":{gap:1,flexDirection:{xs:"column",lg:"row"},alignItems:{xs:"flex-start",lg:"center"}}},children:[e.jsx(l,{label:t("common.createdAt"),value:L(s.created_at)}),a&&a.payment_details&&e.jsx(l,{label:t("customer.payout.payTxHash"),value:e.jsx(q,{details:a.payment_details,method:s.paymentMethod,mode:"customer"})}),e.jsx(l,{label:t("customer.payout.receiver"),value:e.jsx(j,{customer:s.customer,linked:!1,size:g?"default":"small"})})]})]})})})]})}const V=N(r)``;export{oe as default};
|