PageSourceSearch

https://dashboard.leaptodigital.com/assets/index-Cn0H-P6C.js

js leaptodigital.com collected 2026-10-02 10:48:29 UTC 105,404 bytes, 306 lines download raw bytes

1import{P as C,gU as le,n as X,g as S,fo as ee,j as e,hd as Ne,B as g,T as j,k as ne,gm as rn,ke as cn,fI as de,gT as ln,fF as D,e_ as Ge,gO as Ye,hc as dn,le as un,lf as mn,lg as st,l2 as pn,K as x,fh as Y,f3 as ue,eU as ye,fQ as pt,fR as Pe,fS as ft,fT as ht,fU as xt,fV as gt,fW as yt,fX as bt,fY as jt,fZ as St,fP as Qe,f_ as Ke,f$ as Ve,fl as pe,g$ as Ct,kh as ie,fk as Xe,jU as Je,D as Te,f6 as fn,f7 as be,k8 as hn,hz as Ze,fn as _e,fN as Le,fO as wt,lh as De,eZ as vt,_ as ge,fJ as Oe,fK as ke,ge as Pt,gf as Et,gg as At,gh as Tt,gc as M,g4 as xn,kl as _t,km as Ce,kn as Me,kj as te,kk as A,ko as we,A as gn,h as yn,E as bn,e$ as Lt,f0 as Ot,g0 as Ee,li as jn,lj as Sn,fM as Cn}from"./vendor-DgNr872F.js";import{A as fe,H as Se,C as wn,E as Q,F as Ae,L as se,i as kt,G as Ft,x as q,I as It,J as U,K as vn,s as ve,M as Pn,N as it,m as ot,Q as En,R as An}from"./payment-CgZ18bDK.js";import{y as ae,L as V,f as Tn,P as _n,k as Be,M as et,h as J,d as z,bu as Ln,X as je,am as tt,e as Fe,av as Rt,r as Nt,t as Dt,c as Mt,bl as ce,bv as On,au as kn,Y as Fn,F as In,B as ze,w as We,bg as Rn}from"./index-D4fDBXv7.js";import{n as he,o as Nn,p as Bt,P as Dn,q as Mn,L as Bn,h as zn,j as Wn,k as Un,D as $n,T as qn,l as Hn,u as Gn,c as Yn,r as Qn,f as Kn}from"./usePaymentStatusUpdate-DXKKqhdS.js";import{A as me}from"./Accordion-CaiGd0K5.js";import{a as nt,u as zt}from"./useOfficeOptions-DQLLWN3e.js";import"./convertUser-SdC42i9V.js";import"./getParsePaginatedOffice-DFyjOPds.js";import"./useUrlParams-C_PsC2g7.js";const Vn=async t=>{const n=C.User.current();if(!n)throw new Error("Session expired");const{company:a}=(n==null?void 0:n.attributes)||{};if(!a)throw new Error("Company not found");const{id:r}=a;return await le.httpGet(`${fe.GET_BUSINESS}/${r}`,t,{headers:he()})},Xn=async(t,n)=>{const a=C.User.current();if(!a)throw new Error("Session expired");const{company:r}=(a==null?void 0:a.attributes)||{};if(!r)throw new Error("Company not found");const{id:s}=r,{name:i}=(r==null?void 0:r.attributes)||{},{account_name:c,office_id:o,account_id:d,business_id:h}=t,p={account_name:t?`${i} (${s}) ${c} ${o}`:`${i} (${s})`,meta:{userId:a==null?void 0:a.id}};return o&&(p.office_id=o),d&&(p.account_id=d),h&&(p.business_id=h),le.httpPost(fe.CREATE_SUB_ACCOUNT,p,{headers:he(n)})},Jn=async(t,n)=>{const a=await Xn(t,n);return{data:Nn.parse(a.data)}},Zn=async t=>{const n=C.User.current();if(!n)throw new Error("Session expired");const{company:a}=(n==null?void 0:n.attributes)||{};if(!a)throw new Error("Company not found");const{id:r}=a,{name:s}=(a==null?void 0:a.attributes)||{},{business_name:i,office_id:c}=t,o={business_name:t?`${s} (${r}) ${i} ${c}`:`${s} (${r})`,meta:{userId:n==null?void 0:n.id}};return c&&(o.office_id=c),le.httpPost(fe.CREATE_BUSINESS,o,{headers:he()})},ea=async t=>{const n=await Zn(t);return{data:Bt.parse(n.data)}},Wt=async t=>{const n=await Vn(t);let a=null;return n.data&&n.data.uuid&&(a=Bt.parse(n.data)),{data:a}},ta=t=>{const{open:n=!1,onSuccess:a,onClose:r,onError:s,selectedOffice:i}=t,c=X(),o=c["card-repricing"],d=c["leap-pay-hosted-onboarding"]??!1,{setSubAccount:h}=S.useContext(ae),{business:p,setBusiness:m}=S.useContext(ae),[l,y]=S.useState(!1),[u,b]=S.useState({businessId:"",webComponentToken:""}),_=()=>{r(!1)},w=()=>{y(!0)},T=ee({mutationKey:"createSubAccount",mutationFn:P=>Jn({account_name:(i==null?void 0:i.label)||"",office_id:i==null?void 0:i.value,account_id:P==null?void 0:P.account_id,business_id:p==null?void 0:p.business_id},o),onError:s,onSuccess:({data:P})=>{h(P),a(P)}}),L=ee({mutationKey:"createBusiness",mutationFn:()=>ea({business_name:(i==null?void 0:i.label)||"",office_id:i==null?void 0:i.value}),onError:s,onSuccess:({data:P})=>{m(P),b({businessId:P.business_id,webComponentToken:P.web_component_token}),w()}}),E=ee({mutationKey:"refreshLeapPayBusiness",mutationFn:()=>Wt(i!=null&&i.value?{office_id:i.value}:{}),onError:s,onSuccess:({data:P})=>{if(!(P!=null&&P.business_id)||!(P!=null&&P.web_component_token)){s({message:Se.SESSION_UNAVAILABLE});return}m(P),b({businessId:P.business_id,webComponentToken:P.web_component_token}),w()}}),I=()=>
1{if(d){if(p&&p.business_id){E.mutate();return}L.mutate();return}if(p&&p.business_id){w();return}L.mutate()},O=P=>{T.mutate({account_id:P.detail.response.data.sub_account_id},{onSuccess:()=>{Be({title:"Success",buttonText:"Close",msg:"Account created successfully!"})}})},v=P=>{T.mutate({account_id:P},{onSuccess:()=>{Be({title:"Success",buttonText:"Close",msg:"Account created successfully!"})}})},f=P=>{s({message:P||Se.FAILED})},k=()=>{_n({children:Se.TOKEN_EXPIRING,severity:"warning"})},F=()=>d?!u.businessId||!u.webComponentToken?e.jsx(j,{variant:"body1",textAlign:"left",pt:2,children:Se.SESSION_UNAVAILABLE}):e.jsx(le.HostedOnboardingForm,{businessId:u.businessId,webComponentToken:u.webComponentToken,onSuccess:v,onError:f,onTokenExpiring:k,height:700,loadingContent:e.jsx(Tn,{size:"xl",label:"Loading..."})}):e.jsx(le.PaymentProvisioningForm,{handleSuccess:O,businessId:(p==null?void 0:p.business_id)||"",webComponentToken:(p==null?void 0:p.web_component_token)||""});return l?e.jsx(Ne,{open:n,onClose:_,title:"Onboarding Form",children:e.jsx(g,{sx:{"& iframe":{border:0}},children:F()})}):e.jsxs(Ne,{"data-testid":"leappay-onboarding-modal",open:n,onClose:_,title:"Get Started with Leap Pay",children:[e.jsxs(g,{children:[e.jsxs(j,{variant:"body1",textAlign:"left",pt:2,children:["Filling out the onboarding form can take about 5 minutes and will require you to enter information about your business. You can see a full list of items needed ",e.jsx("a",{href:wn,target:"_blank",rel:"noreferrer",children:"here"}),". To make this process as smooth as possible, please make sure you have the following items ready before you start:"]}),e.jsx(g,{textAlign:"left",py:2,children:e.jsxs("ul",{children:[e.jsx("li",{children:e.jsx(j,{variant:"body1",children:"Business tax ID"})}),e.jsx("li",{children:e.jsx(j,{variant:"body1",children:"Bank routing & account numbers"})}),e.jsx("li",{children:e.jsx(j,{variant:"body1",children:"A photo of a voided check or bank statement"})})]})}),e.jsx(j,{textAlign:"left",children:"When you are ready, click Continue."})]}),e.jsxs(g,{mt:4,display:"flex",alignItems:"center",justifyContent:"space-between",children:[e.jsx(g,{children:e.jsx(Dn,{})}),e.jsxs(g,{children:[e.jsx(V,{color:"primary","data-cy":"confirm",variant:"contained",size:"medium",onClick:I,loading:L.isLoading||E.isLoading,children:"Continue"}),e.jsx(ne,{sx:{ml:2},color:"secondary",variant:"outlined",onClick:_,"data-cy":"cancel",children:"Cancel"})]})]})]})},Ut={leapPayBanner:{display:"flex",position:"relative",width:"100%",height:"150px"},leapPayBannerOverlay:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"success.main",opacity:.8},leapPayLogo:{width:"400px",height:"auto",marginTop:"50px",marginBottom:"20px"},leapPayContent:{maxWidth:"90%",margin:"0 auto",marginBottom:"40px"},textGreen:{color:"success.main"},borderTitle:{width:"40px",height:"7px",margin:0,marginBottom:"0",border:"2px solid",borderColor:"success.main",backgroundColor:"success.main",borderRadius:4},leapPayOfficeFilter:{display:"flex",justifyContent:"space-between",marginBottom:"20px"},leapPayHelpButton:{display:"flex",justifyContent:"end",marginBottom:"20px"}},$t=async(t,n,a)=>await le.httpGet(`${fe.GET_LEAPPAY_COMPANY_RATES}/${t}`,{},{headers:he(n,a)}),na=rn({officeSelect:{position:"relative",height:"32px",fontSize:"14px","& .office-select__loading-indicator":{display:"none"},"& .office-select__control--is-disabled":{opacity:.5}},control:{boxShadow:"none",width:"100%"},menuPortal:{zIndex:9999}}),qt=({label:t,isSelected:n})=>e.jsx(j,{variant:"body1",sx:{color:n?"black":"gray"},children:t}),Ht=({status:t,isSelected:n})=>e.jsxs(g,{sx:{display:"flex",alignItems:"center",marginLeft:"auto",gap:"4px"},children:[e.jsx(g,{sx:{display:"flex",alignItems:"center",borderRadius:"15px",backgroundColor:t==="enabled"?"#26d07c":"#ed6c02",width:"14px",height:"14px"}}),e.jsx(j,{variant:"body1",sx:{color:n?"black":"gray",textTransform:"capitalize"},children:t||""})]}),aa=({data:t})=>e.jsxs(e.Fragment,{children:[e.jsx(g,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 8px",cursor:"pointer",borderBottom:"1px solid #e0e0e0",":last-of-type":{borderBottom:"none"}},children:e.jsx(qt,{label:t.label})}),e.jsx(Ht,{status:"status"in t?t.status:""})]}),sa=t=>{const{data:n,innerRef:a,innerProps:r,isSelected:s}=t;return e.jsx("div",{ref:a,...r,style:{borderBottom:"1px solid #e0e0e0"},children:e.jsxs(g,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 8px",cursor:"pointer",borderBottom:"1px solid #e0e0e0",":last-of-type":{borderBottom:"none"}},children:[e.jsx(g,{sx:{display:"flex",alignItems:"center"},children:e.jsx(qt,{label:n.label,isSelected:s})}),e.jsx(Ht,{status:"status"in n?n.status:"",isSelected:s})]})})},Gt=t=>{const{value:n,onChange:a,placeholder:r="Select Office  ",width:s,forLinkedAccount:i,customStyles:c,officeList:o,isCustomOption:d=!1,...h}=t,p=na(t),m=S.useMemo(()=>{const y=o==null?void 0:o.find(u=>u.value===n);return y?{...y,label:y.label||"",value:y.value,leapPayId:y.leapPayId,accountId:y.accountId}:{label:"Select Office",value:"",status:"Leap Pay Status",leapPayId:"",accountId:""}},[o,n]);S.useEffect(()=>{a&&m.value!==n&&a(m)},[a,m,n]);const l=y=>{if(y&&t.onChange){const{label:u,value:b,accountId:_}=y;
1t.onChange({label:u,value:b,accountId:_})}};return e.jsx(cn,{"data-testid":"office-filter",isSearchable:!0,components:d?{Option:y=>e.jsx(sa,{...y}),SingleValue:y=>e.jsx(aa,{...y})}:void 0,onChange:y=>l(y),value:m,options:o||[],placeholder:r,classNamePrefix:"office-select",className:p.officeSelect,isLoading:o.length===0,loadingMessage:()=>"Loading offices...",styles:{control:y=>({...y,boxShadow:"none",width:"650px"}),menuPortal:y=>({...y,zIndex:9999})},menuPortalTarget:document.body,...h})},ia=async t=>await C.Cloud.run("linkOfficeSubaccount",t),Yt=({linkedOffice:t,officeId:n,onSuccess:a,isForceLinking:r=!1})=>{const{setSnackbar:s}=J(),{subAccount:i}=S.useContext(ae),[c,o]=S.useState(!1),[d,h]=S.useState({value:"",accountId:"",label:""}),p=()=>{o(!1)},l=ee({mutationKey:"linkAccountWithOffice",mutationFn:b=>ia(b),onError:b=>{s({children:(b==null?void 0:b.message)||Q,severity:"error"})},onSuccess:()=>{s({children:"Account Linked Successfully",severity:"success"}),p(),a(r?d:{value:"",accountId:"",label:""})}}),y=()=>{let b={to_office_id:n,from_office_id:String(d==null?void 0:d.value)||"",account_id:(d==null?void 0:d.accountId)||""};r&&(b={from_office_id:"",to_office_id:String(d==null?void 0:d.value)||"",account_id:(i==null?void 0:i.account_id)||""}),l.mutate(b)},u=b=>{b&&h({...b})};return S.useEffect(()=>{r&&o(!0)},[r]),e.jsxs(e.Fragment,{children:[!r&&e.jsx(ne,{sx:{marginLeft:2},"data-testid":"link-account-with-office-btn",variant:"outlined",color:"secondary",onClick:()=>o(!0),children:"Link your existing LeapPay Account"}),c&&e.jsxs(et,{"data-testid":"leappay-link-office-modal",open:c,title:r?"Please assign your Leap Pay Account to an office to proceed":"Link Existing Leap Pay Account",modalContainerProps:{id:"link-account-modal",sx:{'& .MuiButtonBase-root[aria-label="close"]':{display:"none"}}},children:[e.jsx(g,{children:e.jsx(g,{sx:{flexDirection:"column",position:"relative",width:"100%",marginTop:"30px"},children:e.jsxs(de,{children:[e.jsx(ln,{sx:{color:"text.primary"},children:r?"Select Office":"Copy from another office"}),e.jsx(Gt,{id:"office-filter",width:"large",officeList:t||[],onChange:b=>u(b),value:String(d==null?void 0:d.value)})]})})}),e.jsxs(g,{mt:5,display:"flex",alignItems:"center",justifyContent:"end",children:[e.jsx(g,{sx:{flexGrow:1,display:"flex",justifyContent:"flex-end"},children:e.jsx(V,{color:"primary","data-testid":"link-account-btn","data-cy":"link-account-btn",variant:"contained",size:"medium",disabled:!(d!=null&&d.value),loading:l.isLoading,onClick:y,children:"Link Account"})}),!r&&e.jsx(ne,{"data-testid":"cancel-link-account-btn",variant:"outlined",color:"secondary",size:"medium",onClick:p,sx:{marginLeft:2},disabled:l.isLoading,children:"Cancel"})]})]})]})},oa=({afterOnBoarding:t,selectedOffice:n,officeList:a})=>{const{showErrorModal:r}=Ln(),s=Ut,i=C.User.current(),{company:c}=(i==null?void 0:i.attributes)||{},o=X(),{subAccount:d}=S.useContext(ae),[h,p]=S.useState(!1),[m,l]=S.useState([]),[y,u]=S.useState({...Ae}),b=o["card-repricing"],_=o["leappay-ach-cap"],w=S.useCallback(async O=>{const v=await $t(O,b,_);return u((v==null?void 0:v.leappayCompanyRate)||Ae),v},[b,_]),T=O=>{p(!1),t(O)},L=O=>{const v="error"in O?O.error:O.message;r({title:"Onboarding Error",msg:v||Q})};S.useEffect(()=>{c&&w(c.id)},[c,w]),S.useEffect(()=>{if(a&&a.length>0){const O=a.filter(v=>v.status===se.enabled);l(O)}},[a]);const E=()=>{t(d)},I=()=>{var O,v,f,k;if(o["card-repricing"]&&kt(y)){const F=((O=y.CREDIT_CARD)==null?void 0:O.RATE)??y.CARD_RATE,P=(v=y.CREDIT_CARD)==null?void 0:v.FIXED_PRICE,W=P?` + ${z(P)}`:"",N=((f=y.ACH)==null?void 0:f.RATE)??y.ACH_RATE,B=((k=y.ACH)==null?void 0:k.MAX_FEE)??y.ACH_MAX_FEE,K=_?` (${z(B)} max)`:"",H=Ft(y,z),$=H?` (${H})`:"";return e.jsxs(j,{variant:"body1",fontSize:14,mt:2,color:"grey",children:["Leap Pay is available for all SalesPro customers as a part of their subscription. A payment processing fee of ",F,"%",W," applies to Credit and Debit Card payments",$,". A fee of ",N,"%",K," applies to Bank Transfer (ACH) payments."]})}return e.jsxs(j,{variant:"body1",fontSize:14,mt:2,color:"grey",children:["Leap Pay is available for all SalesPro customers. A processing fee of $",y.CARD_RATE,"% +"," ",z(y.CARD_FIXED_PRICE)," for credit and debit cards and ",y.ACH_RATE,"% (",z(y.ACH_MAX_FEE)," max) for ACH transfers will apply."]})};return e.jsxs(e.Fragment,{children:[e.jsx(g,{"data-testid":"leappay-onboarding-page",children:e.jsxs(g,{sx:s.leapPayContent,children:[e.jsx(D,{children:e.jsxs(D,{item:!0,xs:8,children:[e.jsx(g,{sx:s.leapPayLogo,children:e.jsx("img",{alt:"Leap pay logo",src:"/images/leap_pay/leappay-logo.svg"})}),e.jsxs(j,{color:"content",variant:"h2",fontSize:30,m:0,p:0,children:["Payment Processing Built to Help Contractors",e.jsx("br",{}),e.jsx(g,{component:"span",sx:s.textGreen,children:"Get Paid Faster"})," And Easier"]}),e.jsxs(g,{py:4,children:[e.jsx(j,{variant:"body1",fontSize:16,children:"Leap Pay streamlines the payment process making it easy to send invoices, track payments, and get paid faster."}),e.jsx(j,{variant:"body1",fontSize:16,children:"Leap Pay is directly integrated 
1with SalesPro making it a seamless solution for you and your customers."})]})]})}),e.jsxs(D,{container:!0,children:[e.jsxs(D,{item:!0,xs:12,sm:6,mb:5,children:[e.jsx(g,{sx:s.borderTitle}),e.jsxs(j,{color:"content",variant:"h4",fontSize:24,children:["Get Paid ",e.jsx(g,{component:"span",sx:s.textGreen,children:"Faster"})]}),e.jsx(j,{color:"content",variant:"body1",fontSize:16,children:"Accept payments online and in-person, including credit cards, debit cards, and ACH transfers."})]}),e.jsxs(D,{item:!0,xs:12,sm:6,mb:5,children:[e.jsx(g,{sx:s.borderTitle}),e.jsxs(j,{color:"content",variant:"h4",fontSize:24,children:[e.jsx(g,{component:"span",sx:s.textGreen,children:"Improve"})," Customer Satisfaction"]}),e.jsx(j,{color:"content",variant:"body1",fontSize:16,children:"Leap Pay makes it easy for your customers to pay you at their convenience, from anywhere."})]}),e.jsxs(D,{item:!0,xs:12,sm:6,mb:5,children:[e.jsx(g,{sx:s.borderTitle}),e.jsxs(j,{color:"content",variant:"h4",fontSize:24,children:["Save"," ",e.jsx(g,{component:"span",sx:s.textGreen,children:"Time"})," ","and Money"]}),e.jsx(j,{color:"content",variant:"body1",fontSize:16,children:"Stop chasing down checks and ditch the manual calculations so you can focus on your business."})]}),e.jsxs(D,{item:!0,xs:12,sm:6,mb:5,children:[e.jsx(g,{sx:s.borderTitle}),e.jsxs(j,{color:"content",variant:"h4",fontSize:24,children:["Payments That ",e.jsx(g,{component:"span",sx:s.textGreen,children:"Go With You"})]}),e.jsx(j,{color:"content",variant:"body1",fontSize:16,children:"From invoices, to payments and from the field to the office, everything you need right at your fingertips."})]}),e.jsxs(D,{item:!0,xs:12,sm:6,mb:5,children:[e.jsx(g,{sx:s.borderTitle}),e.jsxs(j,{color:"content",variant:"h4",fontSize:24,children:["Reduce"," ",e.jsx(g,{component:"span",sx:s.textGreen,children:"Errors"})]}),e.jsx(j,{color:"content",variant:"body1",fontSize:16,children:"Leap Pay’s secure, PCI compliant processing system helps to reduce errors and protect your customer’s sensitive financial information."})]})]}),e.jsxs(g,{py:4,children:[e.jsxs(j,{color:"content",variant:"h2",fontSize:30,m:0,p:0,children:["Leap Pay is Perfect for",e.jsx("br",{}),e.jsx(g,{sx:s.textGreen,children:"Contractors of All Sizes"})]}),e.jsx(j,{color:"content",variant:"body1",fontSize:16,mb:3,mt:1,children:"Whether you’re the neighborhood hero or the national franchise, Leap Pay helps you get paid faster and easier."}),e.jsxs(j,{color:"content",variant:"body1",fontSize:16,children:["There is no additional subscription needed to start using Leap Pay. ",e.jsx("b",{children:"Learn more and get started today."})]})]}),e.jsxs(g,{mt:2,children:[e.jsx(ne,{color:"primary",variant:"contained","data-testid":"get-started-with-leapPay-button",onClick:()=>p(!0),children:"Get Started With Leap Pay"}),o["leap-pay-with-office"]&&(!d||Mn(d==null?void 0:d.status))&&m&&m.length>0&&e.jsx(Yt,{linkedOffice:m,officeId:n==null?void 0:n.value,onSuccess:E,isForceLinking:!1}),I()]})]})}),h&&e.jsx(ta,{open:!0,onClose:()=>p(!1),onSuccess:T,onError:L,selectedOffice:n||{}})]})},ra={[se.enabled]:{icon:()=>e.jsx(pn,{style:{color:"#27d07d"}}),color:"#2c704f",backgroundColor:"#e9faf2",title:"Account Enabled",desc:"Your Leap Pay account is active. You are all set to receive payments from your customer."},[se.submitted]:{icon:()=>e.jsx(st,{style:{color:"#497aff"}}),color:"#384c82",backgroundColor:"#ecf1ff",title:"Account In Review",desc:"Your onboarding information is being reviewed. We will notify you once the review is complete."},[se.created]:{icon:()=>e.jsx(st,{style:{color:"#497aff"}}),color:"#384c82",backgroundColor:"#ecf1ff",title:"Account In Review",desc:"Your onboarding information is being reviewed. We will notify you once the review is complete."},[se.information_needed]:{icon:()=>e.jsx(mn,{style:{color:"#ed6c02"}}),color:"#7b471d",backgroundColor:"#fdf0e5",title:"Account Info Needed",desc:"Additional information is needed to complete your onboarding. Please look out for an email from our support team with request for additional documents."},[se.disabled]:{icon:()=>e.jsx(un,{style:{color:"#f10826"}}),color:"#7c1c28",backgroundColor:"#fee5e8",title:"Account Disabled",desc:"Your account has been temporarily disabled until further review. Please reach out to our support team for additional information."},[se.archived]:{icon:()=>e.jsx(dn,{style:{color:"#898989"}}),color:"#2e2e2e",backgroundColor:"#f3f3f3",title:"Account Archived",desc:"Your account has been deleted. Please contact our support team to re-instate your account."}},ca=({status:t})=>{const n=t?ra[t]:null;if(!n)return null;const{title:a,desc:r,color:s,backgroundColor:i,icon:c}=n;return e.jsxs(Ge,{icon:e.jsx(c,{}
1),sx:{backgroundColor:i,color:s},children:[e.jsx(Ye,{sx:{fontWeight:400,fontSize:"16px"},children:a}),r]})},la=async(t,n)=>await le.httpGet(`${fe.GET_BALANCE_SUMMARY}/${t}`,n,{headers:he()}),da=x.object({balance_amount:x.number(),payout_amount:x.number()}),ua=async(t,n)=>{const a=await la(t,n);return{data:da.parse(a.data)}},ma=({officeId:t})=>{const a=X()["leap-pay-with-office"],{setSnackbar:r}=J(),{subAccount:s}=S.useContext(ae),i=(s==null?void 0:s.uuid)||"",c=(s==null?void 0:s.status)||"",[o,d]=S.useState(null),h=l=>{r({children:(l==null?void 0:l.message)||Q,severity:"error"})},p=S.useCallback(()=>a?{office_id:t}:{},[a,t]),m=Y({queryKey:["fetchBalanceSummary"],queryFn:async()=>{const{data:l}=await ua(i,p());return l},onSuccess:l=>{d(l)},enabled:!!i,refetchOnWindowFocus:!1,onError:h});return S.useEffect(()=>{a&&i&&t&&m.refetch()},[i,a]),e.jsx(g,{"data-testid":"leappay-balance-page",children:e.jsx(me,{title:"Account Summary",defaultExpanded:!0,children:m.isFetching?e.jsx(g,{height:"100%",py:8,textAlign:"center",children:e.jsx(ue,{})}):e.jsxs(e.Fragment,{children:[e.jsx(j,{color:"content",variant:"h2",sx:{margin:0},children:"Balance"}),e.jsx(j,{color:"primary",variant:"h1",sx:{margin:0},"data-testid":"balance-amount",children:z((o==null?void 0:o.balance_amount)||0)}),e.jsx(g,{pt:1,children:e.jsxs(j,{color:"content",component:"div",sx:{margin:0},children:[e.jsx(g,{component:"span",fontWeight:"bold",children:"Total Payouts (All Time): "}),e.jsx(g,{component:"span","data-testid":"total-payouts",children:z((o==null?void 0:o.payout_amount)||0)})]})}),e.jsx(g,{py:2,children:e.jsx(ca,{status:c})})]})})})},pa=x.object({id:x.string(),user:x.string(),offices:x.array(x.string()).optional(),notifications:x.array(x.string()),order:x.number().default(1),office:x.string().optional()}),Ue=x.array(pa),fa=x.object({label:x.string(),value:x.string(),desc:x.string(),tooltipText:x.string().nullable().default("")}),rt=x.array(fa),ha=async t=>{const n=new C.Query("LeapPayUserEmailNotificationSettings"),a=C.User.current();if(!a)throw new Error("Session expired");const{company:r}=(a==null?void 0:a.attributes)||{};if(!r)throw new Error("Company not found");const{id:s}=r||{},i=new C.Object("Company");if(i.id=s,n.equalTo("company",i),n.ascending("order"),t.office_id){const o=new C.Object("Office");o.id=String(t.office_id)||"",n.equalTo("office",o)}else n.exists("offices"),n.notEqualTo("offices",[]);return await n.find()},xa=t=>{const n=C.User.current();if(!n)throw new Error("Session expired");const{company:a}=(n==null?void 0:n.attributes)||{};if(!a)throw new Error("Company not found");const{id:r}=a||{},s=new C.Object("LeapPayUserEmailNotificationSettings"),i=new C.Object("_User");i.id=t.user||"";const c=new C.Object("Company");c.id=r;const o=()=>t.notifications.map(h=>{const p=new C.Object("LeapPayEmailNotificationType");return p.id=h,p}),d=()=>t.offices.map(h=>{const p=new C.Object("Office");return p.id=h,p});if(s.set("user",i),s.set("company",c),t!=null&&t.leapPayWithOffice){const h=new C.Object("Office");h.id=t.offices[0]||"",s.set("office",h),s.set("offices",[])}else s.set("offices",d());return s.set("notificationTypes",o()),s.set("order",t.order),s},ga=t=>{const n=new C.Object("LeapPayUserEmailNotificationSettings");n.id=t.id;const a=new C.Object("_User");a.id=t.user||"";const r=()=>t.notifications.map(c=>{const o=new C.Object("LeapPayEmailNotificationType");return o.id=c,o}),s=()=>t.offices.map(c=>{const o=new C.Object("Office");return o.id=c,o}),i={user:a,notificationTypes:r(),order:t.order,offices:[],office:null};if(t!=null&&t.leapPayWithOffice){const c=new C.Object("Office");c.id=t.offices[0]||"",i.office=c,i.offices=[]}else i.offices=s(),i.office=null;return n.set(i),n},ya=async()=>await new C.Query("LeapPayEmailNotificationType").findAll(),ba=t=>{const n=new C.Object("LeapPayUserEmailNotificationSettings");return n.id=t,n},ja=x.object({id:x.string(),user:x.string().default(""),offices:x.array(x.string()).default([]),notifications:x.array(x.string()).default([]),order:x.number().default(1)}),Qt=x.object({settings:x.array(ja)}),Sa=x.object({types:x.array(x.object({id:x.string(),name:x.string().default(""),description:x.string().default("")}))}),Ca=async t=>{if(!C.User.current())throw new Error("Session expired");const a=await C.Cloud.run("getLeapPayEmailNotificationSettings",{...t?{officeId:String(t)}:{}});return Qt.parse(a).settings},wa=async()=>
1{if(!C.User.current())throw new Error("Session expired");const n=await C.Cloud.run("getLeapPayEmailNotificationTypes",{});return Sa.parse(n).types},va=async t=>{if(!C.User.current())throw new Error("Session expired");const a=s=>s.map(i=>({...i.id?{id:String(i.id)}:{},user:String(i.user??""),notifications:(i.notifications??[]).map(String),offices:(i.offices??[]).map(String),order:typeof i.order=="number"?i.order:0})),r=await C.Cloud.run("batchSaveLeapPayEmailNotificationSettings",{creates:a(t.creates),updates:a(t.updates),deletes:t.deletes.map(String),...t.leapPayWithOffice!==void 0?{leapPayWithOffice:t.leapPayWithOffice}:{}});return Qt.parse(r).settings},Pa=async t=>{if((await je).variation("finance-lending-dashboard-redesign",!1)){const i=await Ca(t.office_id?String(t.office_id):void 0);return Ue.parse(i)}const s=(await ha(t)).map(i=>{var c,o,d,h,p,m;return{id:i.id,user:((o=(c=i==null?void 0:i.attributes)==null?void 0:c.user)==null?void 0:o.id)||"",offices:(h=(d=i==null?void 0:i.attributes)==null?void 0:d.offices)==null?void 0:h.map(l=>l==null?void 0:l.id),notifications:(p=i==null?void 0:i.attributes)==null?void 0:p.notificationTypes.map(l=>l==null?void 0:l.id),order:(m=i==null?void 0:i.attributes)==null?void 0:m.order}});return Ue.parse(s)},Kt=async()=>{if((await je).variation("finance-lending-dashboard-redesign",!1)){const i=(await wa()).map(c=>({label:c.name,value:c.id,desc:c.description,tooltipText:c.description}));return rt.parse(i)}const r=(await ya()).map(s=>({label:s.attributes.name,value:s.id,desc:s.attributes.description,tooltipText:s.attributes.description}));return rt.parse(r)},Ea=t=>{const n=t.map(a=>{var r,s,i,c,o;return{id:a.id,user:((s=(r=a==null?void 0:a.attributes)==null?void 0:r.user)==null?void 0:s.id)||"",offices:(i=a==null?void 0:a.attributes)==null?void 0:i.offices.map(d=>d.id),notifications:(c=a==null?void 0:a.attributes)==null?void 0:c.notificationTypes.map(d=>d==null?void 0:d.id),order:(o=a==null?void 0:a.attributes)==null?void 0:o.order}});return Ue.parse(n)},Aa=async(t,n,a)=>{const r=t.map(o=>xa(o)),s=n.map(o=>ga(o)),i=a.map(o=>ba(o)),c=await C.Object.saveAll(r.concat(s));return await C.Object.destroyAll(i),c},Ta=async(t,n,a=!1)=>{const r=n.map(m=>m.id),s=t.map(m=>m.id),i=t.filter(m=>!m.id).map(m=>
1({...m,leapPayWithOffice:a,offices:m.offices??[]})),c=t.filter(m=>m.id&&r.includes(m.id)).map(m=>({...m,leapPayWithOffice:a,offices:m.offices??[]})),o=n.filter(m=>!s.includes(m.id)).map(({id:m})=>m);if((await je).variation("finance-lending-dashboard-redesign",!1))return await va({creates:i,updates:c,deletes:o,leapPayWithOffice:a});const p=await Aa(i,c,o);return Ea(p)},Vt={emailTableContainer:{flexGrow:1,width:"100%",overflowY:"hidden","*::-webkit-scrollbar":{width:"6px !important",height:"6px !important"},border:"1px solid #2E2E2E3B",borderRadius:"16px"},gridContainer:{display:"flex",alignItems:"center",flexWrap:"nowrap",paddingTop:0,paddingBottom:0,border:"1px solid #F6F6F7",margin:0,borderTopLeftRadius:16,borderTopRightRadius:16,backgroundColor:"gray1.main",minHeight:48},fieldContainer:{display:"flex",flexDirection:"column",height:"auto",maxHeight:"320px",overflowY:"auto"},pagination:{"& p":{margin:0}},emailAddNewDropDownColumn:{paddingLeft:10}},_a=ye.memo(t=>{const{children:n,fields:a,moveItems:r,setSnackbar:s,disableDragDrop:i=!1}=t,c=Vt,o=pt(Pe(xt),Pe(ht,{coordinateGetter:ft})),d=async p=>{var y,u;const{active:m,over:l}=p;if(l&&m.id!==l.id)try{r((y=m.data.current)==null?void 0:y.sortable.index,(u=l.data.current)==null?void 0:u.sortable.index)}catch{s({children:"There was an error updating the order",severity:"error"})}},h=a.map(p=>p.id);return i?e.jsx(g,{sx:c.fieldContainer,children:n}):e.jsx(gt,{sensors:o,collisionDetection:bt,modifiers:[yt],onDragEnd:d,children:e.jsx(g,{sx:c.fieldContainer,children:e.jsx(jt,{items:h,strategy:St,children:n})})})}),La=ye.memo(t=>{var N,B,K,H;const{setSnackbar:n}=J(),{userOptions:a,notificationsOptions:r,field:s,register:i,index:c,remove:o,control:d,errors:h,setValue:p,update:m}=t,l=Qe({control:d,name:`emailItems.${c}`}),y=(l==null?void 0:l.user)||"",u=(l==null?void 0:l.email)||"",b=l==null?void 0:l.selectedOffices,_=l==null?void 0:l.notifications,w=(l==null?void 0:l.allowedOffices)||[],{attributes:T,listeners:L,setNodeRef:E,transform:I,transition:O,setActivatorNodeRef:v}=Ke({id:s.id,data:{item:s}}),f={transform:Ve.Transform.toString(I),transition:O||""},k={...f,background:"#E3EAFE",boxShadow:"0px 3px 6px #00000029",borderRadius:"16px",zIndex:1e3},F=$=>{n({children:($==null?void 0:$.message)||Q,severity:"error"})},P=ee({mutationKey:`fetchAllowedOffice-${c}`,mutationFn:nt,onSuccess:($,[oe])=>{p(`emailItems.${c}.allowedOffices`,$[oe]||[])},onError:F}),W=$=>{const oe=$.target.value;m(c,{...l,user:oe,selectedOffices:[],allowedOffices:[],notifications:r.map(xe=>String(xe.value))}),P.mutate([oe])};return e.jsxs(e.Fragment,{children:[e.jsxs(D,{ref:E,style:T["aria-pressed"]?k:f,container:!0,wrap:"nowrap",display:"flex",alignItems:"auto",position:"absolute",padding:"4px",gap:"16px",children:[e.jsx(D,{ml:1.5,item:!0,xs:1.5,maxWidth:"16px !important",children:e.jsx(g,{sx:{position:"absolute",top:"15px"},ref:v,...T,...L,children:e.jsx(tt,{})})}),e.jsx(D,{item:!0,xs:4,children:"email"in s?e.jsx(pe,{sx:{m:0,width:"100%",maxWidth:"330px"},size:"small",label:"Email",color:"secondary",value:u,...i(`emailItems.${c}.email`,{required:!0,pattern:{value:new RegExp(`(${Fe.source})|(${Rt.source})`),message:"Please enter a valid email or placeholder"}}),helperText:h.emailItems&&((B=(N=h==null?void 0:h.emailItems[c])==null?void 0:N.email)==null?void 0:B.message),error:h.emailItems&&!!((H=(K=h==null?void 0:h.emailItems[c])==null?void 0:K.email)!=null&&H.message),"data-testid":"leap-pay-email-input"}):e.jsx(Ct,{label:"User",options:a,size:"small",value:y,sx:{m:0,width:"100%",maxWidth:"300px"},...i(`emailItems.${c}.user`,{required:!0}),onChange:W,"data-testid":"leap-pay-select-user",SelectProps:{MenuProps:{PaperProps:{sx:{maxHeight:"300px"}}}}})}),e.jsx(D,{item:!0,xs:4,children:e.jsx(ie,{label:"Office(s)",inputLabelProps:{size:"small"},size:"small",MenuProps:{PaperProps:{sx:{maxHeight:"300px"}}},formControlSx:{m:0,width:"100%",maxWidth:"300px"},variant:"outlined",options:w,disabled:!y||w.length===0||P.isLoading,value:b,showSelectedCount:!0,selectedCountLabel:(b==null?void 0:b.length)===w.length?"Offices: All":`${b==null?void 0:b.length} Offices Selected`,...i(`emailItems.${c}.selectedOffices`,{required:!0}),"data-testid":"leap-pay-select-office"})}),e.jsx(D,{item:!0,xs:4,children:e.jsx(ie,{label:"Notifications",inputLabelProps:{size:"small"},size:"small",sx:{m:0,width:"100%"},formControlSx:{m:0,width:"100%",maxWidth:"300px"},variant:"outlined",options:r,value:_,showSelectedCount:!0,disabled:!y,showSelectedCountLimit:2,selectedCountLabel:`${_==null?void 0:_.length} Notifications Selected`,...i(`emailItems.${c}.notifications`,{required:!0}),"data-testid":"leap-pay-select-notifications"})}),e.jsx(D,{item:!0,xs:1.5,children:e.jsx(Xe,{onClick:()=>o(c),sx:{padding:0,marginLeft:"35px",marginTop:"8px"},"data-testid":"remove-email-notification",children:e.jsx(Je,{sx:{color:"#F1001F"}})})})]},s.id),c>
10&&e.jsx(Te,{sx:{position:"relative",bottom:"16px"}})]})}),$e={id:"",selectedOffices:[],notifications:[],allowedOffices:[]},Oa=t=>{const{prepend:n}=t,[a,r]=S.useState(null),s=!!a,i=h=>{r(h.currentTarget)},c=()=>{r(null)},o=h=>{h(),c()},d=[{label:"From User List",onClick:()=>{n({...$e,user:""})}},{label:"Email or Placeholder",onClick:()=>{n({...$e,email:""})},disabled:!0}];return e.jsxs(g,{children:[e.jsx(ne,{"aria-controls":s?"add-options-menu":void 0,"aria-haspopup":"true","aria-expanded":s?"true":void 0,onClick:i,color:"secondary",variant:"text",children:"Add +"}),e.jsx(fn,{id:"add-options-menu",anchorEl:a,open:s,onClose:c,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:d.map(h=>e.jsx(be,{onClick:()=>o(h.onClick),disabled:h.disabled,sx:{display:h.disabled?"none":"show"},children:h.label},h.label))})]})},ka=ye.memo(t=>{var W,N,B,K;const{setSnackbar:n}=J(),{userOptions:a,notificationsOptions:r,field:s,register:i,index:c,remove:o,control:d,errors:h,setValue:p,update:m,officeId:l}=t,y=Qe({control:d,name:`emailItems.${c}`}),u=(y==null?void 0:y.user)||"",b=(y==null?void 0:y.email)||"",_=y==null?void 0:y.notifications,{attributes:w,listeners:T,setNodeRef:L,transform:E,transition:I,setActivatorNodeRef:O}=Ke({id:s.id,data:{item:s}}),v={transform:Ve.Transform.toString(E),transition:I||""},f={...v,background:"#E3EAFE",boxShadow:"0px 3px 6px #00000029",borderRadius:"16px",zIndex:1e3},k=H=>{n({children:(H==null?void 0:H.message)||Q,severity:"error"})},F=ee({mutationKey:`fetchAllowedOffice-${c}`,mutationFn:nt,onSuccess:(H,[$])=>{p(`emailItems.${c}.allowedOffices`,H[$]||[])},onError:k}),P=H=>{const $=H.target.value;m(c,{...y,user:$,selectedOffices:l?[String(l)]:[],allowedOffices:[],notifications:r.map(oe=>String(oe.value))}),F.mutate([$])};return e.jsxs(D,{ref:L,style:w["aria-pressed"]?f:v,container:!0,wrap:"nowrap",display:"flex",alignItems:"center",position:"relative",padding:"16px",sx:{backgroundColor:"#fff","&:hover":{backgroundColor:"#f5f5f5"},borderBottom:"1px solid #e0e0e0"},gap:"24px",children:[e.jsx(D,{ml:1,item:!0,xs:"auto",children:e.jsx(g,{sx:{cursor:"grab",display:"flex",alignItems:"center",height:"100%"},ref:O,...w,...T,children:e.jsx(tt,{})})}),e.jsx(D,{item:!0,xs:6,children:"email"in s?e.jsx(pe,{sx:{m:0,width:"100%","& .MuiOutlinedInput-root":{backgroundColor:"#fff"}},size:"small",label:"Email",color:"secondary",value:b,...i(`emailItems.${c}.email`,{required:!0,pattern:{value:new RegExp(`(${Fe.source})|(${Rt.source})`),message:"Please enter a valid email or placeholder"}}),helperText:h.emailItems&&((N=(W=h==null?void 0:h.emailItems[c])==null?void 0:W.email)==null?void 0:N.message),error:h.emailItems&&!!((K=(B=h==null?void 0:h.emailItems[c])==null?void 0:B.email)!=null&&K.message),"data-testid":"leap-pay-email-input"}):e.jsx(Ct,{label:"User",options:a,size:"small",value:u,sx:{m:0,width:"100%","& .MuiOutlinedInput-root":{backgroundColor:"#fff"}},...i(`emailItems.${c}.user`,{required:!0}),onChange:P,"data-testid":"leap-pay-select-user",SelectProps:{MenuProps:{PaperProps:{sx:{maxHeight:"300px"}}}}})}),e.jsx(D,{item:!0,xs:6,children:e.jsx(ie,{label:"Notifications",inputLabelProps:{size:"small"},size:"small",formControlSx:{m:0,width:"100%","& .MuiOutlinedInput-root":{backgroundColor:"#fff"}},variant:"outlined",options:r,value:_,showSelectedCount:!0,disabled:!u,showSelectedCountLimit:2,selectedCountLabel:`${_==null?void 0:_.length} Notifications Selected`,...i(`emailItems.${c}.notifications`,{required:!0}),"data-testid":"leap-pay-select-notifications"})}),e.jsx(D,{item:!0,xs:"auto",children:e.jsx(Xe,{onClick:()=>o(c),sx:{padding:"8px","&:hover":{backgroundColor:"rgba(241, 0, 31, 0.04)"}},"data-testid":"remove-email-notification",children:e.jsx(Je,{sx:{color:"#F1001F",fontSize:"20px"}})})})]},s.id)}),Fa={total:0,limit:20,page:0},Ia=t=>{const{loading:n,userOptions:a,notificationsOptions:r,fields:s,register:i,prepend:c,remove:o,move:d,control:h,setSnackbar:p,errors:m,setValue:l,update:y,disablePagination:u,LeapPayWithOffice:b,officeId:_}=t,w=Vt,[T,L]=S.useState({...Fa,total:s.length});S.useEffect(()=>{!n&&s.length&&L(v=>({...v,total:s.length}))},[n,s.length]);const E=(v,f)=>{L(k=>({...k,page:f}))},I=v=>{L({...T,limit:parseInt(v.target.value,10),page:0})},O=S.useMemo(()=>{const v=T.page*T.limit,f=v+T.limit;return v&&v===s.length?(L(F=>({...F,page:F.page-1})),[]):s.slice(v,f)},[s,T]);return e.jsxs(g,{sx:w.emailTableContainer,children:[e.jsxs(D,{container:!0,columnGap:b?6:4,sx:w.gridContainer,children:[e.jsx(D,{item:!0,children:e.jsx(g,{width:"16px"})}),e.jsx(D,{item:!0,xs:b?5:4,children:e.jsx(j,{variant:"body1",fontWeight:"bold",children:"User"})}),!b&&e.jsx(D,{item:!0,xs:4,children:e.jsx(j,{variant:"body1",fontWeight:"bold",children:"Office(s)"})}),e.jsx(D,{item:!0,xs:4,children:e.jsx(j,{variant:"body1",fontWeight:"bold",children:"Notifications"})}),e.jsx(D,{item:!0,xs:1.5,sx:b?w.emailAddNewDropDownColumn:null,children:e.jsx(Oa,{prepend:c})})]}),n&&e.jsx(g,{height:"100%",py:6,textAlign:"center",children:e.jsx(ue,{})}),!n&&O.length===0&&e.jsx(g,{py:2,textAlign:"center",children:e.jsx(j,{variant:"subtitle2",children:"It looks like you don't have any email notification settings yet."})}),!n&&O.length>0&&e.jsx(_a,{moveItems:d,setSnackbar:p,fields:O,children:e.jsx(hn,{height:O.length*72,width:"100%",itemSize:72,itemCount:O.length,children:({index:v,style:f})=>{const k=O[v],F=T.page*T.limit+v;return e.jsx(g,{style:f,pt:1.5,children:b?e.jsx(ka,{setValue:l,f
1ield:k,register:i,update:y,index:F,remove:o,control:h,userOptions:a,notificationsOptions:r,errors:m,officeId:String(_)||""},k.id):e.jsx(La,{setValue:l,field:k,register:i,update:y,index:F,remove:o,control:h,userOptions:a,notificationsOptions:r,errors:m,officeId:String(_)||""},k.id)})}})}),e.jsx(Te,{}),e.jsx(Ze,{component:"div",disabled:u,sx:w.pagination,rowsPerPageOptions:[5,10,20],count:T.total,page:T.page,rowsPerPage:T.limit,onPageChange:E,onRowsPerPageChange:I})]})},Ra=async t=>{try{return await C.Cloud.run("fetchUsersForOfficeLeappay",t)}catch(n){throw await Nt(n),n}},Xt=({officeId:t})=>{const{setSnackbar:n}=J(),a=_e(),s=X()["leap-pay-with-office"],[i,c]=S.useState({}),[o,d]=S.useState([]),[h,p]=S.useState([]),[m,l]=S.useState([]),y=Le({defaultValues:{emailItems:[$e]},mode:"onChange"}),{control:u,register:b,reset:_,handleSubmit:w,formState:T,setValue:L}=y,{fields:E,prepend:I,remove:O,move:v,update:f}=wt({control:u,name:"emailItems"}),k=Qe({control:u,name:"emailItems"}),{isValid:F,errors:P,isDirty:W}=T,N=()=>h.map((R,Z)=>{var G;return{id:R.id,user:R.user,selectedOffices:s&&t?[String(t)]:R==null?void 0:R.offices,notifications:R.notifications||[],allowedOffices:i[R==null?void 0:R.user]||((G=k[Z])==null?void 0:G.allowedOffices)||[]}});S.useEffect(()=>{_({emailItems:N()})},[h,i]);const B=R=>{n({children:(R==null?void 0:R.message)||Q,severity:"error"})},K=Y({queryKey:["fetchAllowedOffices"],queryFn:async()=>{const R=h.map(G=>G.user);return await nt(R)},onSuccess:R=>{c(R)},refetchOnWindowFocus:!1,enabled:h.length>0,onError:B}),H=Y({queryKey:["fetchLeapPayEmailNotificationType"],queryFn:Kt,onSuccess:R=>{d(R)},refetchOnWindowFocus:!1,onError:B}),$=Y({queryKey:["fetchLeapPayEmailNotificationSettings"],queryFn:()=>{const R={};return s&&t&&(R.office_id=t),Pa(R)},onSuccess:R=>{p(R)},refetchOnWindowFocus:!1,onError:B}),oe=Y({queryKey:["fetchUsersForOffice",s,t],queryFn:async()=>{const R={};return s&&t&&(R.office_id=t),await Ra(R)},onSuccess:R=>{const Z=R.users.map(G=>({...G,disabled:!!E.find(Ie=>Ie.user===G.value)}));l(Z)},onError:B,refetchOnWindowFocus:!1}),xe=ee({mutationKey:"batchSaveLeapPayEmailNotificationSettings",mutationFn:({newData:R,currentData:Z})=>Ta(R,Z,s),onError:B,onSuccess:R=>{n({children:"Email Notification Settings saved successfully",severity:"success"}),a.setQueryData("fetchLeapPayEmailNotificationSettings",R)}}),sn=w(R=>{const Z=R.emailItems.map((G,Ie)=>({id:G.id||"",user:G.user||"",offices:s&&t?[String(t)]:G==null?void 0:G.selectedOffices,notifications:G.notifications,order:Ie+1}));xe.mutate({newData:Z,currentData:h})});S.useEffect(()=>{s&&t&&(oe.refetch(),$.refetch())},[t,s]);const on=!F||!W||K.isFetching||xe.isLoading;return S.useEffect(()=>{const R=m.map(Z=>({...Z,disabled:!!E.find(G=>G.user===Z.value)}));l(R)},[E]),e.jsx(me,{title:"Email Notification Settings",children:e.jsx(g,{mb:1,children:e.jsxs(De,{id:"email-settings",onSubmit:sn,children:[e.jsxs(j,{variant:"body1",children:["Add admin emails or users to send Leap Pay notifications to. ",e.jsx("br",{}),"Sales Reps will automatically receive payment notifications for any transactions they initiate."]}),e.jsx(Ia,{fields:E,move:v,disablePagination:W||!E.length||K.isFetching||H.isFetching||xe.isLoading,prepend:I,remove:O,register:b,setValue:L,update:f,control:u,userOptions:m,notificationsOptions:o,setSnackbar:n,loading:K.isFetching||H.isFetching||$.isFetching,errors:P,LeapPayWithOffice:s,officeId:String(t)||""}),e.jsx(De.ActionRow,{children:e.jsx(V,{size:"medium",color:"primary",disabled:on,type:"submit","data-testid":"save",children:"Save"})})]})})})};Xt.defaultProps={config:{},officeId:""};const Na=async t=>await C.Cloud.run("exportLeapPayPayoutHistoryActivity",t),re={ALL_TIME:"all_time",YTD:"YTD",MTD:"MTD",PAST_30_DAYS:"past_30_days",PAST_90_DAYS:"past_90_days",CUSTOM:"custom_date_range"},ct=re.PAST_30_DAYS,Re=[{value:q.SUCCEEDED,label:"Succeeded"},{value:q.FULLY_REFUNDED,label:"Fully Refunded"},{value:q.PARTIAL_REFUNDED,label:"Partially Refunded"},{value:q.CANCELED,label:"Canceled"},{value:q.FAILED,label:"Failed"},{value:q.DISPUTED,label:"Disputed"}],lt=(t,n)=>{const a=M().format(U);switch(t){case re.YTD:return[M().startOf("year").format(U),a];case re.MTD:return[M().startOf("month").format(U),a];case re.PAST_30_DAYS:return[M().subtract(30,"day").format(U),a];case re.PAST_90_DAYS:return[M().subtract(90,"day").format(U),a];case re.ALL_TIME:return["",""];case re.CUSTOM:default:return n}},Da=t=>{const{open:n,onClose:a,uuid:r,officeOptions:s,defaultSelectedOffices:i}=t,{userOptions:c}
1=Dt(),[o,d]=S.useState(ct),[h,p]=S.useState(!1),[m,l]=S.useState({office:i,user:[],date:lt(ct,["",""]),status:[]}),y=async()=>{p(!0);try{const u=await Na({uuid:r,filters:m});xn({title:"Payout History Export",msg:u.message,buttonText:"OK"}),a()}catch(u){Mt({title:"Payout History Export Error",showVerbose:!0,error:u})}finally{p(!1)}};return e.jsx(et,{open:n,onClose:a,modalContainerProps:{sx:{width:624,maxWidth:"624px",minWidth:"624px"}},children:e.jsxs(vt,{spacing:3,sx:{width:"100%",pt:1},"data-testid":"export-payout-history-modal",children:[e.jsxs(g,{children:[e.jsx(j,{sx:{color:"#1fbc6f",fontWeight:700,fontSize:24,lineHeight:1.2},children:"Export Payment History"}),e.jsx(g,{sx:{mt:1,borderBottom:"2px solid #1fbc6f"}})]}),e.jsx(ie,{label:"Office",inputLabelProps:{size:"small"},size:"small",variant:"outlined",fullWidth:!0,formControlSx:{width:"100%",m:0},options:s,value:m.office,showSelectedCount:!0,selectedCountLabel:m.office.length===s.length?"Offices: All":`${m.office.length} Offices Selected`,onChange:u=>{const b=u.target.value||[];l({...m,office:b.length?ge.pull(b,"none"):[]})},"data-testid":"export-office-select"}),e.jsx(ie,{label:"Users",inputLabelProps:{size:"small"},size:"small",variant:"outlined",fullWidth:!0,formControlSx:{width:"100%",m:0},options:c,value:m.user,showSelectedCount:!0,selectedCountLabel:m.user.length===c.length&&c.length>0?"Users: All":`${m.user.length} Users Selected`,onChange:u=>{const b=u.target.value||[];l({...m,user:b.length?ge.pull(b,"none"):[]})},"data-testid":"export-user-select"}),e.jsxs(de,{fullWidth:!0,variant:"outlined",children:[e.jsx(Oe,{id:"export-date-range-label",children:"Date Filter"}),e.jsx(ke,{size:"small",labelId:"export-date-range-label",label:"Date Filter",value:o,"data-testid":"export-date-filter",onChange:u=>{d(u.target.value),l({...m,date:lt(u.target.value,m.date)})},children:It.map(u=>e.jsx(be,{value:u.value,"data-testid":`export-${u.value}`,children:u.label},u.value))})]}),o===re.CUSTOM&&e.jsx(Pt,{dateAdapter:Et,children:e.jsx(At,{slots:{field:Tt},disableFuture:!0,value:[m.date[0]?M(m.date[0],U):null,m.date[1]?M(m.date[1],U):null],onChange:u=>{u&&u[0]&&u[1]&&l(b=>({...b,date:[M(u[0]).format(U),M(u[1]).format(U)]}))},slotProps:{textField:{size:"small",color:"secondary",sx:{minWidth:200}}},"data-testid":"export-date-range"})}),e.jsx(ie,{label:"Status Filter",inputLabelProps:{size:"small"},size:"small",variant:"outlined",fullWidth:!0,formControlSx:{width:"100%",m:0},options:Re,value:m.status,showSelectedCount:!0,selectedCountLabel:m.status.length===Re.length&&Re.length>0?"Status: All":`${m.status.length} Selected`,onChange:u=>{const b=u.target.value||[];l({...m,status:b.length?ge.pull(b,"none"):[]})},"data-testid":"export-status-select"}),e.jsx(Te,{}),e.jsxs(g,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(ne,{variant:"outlined","data-testid":"export-cancel-btn",onClick:a,sx:{borderRadius:"8px",px:2,py:.75,fontWeight:700,color:"#4779ff",borderColor:"#4779ff",borderWidth:2,"&:hover":{borderColor:"#4779ff",borderWidth:2}},children:"Cancel"}),e.jsx(V,{variant:"contained","data-testid":"export-submit-btn",loading:h,onClick:y,sx:{borderRadius:"8px",px:2,py:.75,fontWeight:700,bgcolor:"#26d07c","&:hover":{bgcolor:"#1fbc6f"}},children:"Export"})]})]})})},Ma=async t=>await C.Cloud.run("fetchLeapPayPayouts",t),Ba=async t=>await C.Cloud.run("fetchLeapPayPayoutPayments",t),Jt=x.object({id:x.union([x.number(),x.string()]),status:x.string().default(""),amount:x.number().default(0),fee_amount:x.number().default(0),net:x.number().default(0).optional(),payment_method:x.string().default(""),customer:x.object({estimateName:x.string().default(""),nameFirst:x.string().default(""),nameLast:x.string().default(""),id:x.string().default("")}).default({}),description:x.string().default("")}),za=x.object({id:x.string(),deposits_at:x.string().default(""),created_at:x.string().default(""),amount:x.number().default(0),bank_account:x.object({account_number_last4:x.string().default("")}).default({}),status:x.string().default(""),type:x.string().default(""),payments:x.array(Jt).default([])}),Wa=x.array(za).default([]),Ua=x.array(Jt).default([]),$a=x.object({has_previous:x.boolean(),has_next:x.boolean(),end_cursor:x.str
1ing().default("").nullable(),start_cursor:x.string().default("").nullable()});x.object({next:x.string().default("").nullable(),limit:x.number().default(0),uuid:x.string()});x.object({uuid:x.string(),payoutId:x.string()});const qa=async t=>{const n=await Ma(t),a=Wa.parse(n.data.payouts),r=$a.parse(n.data.page_info);return{data:a,pageInfo:r}},Ha=async t=>{const n=await Ba(t);return{data:Ua.parse(n)}},Ga={has_previous:!1,has_next:!1,start_cursor:"",end_cursor:""},Ya=({officeId:t})=>{const n=X(),a=n["leap-pay-with-office"],r=n["leap-pay-payout-history-export"]??!1,{setSnackbar:s}=J(),{subAccount:i}=S.useContext(ae),[c,o]=S.useState([]),[d,h]=S.useState(),[p,m]=S.useState({...Ga}),[l,y]=S.useState({limit:20,next:"",office_id:t}),u=(i==null?void 0:i.uuid)||"",{officeOptions:b}=zt({userAllowedOffices:!0}),[_,w]=S.useState(!1),T=a&&t?[String(t)]:b.map(f=>String(f.value)),L=f=>{s({children:(f==null?void 0:f.message)||Q,severity:"error"})},E=S.useCallback(()=>a?{office_id:t,uuid:u,...l}:{uuid:u,...l},[a,t,u,l]),I=Y({queryKey:["fetchPayoutHistory"],queryFn:async()=>{const{data:f,pageInfo:k}=await qa(E());return{data:f,pageInfo:k}},onSuccess:({data:f,pageInfo:k})=>{f&&f.length>0&&o(l.next?[...c,...f]:f),k&&(m(k),y({...l,next:k.end_cursor}))},refetchOnWindowFocus:!1,onError:L}),O=Y({queryKey:["fetchPayoutPayments"],queryFn:async()=>{const{data:f}=await Ha({uuid:u,payoutId:(d==null?void 0:d.id)||""});return f},onSuccess:f=>{if(f){const k=c.map(F=>F.id===(d==null?void 0:d.id)?{...F,payments:Array.isArray(f)?f:[]}:F);o(k)}},enabled:!!(d!=null&&d.id),refetchOnWindowFocus:!1,onError:L}),v=()=>{y(f=>({...f,next:p.end_cursor})),I.refetch()};return S.useEffect(()=>{d&&(d!=null&&d.id)&&!d.payments.length&&O.refetch()},[d==null?void 0:d.id]),S.useEffect(()=>{I.refetch()},[u]),e.jsx(g,{"data-testid":"leappay-payout-history-page",children:e.jsxs(me,{title:"Payout History",children:[r&&e.jsxs(e.Fragment,{children:[e.jsx(g,{sx:{display:"flex",justifyContent:"flex-end",marginBottom:"8px"},children:e.jsx(V,{variant:"contained",size:"medium","data-testid":"open-export-payout-btn",onClick:()=>w(!0),sx:{bgcolor:"success.main","&:hover":{bgcolor:"success.dark"}},children:"Export"})}),e.jsx(Da,{open:_,onClose:()=>w(!1),uuid:u,officeOptions:b,defaultSelectedOffices:T})]}),e.jsx(j,{component:"span",children:"Leap Pay funds are transferred daily to your bank account if available."}),e.jsxs(_t,{sx:{marginTop:"16px",marginBottom:"16px",maxHeight:"500px",border:"1px solid rgba(224, 224, 224, 1)"},children:[e.jsxs(Ce,{"aria-label":"Details Table",children:[e.jsx(Me,{sx:{backgroundColor:"gray1.main"},children:e.jsxs(te,{children:[e.jsx(A,{sx:{width:"10%"}}),e.jsx(A,{sx:{width:"30%"},children:e.jsx(j,{variant:"subtitle2",children:"Created"})}),e.jsx(A,{sx:{width:"30%"},children:e.jsx(j,{variant:"subtitle2",children:"Type"})}),e.jsx(A,{sx:{width:"30%"},children:e.jsx(j,{variant:"subtitle2",children:"Amount"})}),e.jsx(A,{sx:{width:"30%"},children:e.jsx(j,{variant:"subtitle2",children:"Status"})}),e.jsx(A,{sx:{width:"30%"},children:e.jsx(j,{variant:"subtitle2",children:"To Account"})})]})}),e.jsx(we,{children:c.length>0?c.map(f=>{var k;return e.jsx(te,{sx:{maxHeight:"60px",padding:0,border:"none"},children:e.jsx(A,{sx:{padding:0,width:"10%"},colSpan:6,children:e.jsxs(gn,{sx:{backgroundColor:"transparent",borderRadius:0,border:"none",boxShadow:"none"},onClick:()=>h(f),children:[e.jsx(Ce,{children:e.jsx(we,{children:e.jsxs(te,{children:[e.jsx(A,{sx:{padding:0,width:"10%",background:"transparent"},children:e.jsx(yn,{style:{background:"transparent",width:"10%",border:"none"},expandIcon:e.jsx(bn,{})})}),e.jsx(A,{"data-testid":`payout-date-${f.id}`,sx:{width:"30%",paddingLeft:"16px"},children:M(f.created_at).format(vn)}),e.jsx(A,{"data-testid":`payout-type-${f.id}`,sx:{width:"30%"},children:ce(f==null?void 0:f.type)}),e.jsx(A,{"data-testid":`payout-amount-${f.id}`,sx:{width:"30%"},children:z(f.amount)}),e.jsx(A,{"data-testid":`payout-status-${f==null?void 0:f.id}`,sx:{width:"30%",paddingLeft:"16px"},children:f!=null&&f.status?ce(f==null?void 0:f.status):""}),e.jsx(A,{"data-testid":`payout-bank_account-${f.id}`,sx:{width:"30%"},children:(k=f==null?void 0:f.bank_account)==null?void 0:k.account_number_last4})]})})}),e.jsxs(Ce,{sx:{maxHeight:"100px"},children:[e.jsx(Me,{sx:{backgroundColor:"gray1.main"},children:e.jsxs(te,{children:[e.jsx(A,{sx:{width:"5%"}}),e.jsx(A,{sx:{width:"10%"},children:e.jsx(j,{variant:"subtitle2",children:"Customer Name"})}),e.jsx(A,{sx:{width:"10%"},children:e.jsx(j,{variant:"subtitle2",children:"Estimate #"})}),e.jsx(A,{sx:{width:"10%"},children:e.jsx(j,{variant:"subtitle2",children:"Amount"})}),e.jsx(A,{sx:{width:"10%"},children:e.jsx(j,{variant:"subtitle2",children:"Fee Amount"})}),e.jsx(A,{sx:{width:"10%"},children:e.jsx(j,{variant:"subtitle2",children:"Net Amount"})}),e.jsx(A,{sx:{width:"10%"},children:e.jsx(j,{variant:"subtitle2",children:"Payment Method"})}),e.jsx(A,{sx:{width:"10%"},children:e.jsx(j,{variant:"subtitle2",children:"Description"})})]})}),e.jsx(we,{children:f.payments.length>0?f.payments.map(F=>{var P,W,N;return e.jsxs(te,{sx:{padding:0,maxHeight:"30px"},children:[e.jsx(A,{sx:{width:"5%"}}),e.jsx(A,{sx:{width:"10%"},children:`${(P=F==null?void 0:F.customer)==null?void 0:P.nameFirst} ${(W=F==null?void 0:F.customer)==null?void 0:W.nameLast}`}),e.jsx(A,{sx:{width:"10%"},children:ce((N=F==null?void 0:F.customer)==null?void 0:N.estimateName)}),e.jsx(A,{sx:{width:"10%"},children:z(F.amount)}),e.jsx(A,{sx:{width:"10%"},children:z(F.fee_amount)}),e.jsx(A,{sx:{width:"10%"},children:z(F.net||0)}),e.jsx(A,{sx:{width:"10%"},children:F.payment_method}),e.jsx(A,{sx:{width:"10%"},children:F==null?void 0:F.description})]},F.id)}):e.jsx(te,{children:e.jsx(A,{colSpan:5,sx:{textAlign:"center"},"data-testid":"no-payment-data",children:e.jsx(j,{variant:"subtitle2",children:O.isFetching?"Loading...":"It looks like we don't have any payment details for your payout yet."})})})})]})]})})},f.id)}):e.jsx(te,{children:e.jsx(A,{colSpan:4,sx:{textAlign:"center"},"data-testid":"no-payouts-data",children:e.jsx(j,{variant:"subtitle2",children:I.isFetching?"Loading...":" It looks like you don't have any payouts yet."})})})})]}),p.has_next&&e.jsx(g,{sx:{display:"flex",justifyContent:"center"},children:e.jsx(ne,{onClick:v,disabled:I.isFetching,children:I.isFetching?"Loading...":"Load More"})})]})]})})},Qa=x.object({id:x.string(),isDefaultPaymentMethod:x.boolean().default(!1),paymentMethod:x.string().default(""),paymentMethodsCloned:x.boolean().optional()}),Ka=async t=>{const n=new C.Query("LeapPayAccountSettings"),a=C.User.current(),{company:r={}}=(a==null?void 0:a.attributes)||{},{id:s}=r||{},i=new C.Object("Company");if(i.id=s,n.equalTo("company",i),t.office_id){const o=new C.Object("Office");o.id=String(t.office_id)||"",n.equalTo("office",o)}return await n.first()},Va=async t=>{const n=C.User.current();if(!n)throw new Error("Session expired");const a=new C.Object("LeapPayAccountSettings"),{company:r}=(n==null?void 0:n.attributes)||{};if(!r)throw new Error("Company not found");const{id:s}=r||{},i=new C.Object("_User");i.id=(n==null?void 0:n.id)||"";const c=new C.Object("Company");if(c.id=s,a.set("isDefaultPaymentMethod",t.isDefaultPaymentMethod),a.set("paymentMethod",t.paymentMethod),a.set("company",c),a.set("updatedBy",i),t.office_id){const o=new C.Object("Office");o.id=String(t.office_id)||"",a.set("office",o.toPointer())}return a.save()}
1,Xa=async t=>{const n=new C.Object("LeapPayAccountSettings");n.id=t.id;const a=C.User.current();if(!a)throw new Error("Session expired");const{company:r}=(a==null?void 0:a.attributes)||{};if(!r)throw new Error("Company not found");const{id:s}=r||{},i=new C.Object("_User");i.id=(a==null?void 0:a.id)||"";const c=new C.Object("Company");c.id=s;const o={isDefaultPaymentMethod:t.isDefaultPaymentMethod,paymentMethod:t.paymentMethod,company:c,updatedBy:i};if(t.office_id){const d=new C.Object("Office");d.id=String(t.office_id)||"",o.office=d.toPointer()}return n.save(o)},qe=t=>{var a;const n={id:(t==null?void 0:t.id)||"",isDefaultPaymentMethod:t==null?void 0:t.attributes.isDefaultPaymentMethod,paymentMethod:t==null?void 0:t.attributes.paymentMethod,paymentMethodsCloned:((a=t==null?void 0:t.attributes)==null?void 0:a.paymentMethodsCloned)??void 0};return Qa.parse(n)},Ja=async t=>{const n=await Ka(t);return qe(n)},Za=async t=>Va(t),es=async t=>Xa(t),ts=async t=>{if(t.id){const a=await es(t);return qe(a)}const n=await Za(t);return qe(n)},ns=async(t,n)=>{await le.httpPut(`${fe.ARCHIVE_LEAP_PAY_ACCOUNT}/${t}`,n,{headers:he()})},as=async(t,n)=>{await ns(t,n)},ss=t=>{const{subAccount:n,setSubAccount:a}=S.useContext(ae),{setSnackbar:r}=J(),{showSuccessModal:s}=On(),i=(n==null?void 0:n.uuid)||"",{onClose:c}=t,[o,d]=S.useState(!1),[h,p]=S.useState(""),[m,l]=S.useState(!1),y=()=>{c(!1)},_=ee({mutationKey:"archiveLeapPayAccount",mutationFn:()=>as(i,{status:"archived",reason:h}),onError:E=>{r({children:(E==null?void 0:E.message)||Q,severity:"error"})},onSuccess:()=>{a({...n,status:"archived"}),c(!1),s({title:"Your close request has been received",msg:"We’re so sorry to see you go. Your Leap Pay account will be deleted upon completion of all pending payments and payout. Your customers will no longer be able to pay you using Leap Pay.",titleColor:"primary",buttonText:"OK"})}}),w=()=>
1{if(!o){d(!0);return}_.mutate()},T=()=>e.jsx(j,{variant:"body1",textAlign:"left",children:"Your customers will no longer be able to pay you using Leap Pay. Your Leap Pay account will be deleted upon completion of all currently pending payments and payout."}),L=()=>e.jsxs(g,{children:[e.jsx(pe,{type:"reason",label:"Reason for Leaving (Optional)",value:h,name:"reason_for_leaving",onChange:E=>p(E.target.value),fullWidth:!0}),e.jsx(g,{pt:3}),e.jsxs(Ge,{severity:"warning","data-testid":"delete-account-warning",sx:{backgroundColor:"#feede1",color:"#2e2e2e"},children:[e.jsx(Ye,{children:"Are you sure you want to close your Leap Pay account? This action can not be undone."}),e.jsx(Lt,{control:e.jsx(Ot,{checked:m,onChange:()=>{l(E=>!E)}}),label:"I understand and wish to continue."})]})]});return e.jsxs(Ne,{"data-testid":"leappay-account-deletion-modal",open:!0,onClose:y,sx:{"& .MuiPaper-root":{maxWidth:"600px"}},title:"Confirm closing your Leap Pay account",children:[e.jsx(g,{pt:1,children:o?L():T()}),e.jsxs(g,{mt:4,textAlign:"center",children:[e.jsx(V,{variant:"contained",color:"error",size:"medium","data-testid":"confirm-archive-leap-pay-btn",loading:_.isLoading,disabled:o&&!m,onClick:w,children:`${o?"Confirm":"Close"} Leap Pay Account`}),e.jsx(ne,{sx:{ml:2},color:"secondary",variant:"outlined",onClick:y,"data-testid":"cancel-archive-leap-pay-btn","data-cy":"cancel",children:"Cancel"})]})]})},is=({applicationFee:t,field:n,errors:a})=>{var m;const r=X(),s=r["card-repricing"],i=r["expedited-ach-payment"],c=r["leappay-ach-cap"],o=s&&kt(t),d=()=>{var l,y;if(o){const u=((l=t.CREDIT_CARD)==null?void 0:l.RATE)??t.CARD_RATE,b=(y=t.CREDIT_CARD)==null?void 0:y.FIXED_PRICE,_=b?` + ${z(b)}`:"",w=Ft(t,z),T=w?` (${w})`:"";return`Instant processing with ${u}%${_} fee${T}`}return`Instant processing with ${t.CARD_RATE}% + ${z(t.CARD_FIXED_PRICE)} fee`},h=()=>{var y,u;const l=i?"1-2":"3-5";if(o){const b=((y=t.ACH)==null?void 0:y.RATE)??t.ACH_RATE;if(c){const _=((u=t.ACH)==null?void 0:u.MAX_FEE)??t.ACH_MAX_FEE;return`${l} Business days processing time with ${b}% fee (${z(_)} max)`}return`${l} Business days processing time with ${b}% fee`}return`${l} Business days processing time with ${t.ACH_RATE}% fee (${z(t.ACH_MAX_FEE)} max)`},p=[{label:"Both: Debit/Credit Cards and Bank Transfers (ACH)",value:ve.card_and_ach,desc:""},{label:"Debit/Credit Cards Only",value:ve.card,desc:d()},{label:"Bank Transfers (ACH) Only",value:ve.ach,desc:h()}];return e.jsx(ke,{...n,labelId:"payment-method-label",id:"payment-method",label:"Payment Method",value:n.value,error:!!((m=a.paymentMethod)!=null&&m.message),"data-testid":"leap-pay-payment-method-select",children:p==null?void 0:p.map(l=>e.jsx(be,{value:l.value,children:e.jsxs(g,{children:[e.jsx(j,{variant:"body1",children:l.label}),e.jsx(j,{variant:"body2",color:"textSecondary",fontSize:12,children:l.desc})]})},l.value))})},os=async t=>await C.Cloud.run("unlinkOfficeSubaccount",t),rs=async t=>{await os(t)},cs=({officeId:t,onClose:n,onSuccess:a,accountSettings:r})=>{const{setSnackbar:s}=J(),{subAccount:i}=S.useContext(ae),[c,o]=S.useState(!1),d=()=>{n(!1)},p=ee({mutationKey:"unlinkAccountFromOffice",mutationFn:()=>rs({office_id:t||"",account_id:(i==null?void 0:i.account_id)||""}),onError:m=>{s({children:(m==null?void 0:m.message)||Q,severity:"error"})},onSuccess:()=>{s({children:"Account Unlinked Successfully",severity:"success"}),d(),a()}});return e.jsx(et,{"data-testid":"leappay-account-deletion-modal",open:!0,onClose:d,sx:{"& .MuiPaper-root":{maxWidth:"600px"}},title:"Unlink Leap Pay Account From Office",children:(r==null?void 0:r.paymentMethodsCloned)===!1?e.jsx(Bn,{message:Pn}):e.jsxs(e.Fragment,{children:[e.jsx(g,{pt:1,children:e.jsx(g,{children:e.jsxs(Ge,{severity:"warning","data-testid":"unlink-leappay-account",sx:{backgroundColor:"#feede1",color:"#2e2e2e"},children:[e.jsx(Ye,{children:"Are you sure you want to unlink the existing Leap Pay account from your Office?"}),e.jsx(Lt,{control:e.jsx(Ot,{checked:c,onChange:()=>{o(m=>!m)}}),label:"I understand and wish to continue."})]})})}),e.jsxs(g,{mt:4,textAlign:"center",children:[e.jsx(V,{variant:"contained",color:"error",size:"medium","data-testid":"unlink-leap-pay-btn",disabled:!c,loading:p.isLoading,onClick:()=>p.mutate(),children:"Unlink Account"}),e.jsx(ne,{sx:{ml:2},color:"secondary",variant:"outlined",onClick:d,"data-testid":"cancel-unlink-leap-pay-btn","data-cy":"cancel",children:"Cancel"})]})]})})},dt={isDefaultPaymentMethod:!1,paymentMethod:""},ls=({applicationFee:t,officeId:n,handleLinkData:a})=>{const s=X()["leap-pay-with-office"],{setSnackbar:i}
1=J(),c=_e(),{accountSettings:o,setAccountSettings:d,subAccount:h}=S.useContext(ae),[p,m]=S.useState(!1),[l,y]=S.useState(!1),{control:u,handleSubmit:b,reset:_,formState:w}=Le({defaultValues:{isDefaultPaymentMethod:dt.isDefaultPaymentMethod,paymentMethod:dt.paymentMethod},mode:"all"}),{errors:T,isValid:L,isDirty:E}=w;S.useEffect(()=>{o&&_({isDefaultPaymentMethod:o==null?void 0:o.isDefaultPaymentMethod,paymentMethod:(o==null?void 0:o.paymentMethod)||ve.card_and_ach})},[o,_]);const I=P=>{i({children:(P==null?void 0:P.message)||Q,severity:"error"})},O=Y({queryKey:["fetchLeapPayAccountSettings"],queryFn:()=>Ja({office_id:n}),onSuccess:P=>{d(P)},refetchOnWindowFocus:!1,onError:I}),v=ee({mutationKey:"saveLeapPayAccountSettings",mutationFn:ts,onError:I,onSuccess:P=>{i({children:"Account Settings saved successfully",severity:"success"}),d(P),c.setQueryData("fetchLeapPayAccountSettings",()=>P)}}),f=P=>{const W={id:(o==null?void 0:o.id)||"",isDefaultPaymentMethod:P.isDefaultPaymentMethod,paymentMethod:P.paymentMethod,office_id:n};!L||!E||v.mutate(W)},k=P=>{P.preventDefault(),m(!0)},F=P=>{P.preventDefault(),y(!0)};return S.useEffect(()=>{s&&n&&O.refetch()},[n]),e.jsxs(g,{children:[e.jsx(me,{title:"Leap Pay Account Settings",children:O.isFetching?e.jsx(g,{height:"100%",py:8,textAlign:"center",children:e.jsx(ue,{})}):e.jsxs(De,{onSubmit:b(f),children:[e.jsxs(g,{children:[e.jsxs(j,{color:"content",variant:"subtitle2",display:"flex",alignItems:"center","data-testid":"section-is-leap-pay-default-method",children:[e.jsx(Ee,{name:"isDefaultPaymentMethod",control:u,render:({field:{value:P,...W}})=>e.jsx(jn,{...W,checked:P})}),e.jsx(g,{ml:2,children:"Leap Pay is the default payment processor"})]}),e.jsx(j,{color:"grey",display:"flex",fontSize:12,pt:1,ml:6,children:"This enables the Credit Card and ACH payment option in invoices to accept online payments."}),e.jsx(j,{pt:1,color:"grey",fontSize:12,ml:6,children:"To temporarily pause your Leap Pay account, simply switch it off. Any payments currently processing will continue as planned. You can reenable your account at any time."}),s&&(h==null?void 0:h.office_subaccounts)&&(h==null?void 0:h.office_subaccounts.length)>1&&e.jsx(j,{pt:1,fontSize:14,ml:6,children:e.jsx("a",{href:"/",onClick:F,"data-testid":"unlink-leap-pay",children:"Unlink your Leap Pay account"})}),e.jsxs(j,{pt:1,color:"grey",fontSize:12,ml:6,children:["To close your Leap Pay account permanently,"," ",e.jsx("a",{href:"/",onClick:k,"data-testid":"archive-leap-pay",children:"click here."})]})]}),e.jsx(g,{display:"block",component:"hr",mt:1,mb:2,width:"100%"}),e.jsx(g,{children:e.jsxs(de,{fullWidth:!0,variant:"outlined",sx:{width:"400px"},children:[e.jsx(Oe,{id:"payment-method-label",children:"Payment Method"}),e.jsx(Ee,{name:"paymentMethod",control:u,render:({field:P})=>e.jsx(is,{applicationFee:t,field:P,errors:T})}),e.jsx(j,{component:"span",color:"grey",fontSize:12,display:"flex",py:1,children:"Payment methods your customer can use."})]})}),e.jsx(g,{display:"flex",justifyContent:"flex-end",width:"100%",mb:1,children:e.jsx(V,{variant:"contained",color:"primary",type:"submit",size:"medium","data-testid":"save-account-settings-btn",loading:v==null?void 0:v.isLoading,disabled:!E||!L||(v==null?void 0:v.isLoading)||(O==null?void 0:O.isFetching),children:"Save"})})]})}),p&&e.jsx(ss,{onClose:()=>m(!1)}),l&&e.jsx(cs,{onSuccess:a,officeId:n,onClose:()=>y(!1),accountSettings:o})]})},ds=`<!DOCTYPE html>
2<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
3<head>
4    <meta charset="utf-8"> <!-- utf-8 works for most cases -->
5    <meta name="viewport" content="width=device-width"> <!-- Forcing initial-scale shouldn't be necessary -->
6    <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- Use the latest (edge) version of IE rendering engine -->
7    <meta name="x-apple-disable-message-reformatting">  <!-- Disable auto-scale in iOS 10 Mail entirely -->
8    <meta name="format-detection" content="telephone=no,address=no,email=no,date=no,url=no">
8 <!-- Tell iOS not to automatically link certain text strings. -->
9    <title></title> <!-- The title tag shows in email notifications, like Android 4.4. -->
10    
11
12    <!-- CSS Reset : BEGIN -->
13    <style>
14
15        /* What it does: Remove spaces around the email design added by some email clients. */
16        /* Beware: It can remove the padding / margin and add a background color to the compose a reply window. */
17        html,
18        body {
19            margin: 0 !important;
20            padding: 0 !important;
21            height: 100% !important;
22            width: 100% !important;
23        }
24
25        /* What it does: Stops email clients resizing small text. */
26        * {dd
27            -ms-text-size-adjust: 100%;
28            -webkit-text-size-adjust: 100%;
29        }
30
31        /* What it does: Centers email on Android 4.4 */
32        div[style*="margin: 16px 0"] {
33            margin: 0 !important;
34        }
35
36        /* What it does: Stops Outlook from adding extra spacing to tables. */
37        table,
38        td {
39            mso-table-lspace: 0pt !important;
40            mso-table-rspace: 0pt !important;
41        }
42
43        /* What it does: Fixes webkit padding issue. */
44        table {
45            border-spacing: 0 !important;
46            border-collapse: collapse !important;
47            table-layout: fixed !important;
48            margin: 0 auto !important;
49        }
50
51        /* What it does: Uses a better rendering method when resizing images in IE. */
52        img {
53            -ms-interpolation-mode:bicubic;
54        }
55
56        /* What it does: Prevents Windows 10 Mail from underlining links despite inline CSS. Styles for underlined links should be inline. */
57        a {
58            text-decoration: none;
59        }
60
61        /* What it does: A work-around for email clients meddling in triggered links. */
62        a[x-apple-data-detectors],  /* iOS */
63        .unstyle-auto-detected-links a,
64        .aBn {
65            border-bottom: 0 !important;
66            cursor: default !important;
67            color: inherit !important;
68            text-decoration: none !important;
69            font-size: inherit !important;
70            font-family: inherit !important;
71            font-weight: inherit !important;
72            line-height: inherit !important;
73        }
74
75        /* What it does: Prevents Gmail from changing the text color in conversation threads. */
76        .im {
77            color: inherit !important;
78        }
79
80        /* What it does: Prevents Gmail from displaying a download button on large, non-linked images. */
81        .a6S {
82            display: none !important;
83            opacity: 0.01 !important;
84        }
85        /* If the above doesn't work, add a .g-img class to any image in question. */
86        img.g-img + div {
87            display: none !important;
88        }
89
90        /* What it does: Removes right gutter in Gmail iOS app: https://github.com/TedGoas/Cerberus/issues/89  */
91        /* Create one of these media queries for each additional viewport size you'd like to fix */
92
93        /* iPhone 4, 4S, 5, 5S, 5C, and 5SE */
94        @media only screen and (min-device-width: 320px) and (max-device-width: 374px) {
95            u ~ div .email-container {
96                min-width: 320px !important;
97            }
98        }
99        /* iPhone 6, 6S, 7, 8, and X */
100        @media only screen and (min-device-width: 375px) and (max-device-width: 413px) {
101            u ~ div .email-container {
102                min-width: 375px !important;
103            }
104        }
105        /* iPhone 6+, 7+, and 8+ */
106        @media only screen and (min-device-width: 414px) {
107            u ~ div .email-container {
108                min-width: 414px !important;
109            }
110        }
111
112    </style>
113
114    <!-- What it does: Makes background images in 72ppi Outlook render at correct size. -->
115    <!--[if gte mso 9]>
116    <xml>
117        <o:OfficeDocumentSettings>
118            <o:AllowPNG/>
119            <o:PixelsPerInch>96</o:PixelsPerInch>
120        </o:OfficeDocumentSettings>
121    </xml>
122    <![endif]-->
123
124    <!-- CSS Reset : END -->
125
126    <!-- Progressive Enhancements : BEGIN -->
127    <style>
128
129        /* What it does: Hover styles for buttons */
130        .button-td,
131        .button-a {
132            transition: all 300ms ease-out;
133            border-color: #26d07c !important;
134        }
135        .button-td-primary:hover,
136        .button-a-primary:hover {
137            background: #8edd65 !important;
138            border-color: #8edd65 !important;
139        }
140
141        /* Media Queries */
142        @media screen and (max-width: 480px) {
143
144            /* What it does: Forces table cells into full-width rows. */
145            .stack-column,
146            .stack-column-center {
147                display: block !important;
148                width: 100% !important;
149                max-width: 100% !important;
150                direction: ltr !important;
151            }
152            /* And center justify these ones. */
153            .stack-column-center {
154                text-align: center !important;
155            }
156
157            /* What it does: Generic utility class for centering. Useful for images, buttons, and nested tables. */
158            .center-on-narrow {
159                text-align: center !important;
160                display: block !important;
161                margin-left: auto !important;
162                margin-right: auto !important;
163                float: none !important;
164            }
165            table.center-on-narrow {
166                display: inline-block !important;
167            }
168
169            /* What it does: Adjust typography on small screens to improve readability */
170            .email-container p {
171                font-size: 17px !important;
172            }
173            
174            h1{
175                font-size: 20px!important;
176            }
177            
178            h2{
179                font-size: 16px!important;
180            }
181        }
182
183    </style>
184    <!-- Progressive Enhancements : END -->
185
186</head>
187<!--
188    The email background color (#222222) is defined in three places:
189    1. body tag: for most email clients
190    2. center tag: for Gmail and Inbox mobile apps and web versions of Gmail, GSuite, Inbox, Yahoo, AOL, Libero, Comcast, freenet, Mail.ru, Orange.fr
191    3. mso conditional: For Windows 10 Mail
192-->
193<body width="100%" style="margin: 0; padding: 0 !important; mso-line-height-rule: exactly; background-color: #fafafa; font-family: 'arial', 'helvetica', sans-serif; ">
194    <center style="width: 100%; background-color: #fafafa;">
195    <!--[if mso | IE]>
196    <table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: #222222;">
197    <tr>
198    <td>
199    <![endif]-->
200
201        <!-- Visually Hidden Preheader Text : BEGIN -->
202        <div style="display: none; font-size: 1px; line-height: 1px; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden; mso-hide: all; font-family: sans-serif;">
203            Payment request from %companyName%
204        </div>
205        <!-- Visually Hidden Preheader Text : END -->
206
207        <!-- Create white space after the desired preview text so email clients don’t pull other distracting text into the inbox preview. Extend as necessary. -->
208        <!-- Preview Text Spacing Hack : BEGIN -->
209        <div style="display: none; font-size: 1px; line-height: 1px; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden; mso-hide: all; font-family: sans-serif;">
210            &zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;
211        </div>
212        <!-- Preview Text Spacing Hack : END -->
213
214        <!--
215            Set the email width. Defined in two places:
216            1. max-width for all clients except Desktop Windows Outlook, allowing the email to squish on narrow but never go wider than 680px.
217            2. MSO tags for Desktop Windows Outlook enforce a 680px width.
218            Note: The Fluid and Responsive templates have a different width (600px). The hybrid grid is more "fragile", and I've found that 680px is a good width. Change with caution.
219        -->
220        <div style="max-width: 580px; margin: 0 auto;" class="email-container">
221            <!--[if mso]>
222            <table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="680">
223            <tr>
224            <td>
225            <![endif]-->
226
227            <!-- Email Body : BEGIN -->
228            <table role="presentation" cellspacing="0" cellpadding="5" border="0" width="100%" style="margin: auto;">
229                <!--START NAV BAR-->
230                <tr style="background-color: #fff; vertical-align: middle !important;">
231                    <th colspan="4" style="padding-top: 25px; padding-bottom: 25px;">
232                            <img alt="Company Name & Logo" src="%companyLogo%" width="250"/>
233                    </th>
234                </tr>
235<!--END NAV BAR-->
236
237
238                <!-- 1 Column Text + Button : BEGIN -->
239                <tr>
240                    <td colspan="4" style="background-color: #ffffff;">
241                        <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
242                            <tr>
243                                <td style="padding: 10px; font-family: sans-serif; font-size: 16px; line-height: 25px; color: #555555;">
244                                    <h1 style="font-family: 'arial', 'helvetica', sans-serif; font-size: 40px; font-weight: 500; margin: 0; Margin-bottom: 10px; color: #333; line-height: 50px">Payment Requested</h1>
245                                    %message%
246                                    
247                                </td>
248                            </tr>
249                            
250
251                        </table>
252                    </td>
253
254                </tr>
255                <!-- 1 Column Text + Button : END -->
256                <!-- 1 Column Text : BEGIN -->
257                <tr>
258                    <td cellpadding="15" colspan="4" style="background-color: #ffffff;">
259                        <table role="presentation" cellspacing="0" cellpadding="30" border="0" width="100%">
260                            <tr>
261                                <td>
262                            <!-- Button : BEGIN -->
263                                        <table role="presentation" cellspacing="0" cellpadding="0" border="0" class="center-on-narrow">
264                                            <tr>
265                                                <td class="button-td button-td-primary" style="border-radius: 4px; background: #26d07c;">
266                                                    <a class="button-a button-a-primary" href="%payment_link_url%" style="background: #26d07c; border: 1px solid #000000; font-family: sans-serif; font-size: 15px; line-height: 15px; text-decoration: none; padding: 13px 17px; color: #000000; display: block; border-radius: 4px;">Submit Payment</a>
267                                                </td>
268                                            </tr>
269                                        </table>
270                            <!-- Button : END -->
271                             <p style="margin: 10px 0 10px; text-align:center;"><em>Note: This link will expire in 7 days.</em></p>
272                        </td>
273                    </tr>
274                        </table>
275                    </td>
276                </tr>
277                <!-- 1 Column Text : END -->
278            </table>
279            <!-- Email Body : END -->
280
281            <!-- Email Footer : BEGIN -->
282            <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="max-width: 580px;">
283                <tr>
284                    <td style="padding: 20px; font-family: sans-serif; font-size: 12px; line-height: 15px; text-align: center; color: #ced4da; background-color: #212529;">
285                        <img src="https://api.leaptodigital.com/leap/files/vsJUoMTVBxWim04bhb92eEHYlC7CF5TGGeV5zeTL/f57ec48f5bc740bb4a3f01575190522f_leap_logo_light.png" alt="Powered by Leap" width="122"/><br/>
286                        Powered by Leap&trade;
287                    </td>
288                </tr>
289            </table>
290            <!-- Email Footer : END -->
291
292            <!--[if mso]>
293            </td>
294            </tr>
295            </table>
296            <![endif]-->
297        </div>
298
299    <!--[if mso | IE]>
300    </td>
301    </tr>
302    </table>
303    <![endif]-->
304    </center>
305</body>
306</html>`,us=async t=>{const n=C.User.current();if(!n)throw new Error("Session expired");const a=new C.Query("LeapPayRemotePaymentCaptureSettings"),{company:r={}}=(n==null?void 0:n.attributes)||{};if(!r)throw new Error("Company not found");const{id:s}=r||{},i=new C.Object("Company");if(i.id=s,t.office_id){const o=new C.Object("Office");o.id=String(t.office_id)||"",a.equalTo("office",o)}return a.equalTo("company",i),await a.first()},at=x.object({id:x.string().optional(),fromEmail:x.string().default(""),requestEmailSubject:x.string().default(""),emailTemplate:x.str
306ing().default("")}),He=t=>{const n={id:(t==null?void 0:t.id)||"",emailTemplate:t==null?void 0:t.attributes.emailTemplate,fromEmail:t==null?void 0:t.attributes.fromEmail,requestEmailSubject:t==null?void 0:t.attributes.requestEmailSubject};return at.parse(n)},Zt=x.object({id:x.string(),fromEmail:x.string().default(""),requestEmailSubject:x.string().default(""),emailTemplate:x.string().default("")}),ms=x.object({settings:Zt.nullable()}),ps=x.object({settings:Zt}),fs=async t=>{if(!C.User.current())throw new Error("Session expired");const a=await C.Cloud.run("getLeapPayRemotePaymentCaptureSettings",t?{officeId:String(t)}:{});return ms.parse(a).settings},hs=async t=>{if(!C.User.current())throw new Error("Session expired");const a={fromEmail:t.fromEmail??"",requestEmailSubject:t.requestEmailSubject??"",emailTemplate:t.emailTemplate??""};t.id&&(a.id=String(t.id)),t.office_id!==void 0&&t.office_id!==""&&(a.officeId=String(t.office_id));const r=await C.Cloud.run("saveLeapPayRemotePaymentCaptureSettings",a);return ps.parse(r).settings},xs=async t=>{if((await je).variation("finance-lending-dashboard-redesign",!1)){const s=await fs(t.office_id?String(t.office_id):void 0);return at.parse(s??{})}const r=await us(t);return He(r)},gs=async t=>{const n=C.User.current();if(!n)throw new Error("Session expired");const a=new C.Object("LeapPayRemotePaymentCaptureSettings"),{company:r}=(n==null?void 0:n.attributes)||{};if(!r)throw new Error("Company not found");const{id:s}=r||{},i=new C.Object("_User");i.id=(n==null?void 0:n.id)||"";const c=new C.Object("Company");if(c.id=s,a.set("fromEmail",t.fromEmail),a.set("emailTemplate",t.emailTemplate),a.set("requestEmailSubject",t.requestEmailSubject),a.set("company",c),a.set("updatedBy",i),t.office_id){const o=new C.Object("Office");o.id=String(t.office_id),a.set("office",o.toPointer())}return a.save()},ys=async t=>{const n=new C.Object("LeapPayRemotePaymentCaptureSettings");n.id=t.id;const a=C.User.current();if(!a)throw new Error("Session expired");const{company:r}=(a==null?void 0:a.attributes)||{};if(!r)throw new Error("Company not found");const{id:s}=r||{},i=new C.Object("_User");i.id=(a==null?void 0:a.id)||"";const c=new C.Object("Company");c.id=s;const o={emailTemplate:t.emailTemplate,fromEmail:t.fromEmail,requestEmailSubject:t.requestEmailSubject,company:c,updatedBy:i};if(t.office_id){const d=new C.Object("Office");d.id=String(t.office_id),o.office=d.toPointer()}return n.save(o)},bs=async t=>gs(t),js=async t=>ys(t),Ss=async t=>{if((await je).variation("finance-lending-dashboard-redesign",!1)){const s=await hs(t);return at.parse(s)}if(t.id){const s=await js(t);return He(s)}const r=await bs(t);return He(r)},Cs=({officeId:t})=>{var L,E,I,O;const{setSnackbar:n}=J(),a=_e(),s=X()["leap-pay-with-office"],[i,c]=S.useState(),{control:o,register:d,handleSubmit:h,formState:p,reset:m}=Le({defaultValues:{emailTemplate:ds,fromEmail:"",requestEmailSubject:"Payment Request"},mode:"all"}),{errors:l,isDirty:y,isValid:u}=p,b=v=>{n({children:(v==null?void 0:v.message)||Q,severity:"error"})},_=Y({queryKey:["fetchLeapPayRemotePaymentCaptureEmailSettings"],queryFn:()=>xs({office_id:t}),onSuccess:v=>{c(v)},refetchOnWindowFocus:!1,onError:b}),w=ee({mutationKey:"saveLeapPayRemotePaymentCaptureEmailSettings",mutationFn:Ss,onError:b,onSuccess:v=>{n({children:"Remote Payment Capture Settings saved successfully",severity:"success"}),c(v),a.setQueryData("saveLeapPayRemotePaymentCaptureEmailSettings",()=>v)}}),T=h(async v=>{const f={id:(i==null?void 0:i.id)||"",...v};s&&(f.office_id=t),w.mutate(f)});return S.useEffect(()=>{i!=null&&i.fromEmail&&m({fromEmail:i.fromEmail,emailTemplate:i.emailTemplate,requestEmailSubject:i.requestEmailSubject})},[i]),S.useEffect(()=>{s&&_.refetch()},[t]),e.jsx(g,{children:e.jsxs(me,{title:"Remote Payment Capture Email Settings",children:[_.isFetching&&e.jsx(g,{height:"100%",py:8,textAlign:"center",children:e.jsx(ue,{})}),!_.isFetching&&e.jsxs(e.Fragment,{children:[e.jsx(g,{mt:1,children:e.jsx(de,{fullWidth:!0,variant:"outlined",sx:{width:"400px"},children:e.jsx(pe,{placeholder:"Enter Email",label:"Default From Email",InputLabelProps:{shrink:!0},inputProps:{"data-testid":"from-email-remote-payment-capture-settings"},helperText:(L=l.fromEmail)==null?void 0:L.message,error:!!((E=l.fromEmail)!=null&&E.message),...d("fromEmail",{required:"From Email is required!",pattern:{message:"Invalid Email Address!",value:Fe}}),fullWidth:!0})})}),e.jsx(g,{mt:3,children:e.jsx(de,{fullWidth:!0,variant:"outlined",sx:{width:"400px"},children:e.jsx(pe,{size:"medium",placeholder:"Enter Email",inputProps:{"data-testid":"request-email-subject-remote-payment-capture-settings"},label:"Request Email Subject",helperText:(I=l.requestEmailSubject)==null?void 0:I.message,error:!!((O=l.requestEmailSubject)!=null&&O.message),...d("requestEmailSubject",{required:"Request Email Subject is required!"}),fullWidth:!0})})}),e.jsx(g,{mt:3,sx:{width:"100%"}
306,children:e.jsx(Ee,{control:o,name:"emailTemplate",rules:{required:"Email Template is required!",pattern:{value:/([\s\S]*%message%[\s\S]*%payment_link_url%[\s\S]*)|([\s\S]*%payment_link_url%[\s\S]*%message%[\s\S]*)/,message:"Must include : %message% and %payment_link_url% on Template"}},render:({field:v})=>{var f,k;return e.jsx(kn,{validationText:(f=l.emailTemplate)==null?void 0:f.message,defaultValue:(k=p.defaultValues)==null?void 0:k.emailTemplate,...v})}})}),e.jsx(g,{display:"flex",justifyContent:"flex-end",width:"100%",mb:1,children:e.jsx(V,{variant:"contained",color:"primary",disabled:!y||!u,onClick:T,loading:_.isFetching||w.isLoading,size:"medium","data-testid":"save-remote-payment-capture-settings-btn",children:"Save"})})]})]})})},ws=x.object({id:x.string(),email:x.string(),notifications:x.array(x.string()).default([]),order:x.number().default(1)}),vs=x.array(ws),en=x.object({id:x.string(),email:x.string().default(""),notifications:x.array(x.string()).default([]),order:x.number().default(1)}),Ps=x.object({settings:x.array(en)}),Es=x.object({settings:x.array(en),appliedToAllCount:x.number().default(0)}),As=async t=>{if(!C.User.current())throw new Error("Session expired");const a=await C.Cloud.run("getLeapPayCustomEmailNotificationSettings",t?{officeId:String(t)}:{});return Ps.parse(a).settings},Ts=async t=>{if(!C.User.current())throw new Error("Session expired");const a=s=>s.map(i=>({...i.id?{id:String(i.id)}:{},email:String(i.email??""),notifications:(i.notifications??[]).map(String),order:typeof i.order=="number"?i.order:1})),r=await C.Cloud.run("batchSaveLeapPayCustomEmailNotificationSettings",{creates:a(t.creates),updates:a(t.updates),deletes:t.deletes.map(String),...t.officeId?{officeId:String(t.officeId)}:{},...t.leapPayWithOffice!==void 0?{leapPayWithOffice:t.leapPayWithOffice}:{},...t.applyToAll?{applyToAll:!0}:{}});return Es.parse(r)},_s=async t=>{const n=await As(t.office_id?String(t.office_id):void 0);return vs.parse(n)},Ls=async(t,n,a,r=!1,s=!1)=>{const i=n.map(p=>p.id),c=t.map(p=>p.id).filter(Boolean),o=t.filter(p=>!p.id).map(({email:p,notifications:m,order:l})=>({email:p,notifications:m,order:l})),d=t.filter(p=>p.id&&i.includes(p.id)).map(({id:p,email:m,notifications:l,order:y})=>({id:p,email:m,notifications:l,order:y})),h=n.filter(p=>!c.includes(p.id)).map(p=>p.id);return Ts({creates:o,updates:d,deletes:h,officeId:a?String(a):void 0,leapPayWithOffice:r,applyToAll:s})},tn={tableContainer:{flexGrow:1,width:"100%",overflowY:"hidden","*::-webkit-scrollbar":{width:"6px !important",height:"6px !important"},border:"1px solid #2E2E2E3B",borderRadius:"16px"},gridContainer:{display:"flex",alignItems:"center",flexWrap:"nowrap",paddingTop:0,paddingBottom:0,paddingRight:2,border:"1px solid #F6F6F7",margin:0,borderTopLeftRadius:16,borderTopRightRadius:16,backgroundColor:"gray1.main",minHeight:48,columnGap:3},fieldContainer:{display:"flex",flexDirection:"column",height:"auto",maxHeight:"360px",overflowY:"auto"},pagination:{"& p":{margin:0}},row:{display:"flex",alignItems:"center",flexWrap:"nowrap",columnGap:3,padding:"12px 16px 12px 16px",backgroundColor:"#fff",borderBottom:"1px solid #e0e0e0","&:hover":{backgroundColor:"#f9f9f9"}},grabber:{display:"flex",alignItems:"center",cursor:"grab"}},Os=ye.memo(t=>{var w,T;const{id:n,control:a,register:r,errors:s,remove:i,index:c,notificationsOptions:o}=t,d=tn,{attributes:h,listeners:p,setNodeRef:m,setActivatorNodeRef:l,transform:y,transition:u}=Ke({id:n}),b={transform:Ve.Transform.toString(y),transition:u||""},_=(T=(w=s.emailItems)==null?void 0:w[c])==null?void 0:T.email;return e.jsxs(g,{ref:m,style:b,sx:d.row,"data-testid":`custom-email-row-${c}`,children:[e.jsx(g,{ref:l,sx:d.grabber,...h,...p,"data-testid":`custom-email-grabber-${c}`,children:e.jsx(tt,{})}),e.jsx(g,{flex:5,children:e.jsx(pe,{fullWidth:!0,size:"small",label:"Email",color:"secondary",inputProps:{"data-testid":`custom-email-input-${c}`},...r(`emailItems.${c}.email`,{required:"Email is required",pattern:{value:Fe,message:"Invalid email address!"}}),error:!!_,helperText:_==null?void 0:_.message})}
306),e.jsx(g,{flex:5,children:e.jsx(Ee,{control:a,name:`emailItems.${c}.notifications`,rules:{required:!0},render:({field:L})=>{const E=L.value||[];return e.jsx(ie,{label:"Notifications",size:"small",formControlSx:{m:0,width:"100%"},variant:"outlined",options:o,name:L.name,value:E,onChange:L.onChange,showSelectedCount:!0,selectedCountLabel:`${E.length} Notifications Selected`,"data-testid":`custom-notifications-${c}`})}})}),e.jsx(g,{children:e.jsx(Xe,{onClick:()=>i(c),sx:{padding:"4px"},"data-testid":`remove-custom-email-${c}`,children:e.jsx(Je,{sx:{color:"#F1001F"}})})})]})}),ks=[5,10,20],nn=t=>{const{loading:n,fields:a,control:r,register:s,errors:i,notificationsOptions:c,move:o,remove:d,prepend:h}=t,p=tn,[m,l]=S.useState(0),[y,u]=S.useState(20),b=pt(Pe(xt),Pe(ht,{coordinateGetter:ft})),_=L=>{const{active:E,over:I}=L;if(I&&E.id!==I.id){const O=a.findIndex(f=>f.id===E.id),v=a.findIndex(f=>f.id===I.id);O>-1&&v>-1&&o(O,v)}},w=S.useMemo(()=>{const L=m*y;return a.map((E,I)=>({field:E,index:I})).slice(L,L+y)},[a,m,y]),T=a.map(L=>L.id);return e.jsxs(g,{sx:p.tableContainer,children:[e.jsxs(D,{container:!0,sx:p.gridContainer,children:[e.jsx(g,{width:"16px",ml:2}),e.jsx(D,{item:!0,xs:5,children:e.jsx(j,{variant:"body1",fontWeight:"bold",children:"Email"})}),e.jsx(D,{item:!0,xs:5,children:e.jsx(j,{variant:"body1",fontWeight:"bold",children:"Notifications"})}),e.jsx(D,{item:!0,xs:!0,display:"flex",justifyContent:"flex-end",children:e.jsx(ne,{color:"secondary",variant:"text",onClick:()=>h({email:"",notifications:c.map(L=>L.value),order:1}),"data-testid":"add-custom-email-btn",children:"Add +"})})]}),n&&e.jsx(g,{height:"100%",py:6,textAlign:"center",children:e.jsx(ue,{})}),!n&&a.length===0&&e.jsx(g,{py:2,textAlign:"center",children:e.jsx(j,{variant:"subtitle2",children:"It looks like you don't have any custom email notification settings yet."})}),!n&&a.length>0&&e.jsx(gt,{sensors:b,collisionDetection:bt,modifiers:[yt],onDragEnd:_,children:e.jsx(jt,{items:T,strategy:St,children:e.jsx(g,{sx:p.fieldContainer,children:w.map(({field:L,index:E})=>e.jsx(Os,{id:L.id,control:r,register:s,errors:i,remove:d,index:E,notificationsOptions:c},L.id))})})}),e.jsx(Te,{}),e.jsx(Ze,{component:"div",sx:p.pagination,rowsPerPageOptions:ks,count:a.length,page:m,rowsPerPage:y,onPageChange:(L,E)=>l(E),onRowsPerPageChange:L=>{u(parseInt(L.target.value,10)),l(0)}})]})};ye.memo(nn);const ut=t=>t.map(n=>({id:n.id,email:n.email,notifications:n.notifications,order:n.order})),an=({officeId:t})=>{const{setSnackbar:n}=J(),a=_e(),s=X()["leap-pay-with-office"],i=Fn(),c=!!s&&!!i&&i.maxOfficeCount!==1,[o,d]=S.useState([]),[h,p]=S.useState([]),{control:m,register:l,handleSubmit:y,reset:u,formState:b}=Le({defaultValues:{emailItems:[]},mode:"onChange"}),{errors:_}=b,{fields:w,prepend:T,remove:L,move:E}=wt({control:m,name:"emailItems"}),I=N=>n({children:(N==null?void 0:N.message)||Q,severity:"error"}),O=Y({queryKey:["fetchLeapPayEmailNotificationType"],queryFn:Kt,onSuccess:N=>p(N.map(B=>({label:B.label,value:String(B.value)}))),refetchOnWindowFocus:!1,onError:I}),v=Y({queryKey:["fetchLeapPayCustomEmailNotificationSettings",t],queryFn:()=>{const N={};return s&&t&&(N.office_id=t),_s(N)},onSuccess:N=>{d(N),u({emailItems:ut(N)})},refetchOnWindowFocus:!1,onError:I}),f=ee({mutationKey:"batchSaveLeapPayCustomEmailNotificationSettings",mutationFn:({rows:N,applyToAll:B})=>Ls(N,o,t,!!s,B),onError:I,onSuccess:N=>{d(N.settings),u({emailItems:ut(N.settings)}),n({children:"Custom Email Notification Settings saved successfully",severity:"success"}),a.setQueryData(["fetchLeapPayCustomEmailNotificationSettings",t],N.settings)}});S.useEffect(()=>{s&&v.refetch()},[t]);const k=N=>N.emailItems.map((B,K)=>({id:B.id||"",email:B.email,notifications:B.notifications,order:K+1})),F=y(N=>{f.mutate({rows:k(N),applyToAll:!1})}),P=y(N=>{In({title:"Apply to all offices",msg:"This will overwrite the custom notification email list for every office in your company with the list shown above. This cannot be undone.",confirmText:"Confirm",onConfirm:()=>f.mutate({rows:k(N),applyToAll:!0})})}),W=v.isFetching||O.isFetching;return e.jsx(g,{children:e.jsxs(me,{title:"Custom Email Notification Settings",children:[e.jsx(j,{variant:"body1",mb:2,children:"Add email addresses (including non-SalesPro users) to receive Leap Pay notifications, and choose which notifications each address receives. Sales reps still receive notifications for transactions they initiate."}),e.jsx(nn,{loading:W,fields:w,control:m,register:l,errors:_,notificationsOptions:h,move:E,remove:L,prepend:T}),e.jsxs(g,{display:"flex",justifyContent:"flex-end",gap:1,width:"100%",mt:2,mb:1,children:[c&&e.jsx(V,{variant:"outlined",color:"secondary",onClick:P,loading:f.isLoading,size:"medium","data-testid":"apply-to-all-btn",children:"Apply to all office
306s"}),e.jsx(V,{variant:"contained",color:"primary",onClick:F,loading:f.isLoading,size:"medium","data-testid":"save-custom-email-btn",children:"Save"})]})]})})};an.defaultProps={officeId:""};const Fs=async(t,n)=>{const a=C.User.current();if(!a)return{mappedTransactions:[],totalRecords:0};const r=a.get("company"),s=new C.Query("PaymentTransaction").equalTo("company",r).equalTo("paymentGateway","LeapPay").include(["paymentMethod","paymentMethod.customer.estimate","paymentRefunds"]).limit(n.limit).descending("createdAt");if(n.page&&s.skip(n.page*n.limit),t.office.length){const d=new C.Query("Office");d.containedIn("objectId",t.office);const h=new C.Query("PaymentMethod");h.matchesQuery("office",d),s.matchesQuery("paymentMethod",h)}if(t.user.length){const d=new C.Query(Sn.User);d.containedIn("objectId",t.user),s.matchesQuery("createdBy",d)}if(t.date.length){const[d,h]=t.date;if(d&&h){const p=M(d).startOf("day").toDate(),m=M(h).endOf("day").toDate();s.greaterThanOrEqualTo("createdAt",p),s.lessThanOrEqualTo("createdAt",m)}}t.status!==q.ALL&&t.status!==q.EMPTY&&s.equalTo("status",t.status);const i=await s.find(),c=await s.count();return{mappedTransactions:i.map(d=>d),totalRecords:c}},Is=async t=>await C.Cloud.run("exportLeapPayPastTransactionsActivity",{filters:t}),mt=[{value:"All",label:"All"},{value:q.SUCCEEDED,label:"Succeeded"},{value:q.FULLY_REFUNDED,label:"Fully Refunded"},{value:q.PARTIAL_REFUNDED,label:"Partially Refunded"},{value:q.CANCELED,label:"Canceled"},{value:q.FAILED,label:"Failed"},{value:q.PENDING,label:"Pending"},{value:q.DISPUTED,label:"Disputed"}],Rs=({statusFilter:t,setStatusFilter:n,setFilters:a,filters:r})=>e.jsxs(de,{fullWidth:!0,variant:"outlined",sx:{width:"200px",marginBottom:"16px"},children:[e.jsx(Oe,{id:"date-range-label",children:"Status Filter"}),e.jsx(ke,{size:"small",sx:{minWidth:200},value:t||mt[0].value,onChange:s=>{n(s.target.value),a({...r,status:s.target.value==="All"?"":s.target.value})},label:"Payment Status","data-cy":"statusFilter","data-testid":"statusFilter",children:mt.map(s=>e.jsx(be,{value:s.value,"data-testid":s.value,children:e.jsx(g,{children:e.jsx(j,{variant:"body1",children:s.label})})},s.value))})]}),Ns=t=>{var y,u,b,_;const{officeOptions:n,userListOptions:a,filters:r,setFilters:s,filterTransactions:i}=t,[c,o]=S.useState("all_time"),h=X()["leap-pay-with-office"],p=w=>{const T=M().format(U);switch(w){case"YTD":return[M().startOf("year").format(U),T];case"MTD":return[M().startOf("month").format(U),T];case"past_30_days":return[M().subtract(30,"day").format(U),T];case"past_90_days":return[M().subtract(90,"day").format(U),T];case"all_time":return["",""];case"custom_date_range":default:return[r.date[0],r.date[1]]}},m=()=>{i()},l=async()=>{try{const w=await Is(r);Be({title:"Past Activity Export Success",msg:w.message,buttonText:"OK"})}catch(w){Mt({title:"Past Activity Export Error",showVerbose:!0,error:w})}};return e.jsx(ze,{sx:{height:"100%",padding:"12px 0 12px 0",margin:0},children:e.jsx(We,{justifyContent:"space-between",alignItems:"flex-end",m:0,children:e.jsxs(vt,{flexDirection:"row",flexWrap:"wrap",columnGap:2,children:[!h&&e.jsx(ie,{label:"Select Offices",inputLabelProps:{size:"small"},size:"small",formControlSx:{m:0,minWidth:200},variant:"outlined",options:n,value:r.office,showSelectedCount:!0,selectedCountLabel:((y=r.office)==null?void 0:y.length)===n.length?"Offices: All":`${(u=r.office)==null?void 0:u.length} Offices Selected`,onChange:w=>{const T=w.target.value||[];s({...r,office:T.length?ge.pull(T,"none"):[]})},"data-cy":"selectOffice","data-testid":"selectOffice",sx:{marginBottom:"16px"}}),e.jsx(ie,{label:"Select User(s)",inputLabelProps:{size:"small"},size:"small",formControlSx:{m:0,minWidth:200},options:a,variant:"outlined",value:r.user,showSelectedCount:!0,selectedCountLabel:((b=r.user)==null?void 0:b.length)===a.length?"Users: All":`${(_=r.user)==null?void 0:_.length} Users Selected`,onChange:w=>{const T=w.target.value||[];s({...r,user:T.length?ge.pull(T,"none"):[]})},"data-cy":"selectUser","data-testid":"selectUser",sx:{marginBottom:"16px"}}),e.jsxs(de,{fullWidth:!0,variant:"outlined",sx:{width:"200px",marginBottom:"16
306px"},children:[e.jsx(Oe,{id:"date-range-label",children:"Date Filter"}),e.jsx(ke,{size:"small",sx:{minWidth:200},value:c,onChange:w=>{o(w.target.value);const T=p(w.target.value);s({...r,date:T})},label:"Date Filter","data-cy":"dateFilter","data-testid":"dateFilter",children:It.map(w=>e.jsx(be,{value:w.value,"data-testid":w.value,children:e.jsxs(g,{children:[e.jsx(j,{variant:"body1",children:w.label}),e.jsx(j,{variant:"body2",color:"textSecondary",fontSize:12})]})},w.value))})]}),c==="custom_date_range"&&e.jsx(Pt,{dateAdapter:Et,children:e.jsx(At,{slots:{field:Tt},disableFuture:!0,value:[M(r.date[0],U),M(r.date[1],U)],sx:{width:"100%",borderColor:"secondary.main"},onChange:w=>{w!=null&&w[0]&&(w!=null&&w[1])&&s(T=>({...T,date:[M(w[0]).format(U),M(w[1]).format(U)]}))},slotProps:{textField:{size:"small",color:"secondary",sx:{minWidth:200}}},"data-cy":"selectDateRange","data-testid":"selectDateRange"})}),e.jsx(Rs,{statusFilter:r.status,setStatusFilter:w=>s({...r,status:w}),setFilters:s,filters:r}),e.jsx(V,{variant:"contained",color:"primary",type:"submit",size:"medium","data-testid":"apply-filter-btn",onClick:m,sx:{height:"fit-content",marginBottom:"16px"},children:"Apply"}),e.jsx(V,{variant:"contained",color:"primary",size:"medium","data-testid":"export-activity-btn",sx:{height:"fit-content",marginBottom:"16px"},onClick:l,children:"Export"})]})})})},Ds=()=>({refundButton:{width:"16px",height:"16px",display:"flex",alignItems:"center"},disputeButton:{backgroundColor:"transparent",border:"none",cursor:"pointer",color:"blue"},statusField:{display:"flex",alignItems:"center"},loadingIcon:{ml:1},actionIcon:{height:"auto",width:"auto",display:"flex",alignItems:"center","& svg":{width:"auto",height:"18px"}},tableHead:{backgroundColor:"gray1.main","& .MuiTableCell-head":{width:"150px"},"& .MuiTableCell-head:nth-of-type(8)":{width:"220px",minWidth:"220px"},"& .MuiTableCell-head:nth-of-type(15)":{width:"200px",minWidth:"200px"},"& .MuiTableCell-head:nth-of-type(16)":{width:"150px",minWidth:"150px"}},loadingCell:{textAlign:"center"},loadingContainer:{display:"flex",justifyContent:"center",alignItems:"center"},loadingText:{ml:2},transactionIdCell:{width:"200px",minWidth:"200px"},descriptionCell:{width:"40%"},actionsCell:{width:"50%"},noDataCell:{textAlign:"center"},tooltip:{textTransform:"capitalize",m:4,fontSize:"28px"}}),Ms=t=>{const{transactions:n,isLoading:a,uuid:r,refetchTransactions:s,isPaymentUpdating:i=()=>!1,estimateName:c}=t,o=Ds(),h=X()["hide-cardtype-and-brand"],p=h?15:16,m=u=>{var b;return u?u!=null&&u.errorDescription?e.jsx("h5",{children:u.errorDescription}):(b=u==null?void 0:u.paymentRefunds)!=null&&b.length?e.jsx(Hn,{paymentRefunds:u.paymentRefunds}):null:null},l=u=>u.status===q.PENDING&&u.paymentGateway===ot.LEAP_PAY&&u.paymentId&&i(u.paymentId),y=(u,b)=>`${ce(u||"")} ${ce(b||"")}`.trim()||"-";return e.jsxs(Ce,{"aria-label":"Details Table","data-testid":"payment-transaction-table",children:[e.jsx(Me,{sx:o.tableHead,children:e.jsxs(te,{children:[e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Date of Payment"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Customer Name"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Estimate Name"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Amount"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Payment Fee"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Net Balance"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Date of Deposit"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Transaction ID"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Payment Type"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Payment Method"})}),!h&&e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Card Type"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Status"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Created By"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Office"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Description"})}),e.jsx(A,{children:e.jsx(j,{variant:"subtitle2",children:"Actions"})})]})}),e.jsxs(we,{children:[a&&e.jsx(te,{children:e.jsx(A,{colSpan:p,sx:o.loadingCell,"data-testid":"loading-payment-data",children:e.jsxs(g,{sx:o.loadingContainer,children:[e.jsx(ue,{size:20}),e.jsx(j,{variant:"subtitle2",sx:o.loadingText,children:"Loading transactions..."})]})})}),!a&&n.map(u=>{var b,_;return e.jsxs(te,{"data-testid":"payment-transaction-row",children:[e.jsx(A,{children:M(u.createdAt).format(it)}),e.jsx(A,{children:y(u.nameFirst,u.nameLast)}),e.jsx(A,{children:u.estimateName||"-"}),e.jsx(A,{children:z(u.amount)}),e.jsx(A,{children:z(u.feeAmount||0)}),e.jsx(A,{children:z(u.amount-(u.feeAmount||0))}),e.jsx(A,{children:u.deposits_at?M(u.deposits_at).format(it):"-"}),e.jsx(A,{sx:o.transactionIdCell,children:u.paymentGateway===ot.LEAP_PAY?u.paymentId:u.id}),e.jsx(A,{children:zn(u)}),e.jsx(A,{children:Wn(u)}),!h&&e.jsx(A,{children:Un(u)}),e.jsx(A,{children:e.jsx(Cn,{sx:o.tooltip,title:m(u),children:e.jsx("span",{"data-testid":"payment-status",children:u.status===q.DISPUTED?e.jsx($n,{transaction:u}):e.jsxs(g,{sx:o.statusField,children:[ce(u.status),l(u)&&e.jsx(ue,{size:12,sx:o.loadingIcon})]})})})}),e.jsx(A,{"data-testid":"created-by",children:y((b=u.createdBy)==null?void 0:b.nameFirst,(_=u.createdBy)==null?void 0:_.nameLast)}),e.jsx(A,{"data-testid":"office-name",children:ce(u.officeName)}),e.jsx(A,{sx:o.descriptionCell,children:ce(u.description||"")}),e.jsx(A,{sx:o.actionsCell,children:e.jsx(qn,{transaction:u,showEstimateDetails:!0,uuid:r,estimateName:c,reFetchTransactions:s})})]},u.id)}),!a&&n.length===0&&e.jsx(te,{children:e.jsx(A,{colSpan:p,sx:o.noDataCell,"data-testid":"no-payment-data",children:e.jsx(j,{variant:"subtitle2",children:"It looks like we don't have any transactions yet."})})})]})]})},Bs={total:0,limit:20,page:0},zs=({officeId:t,uuid:n})=>{const{setSnackbar:a}=J(),{userOptions:r}=Dt(),{officeOptions:s}=zt(),[i,c]=S.useState([]),[o,d]=S.useState({...Bs}),[h,p]=S.useState({office:[],user:[],date:["",""],status:""}),[m,l]=S.useState(!1),b=Y({queryKey:"fetchPaymentTransactions",queryFn:async()=>{const E={...h};
306t&&(E.office=[t]);const{mappedTransactions:I,totalRecords:O}=await Fs(E,o);return d(v=>({...v,total:O})),I.map(Yn)},refetchOnWindowFocus:!1,onError:E=>{a({children:(E==null?void 0:E.message)||Q,severity:"error"})},retry:!1,onSuccess:E=>{c(E)}}),{isPaymentUpdating:_}=Gn({transactions:i,setTransactions:c,isLeapPayEnabled:!0}),w=(E,I)=>{d({...o,page:I}),l(O=>!O)},T=E=>{d({...o,limit:parseInt(E.target.value,10),page:0}),l(I=>!I)};S.useEffect(()=>{b.refetch()},[m]),S.useEffect(()=>{t&&(p({office:[t],user:[],date:["",""],status:""}),l(E=>!E))},[t]);const L=()=>{d({...o,page:0}),l(E=>!E)};return e.jsx(g,{"data-testid":"leappay-transaction-history-page",children:e.jsxs(me,{title:"Past Transactions","data-testid":"leappay-transaction-history-accordion",children:[e.jsx(Ns,{userListOptions:r,officeOptions:s,filters:h,setFilters:p,filterTransactions:L}),e.jsxs(_t,{sx:{marginBottom:"16px",maxHeight:"500px",border:"1px solid rgba(224, 224, 224, 1)"},children:[e.jsx(Ms,{uuid:n,transactions:i,isLoading:b.isFetching,refetchTransactions:b.refetch,isPaymentUpdating:_}),i.length!==0&&e.jsx(Ze,{component:"div",sx:{mr:3,"& p":{m:0}},rowsPerPageOptions:[5,10,20],count:o.total,page:o.page,rowsPerPage:o.limit,onPageChange:w,onRowsPerPageChange:T})]})]})})},Ws=({officeId:t,handleLinkData:n})=>{var m,l;const{subAccount:a}=S.useContext(ae),r=X(),s=r["card-repricing"],i=r["leappay-ach-cap"],c=C.User.current(),o=(l=(m=c==null?void 0:c.attributes)==null?void 0:m.company)==null?void 0:l.id,[d,h]=S.useState((a==null?void 0:a.leappayCompanyRate)||Ae);S.useEffect(()=>{o&&$t(o,s,i).then(y=>{h((y==null?void 0:y.leappayCompanyRate)||Ae)})},[o,s,i]);const p=()=>(a==null?void 0:a.status)===se.enabled;return e.jsxs(e.Fragment,{children:[e.jsx(g,{children:e.jsx(ma,{officeId:t})}),p()&&e.jsxs(e.Fragment,{children:[e.jsx(g,{mt:3,children:e.jsx(zs,{officeId:t,uuid:a==null?void 0:a.uuid})}),e.jsx(g,{mt:3,children:e.jsx(ls,{applicationFee:d,officeId:t,handleLinkData:()=>{n&&n()}})}),e.jsx(g,{mt:3,children:e.jsx(Xt,{officeId:t})}),e.jsx(g,{mt:3,children:e.jsx(Cs,{officeId:t})}),e.jsx(g,{mt:3,children:e.jsx(an,{officeId:t})})]}),e.jsx(g,{mt:3,children:e.jsx(Ya,{officeId:t})})]})},Us=async()=>{try{return await C.Cloud.run("fetchOfficesForLeappay")}catch(t){throw await Nt(t),t}},Js=()=>{const t=X(),n=t["leap-pay-with-office"],a=t["card-repricing"],r=t["leappay-ach-cap"],s=Ut,{setSnackbar:i}=J(),{setSubAccount:c,setBusiness:o,subAccount:d,business:h}=S.useContext(ae),[p,m]=S.useState([]),[l,y]=S.useState(null),[u,b]=S.useState(!1),_=f=>{i({children:(f==null?void 0:f.message)||Q,severity:"error"})},w=async f=>{try{const k=await Us();if(k){const F=k.map(P=>({...P,label:P.name,value:P.officeId,status:P.status===null?"not enabled":P.status}));m([En,...F]),f&&!(f!=null&&f.primary_office_id)&&b(!0)}}catch(k){_(k)}},T=Y({queryKey:["fetchSubAccount",{isCardRepricing:a,achCapEnabled:r}],queryFn:async()=>{const f={};if(n&&!(l!=null&&l.value))return null;n&&(l!=null&&l.value)&&(f.office_id=(l==null?void 0:l.value)||"");const{data:k}=await Kn(f,a,r);return k},onSuccess:f=>{f&&f.uuid?c(f):c(null)},refetchOnWindowFocus:!1,refetchOnReconnect:!1,enabled:!!t["leap-pay"]&&(!n||n&&!!(l!=null&&l.value)),onError:_}),L=Y({queryKey:["fetchBusiness"],queryFn:async()=>{const f={};if(n&&!(l!=null&&l.value))return null;n&&(l!=null&&l.value)&&(f.office_id=(l==null?void 0:l.value)||"");const{data:k}=await Wt(f);return k},onSuccess:f=>{let k=null;f&&f.uuid&&(k=f),o(k)},refetchOnWindowFocus:!1,refetchOnReconnect:!1,enabled:!!t["leap-pay"]&&(!n||n&&!!(l!=null&&l.value)),onError:_}),E=()=>{T.refetch(),L.refetch(),w(T.data)},I=f=>{f&&y({...f})},O=()=>h&&h.business_id&&d&&d.business_id?!1:!d||d.status===se.created;S.useEffect(()=>{t["leap-pay"]&&(T.refetch(),L.refetch())},[l]),S.useEffect(()=>{n&&w(T.data)},[n]),S.useEffect(()=>{const f=Qn(An);return()=>{f&&document.body.contains(f)&&f.remove()}},[]);const v=()=>e.jsx(We,{children:e.jsx(Gt,{officeList:p,onChange:f=>I(f),value:String((l==null?void 0:l.value)||""),isCustomOption:!0,width:"large"})});return t["leap-pay"]?T.isFetching||L.isFetching||n&&!p.length?e.jsx(Rn,{defaultLoading:!0,defaultMsg:"Loading..."}):n&&!(l!=null&&l.value)&&p?e.jsxs(ze,{sx:{height:"100%"},children:[e.jsx(g,{sx:s.leapPayOfficeFilter,children:v()}),u&&e.jsx(Yt,{linkedOffice:p,officeId:(l==null?void 0:l.value)||"",onSuccess:()=>{T.refetch(),L.refetch(),b(!1)},isForceLinking:u})]}):e.jsx(e.Fragment,{children:e.jsxs(g,{children:[O()&&e.jsx(g,{sx:s.leapPayBanner,children:e.jsx(g,{sx:s.leapPayBannerOverlay})}),e.jsxs(ze,{sx:{height:"100%"},children:[e.jsxs(g,{sx:n?s.leapPayOfficeFilter:s.leapPayHelpButton,children:[n&&v(),e.jsx(We,{children:!O()&&e.jsx(ne,{color:"secondary",variant:"contained",id:"leap-pay-help",children:"Help"})})]}),O()?e.jsx(oa,{afterOnBoarding:E,selectedOffice:l||{value:"",label:""},officeList:p}):e.jsx(Ws,{officeId:(l==null?void 0:l.value)||"",handleLinkData:E})]})]})}):null};export{Js as LeapPaySettings};

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