PageSourceSearch

https://app.withvayu.com/assets/UpdateCustomerSettings-20b2d3f6.js

js withvayu.com collected 2026-10-03 19:30:46 UTC 15,925 bytes, 1 lines download raw bytes

1import{r as h,j as t,q as ge,aS as xe,t as Ce,aN as H,ay as V,o as ye}from"./vendor-react-2cb5d109.js";import{$ as be,cP as Ee,g as W,d as j,f3 as S,f4 as D,f5 as Se,b as k,aT as oe,i as v,n as je,f6 as Te,f7 as Ie,f8 as ve,f9 as Re,fa as we,fb as q,q as Ve,X as Fe,a as K,cb as Me}from"./vendor-vy-bde48d53.js";import{u as re,aN as Ae,aM as De,g as ke,l as Q,H as Ne,aQ as _e}from"./vendor-misc-09f7f1da.js";import{E as O,e as Oe,p as Ue,q as le,_ as Pe,a5 as U,Z as $e,a6 as Be,bU as Le,w as Ge,k as ze,au as He}from"./app-core-47ba8b05.js";import{u as We}from"./use-validated-params-86b4212a.js";import{a as qe,P as Ke,F as Qe,D as Ye}from"./StickyTabBar-ef7bc3d6.js";import{c as Xe}from"./StickyPageHeader-b516c886.js";import{d as Ze,e as Je,n as P,u as et,a as tt,C as Y,b as $,c as F,f as st,g as nt}from"./first-section-with-errors-542f3b8f.js";import{e as X,a6 as de,c as T,b as R,bj as at,ay as Z,m as ce,r as ue,bk as it,n as me,d as N,a7 as ot,bl as fe,bm as rt,bn as pe,bo as J,l as M,o as lt,ar as A}from"./vendor-vy-ds-da93fbfd.js";import{B as ee,I as te,ba as dt,bi as ct,N as ut}from"./vendor-mui-c34240eb.js";import{u as mt}from"./use-update-customer-91712c3b.js";import{b as ft}from"./build-custom-field-rows-ced68044.js";import"./use-country-options-3439e58f.js";import"./page-frame-c2a7254f.js";import"./VyTextFieldField-1213b1b9.js";import"./VyBooleanCheckboxField-0950e339.js";import"./use-toggle-783e3c5d.js";import"./use-subsidiaries-8dc9e8d5.js";import"./reference-data-query-options-consts-650f2d3a.js";import"./VySelectField-91eba7ea.js";import"./use-morning-enabled-03af32c3.js";import"./use-debounce-9c73162a.js";import"./use-net-suite-customers-14528262.js";import"./use-can-connect-net-suite-2977086c.js";import"./VyNumberFieldField-69744edb.js";import"./use-integration-settings-73f65532.js";import"./tax-rate-mode-884ce489.js";import"./use-stripe-tax-enabled-f180c173.js";import"./invoice-due-date-consts-db66e4a6.js";import"./use-account-f5081143.js";import"./customer-portal-link-ce587fc6.js";import"./use-anchor-scroll-fa8df940.js";import"./use-state-params-e6f24508.js";(function(){try{var s=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};s.SENTRY_RELEASE={id:"a44d049e7c59"};var e=new s.Error().stack;e&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[e]="9d2d3333-bef1-4d02-84f4-a2cf2250ef04",s._sentryDebugIdIdentifier="sentry-dbid-9d2d3333-bef1-4d02-84f4-a2cf2250ef04")}catch{}})();const pt=be(S),ht=h.memo(({customerChild:s,onDeleteChild:e,customerName:o,onRelationTypeChange:a,relationType:n})=>{const i=r=>({[S.accumulateUsage]:`Aggregate usage to ${o}`,[S.accumulateCharges]:`Aggregate charges to ${o}`,[S.erpInvoiceSyncOnBehalfParent]:`Invoice sync to ${o} (ERP)`,[S.billToParent]:`Bill to ${o}`})[r]||`Unknown relation to ${o}`;return t.jsxs(qe,{children:[t.jsx(X,{label:"Name",disabled:!0,value:s.name,helperText:O}),t.jsx(X,{label:"External ID",disabled:!0,value:Ee(s.externalId),helperText:O}),t.jsx(de,{...W(D.relatedEntities.relationType),label:"Relationship type",options:pt,value:n,disableClearable:!0,getOptionLabel:i,onChange:(r,l)=>{j(l)&&a(s.id,l)},helperText:O}),t.jsx(T,{sx:{alignItems:"flex-start"},children:t.jsx(R,{...W(D.relatedEntities.delete),emphasis:"secondary",size:"small",startIcon:t.jsx(at,{width:Z,height:Z}),onClick:()=>e(s.id),"aria-label":`Remove ${s.name}`,children:"Delete"})})]})});function gt(s){return ge(le.customer("customer-children"),async()=>{const a=await Oe().getPotentialChildCustomers();return Ue(Se,a)},{refetchOnWindowFocus:!0,...s})}const se=({customerId:s,childrenToAdd:e,childrenToExclude:o,onChildSelect:a})=>{const[n,i]=h.useState(null),{handleClose:r,handleOpen:l,isDialogOpen:m}=Pe(),{data:g,isLoading:E}=gt(),y=(g==null?void 0:g.potentialChildCustomers)??[],u=h.useMemo(()=>xt(s,y,o,e),[s,y,o,e]),c=h.useMemo(()=>u.some(d=>!ne(d,s)),[u,s]),f=()=>{i(null),r()},x=()=>{n&&(a==null||a(n)),f()};return E?t.jsx(ce,{sx:{width:100,height:10,borderRadius:`${ue.full}px`}}):t.jsxs(T,{sx:{alignItems:"flex-start"},children:[t.jsx(R,{emphasis:"secondary",size:"small",startIcon:t.jsx(it,{width:16,height:16}),onClick:l,disabled:!c,"data-vy":"customer-settings-add-related-entity-open",children:"Add entity"}),t.jsx(me,{open:m,onClose:f,fullWidth:!0,title:"Add related entity",actions:t.jsx(R,{emphasis:"primary",onClick:x,disabled:k(n),"data-vy":"customer-settings-add-related-entity-confirm",children:"Confirm"}
1),children:t.jsxs(T,{sx:{gap:2},children:[t.jsx(N,{variant:"body2",sx:{color:"text.secondary"},children:"Add related entities and subsidiaries to this parent account"}),t.jsx(ot,{options:u,fullWidth:!0,autoFocus:!0,label:"Select entity",getOptionLabel:d=>`${d.name} ${j(d.externalId)?`- ${d.externalId}`:""}`,getOptionDisabled:d=>ne(d,s),onChange:(d,p)=>i(p)})]})})]})};function xt(s,e,o=[],a=[]){const n=new Set(o.map(l=>l.id));n.add(s);const i=new Set,r=[];for(const l of e)!n.has(l.id)&&!i.has(l.id)&&(i.add(l.id),r.push(l));for(const l of a)!n.has(l.id)&&!i.has(l.id)&&(i.add(l.id),r.push(l));return r}function ne(s,e){return j(s.parentCustomerId)&&s.parentCustomerId!==e}const B=10,Ct=({customerChildren:s=[],customerId:e,customerName:o,childrenRelations:a=[]})=>{const[n,i]=h.useState(L(e,s,[])),[r,l]=h.useState(()=>yt(s,a)),[m,g]=h.useState(B),E=()=>{g(d=>Math.min(d+B,n.length))},{setValue:y}=re(),u=h.useRef(!0);h.useEffect(()=>{const d=bt(n,r);y("childrenRelations",d,u.current?void 0:{shouldDirty:!0}),u.current=!1},[n,r]);const c=h.useCallback(d=>{i(p=>p.some(b=>b.id===d.id)?p:[d,...p]),l(p=>new Map(p).set(d.id,S.accumulateUsage))},[]),f=h.useCallback(d=>{i(p=>p.filter(b=>b.id!==d)),l(p=>{const b=new Map(p);return b.delete(d),b})},[]),x=h.useCallback((d,p)=>{l(b=>new Map(b).set(d,p))},[]);return t.jsx(fe,{title:"Related entities",description:"Linked records and connections",action:oe(n)?t.jsx(se,{onChildSelect:c,customerId:e,childrenToExclude:n,childrenToAdd:L(e,s,[])}):void 0,children:t.jsxs(T,{sx:{gap:3},children:[n.slice(0,m).map(d=>{const p=r.get(d.id)||S.accumulateUsage;return t.jsx(ht,{customerName:o,customerChild:d,relationType:p,onDeleteChild:f,onRelationTypeChange:x},d.id)}),m<n.length&&t.jsx(T,{direction:"row",sx:{justifyContent:"center",alignItems:"center"},children:t.jsxs(R,{emphasis:"secondary",size:"small",onClick:E,startIcon:t.jsx(rt,{width:16,height:16}),children:["Show next ",Math.min(B,n.length-m)," of"," ",n.length]})}),(n==null?void 0:n.length)===0&&t.jsx(se,{onChildSelect:c,customerId:e,childrenToExclude:n,childrenToAdd:L(e,s,[])})]})})};function L(s,e,o){const a=new Set([s]),n=[];for(const i of e)a.has(i.id)||(a.add(i.id),n.push({id:i.id,name:i.name,externalId:i.externalId}));for(const i of o)a.has(i.id)||(a.add(i.id),n.push(i));return n}function yt(s,e){const o=new Map,a=new Map(e.map(n=>[n.childId,n.relationType]));return s.forEach(n=>{const i=a.get(n.id)||S.accumulateUsage;o.set(n.id,i)}),o}function bt(s,e){return s.map(o=>({id:o.id,relationType:e.get(o.id)||S.accumulateUsage}))}const Et=()=>t.jsx(Ze,{mode:"update"}),St=({customer:s})=>t.jsx(Je,{mode:"update",customer:s}),G=s=>k(s)?"":`${s}`,jt=({value:s,valueType:e,onCommit:o,onBlur:a})=>{const[n,i]=h.useState(!1),[r,l]=h.useState(()=>G(s)),m=h.useRef(null);h.useEffect(()=>{n&&m.current&&(m.current.focus(),m.current.select())},[n]);const g=()=>{if(e==="Number")if(r.trim()==="")o(null);else{const c=Number(r);if(Number.isNaN(c))return;o(c)}else o(r);i(!1),a()},E=()=>{l(G(s)),i(!1)};return{isEditing:n,draft:r,setDraft:l,inputRef:m,enterEditMode:()=>{l(G(s)),i(!0)},commitDraft:g,cancelEdit:E,handleKeyDown:c=>{c.key==="Enter"?(c.preventDefault(),g()):c.key==="Escape"&&(c.preventDefault(),E())}}},ae="--",Tt=s=>{if(k(s))return ae;const e=`${s}`;return v(e)?e:ae},It=({valueType:s,value:e,onCommit:o,onBlur:a,dataVyPrefix:n,showConfirmButtons:i})=>{const{isEditing:r,draft:l,setDraft:m,inputRef:g,enterEditMode:E,commitDraft:y,cancelEdit:u,handleKeyDown:c}=jt({value:e,valueType:s,onCommit:o,onBlur:a});return r?i?t.jsxs(ee,{sx:{display:"flex",alignItems:"center",gap:1},children:[t.jsx(J,{"data-vy":`${n}-input`,inputRef:g,value:l,type:s==="Number"?"number":"text",onChange:f=>m(f.target.value),onKeyDown:c,sx:{width:200}}),t.jsx(te,{onClick:y,size:"small",children:t.jsx(dt,{color:"success",sx:{fontSize:"20px"}})}),t.jsx(te,{onClick:u,size:"small",children:t.jsx(ct,{color:"inherit",sx:{fontSize:"20px"}})})]}):t.jsx(J,{"data-vy":`${n}-input`,inputRef:g,value:l,type:s==="Number"?"number":"text",onChange:f=>m(f.target.value),onBlur:y,onKeyDown:c,sx:{width:200}}):t.jsx(ee,{"data-vy":`${n}-display`,onClick:E,sx:{cursor:"pointer",width:"100%",height:"100%",display:"flex",alignItems:"center"},children:t.jsx(N,{variant:"body2",component:pe,children:Tt(e)})})},vt=()=>{},Rt=({value:s,valueType:e,onCommit:o,onBlur:a=vt,dataVyPrefix:n,showConfirmButtons:i=!1,allowedValues:r=[]})=>e==="Boolean"?t.jsx(ut,{"data-vy":`${n}-checkbox`,checked:s===!0,onChange:l=>o(l.target.checked),onBlur:a}):e==="Enum"?t.jsx(de,{"data-vy":`${n}-select`,options:r,getOptionLabel:l=>l,value:typeof s=="string"&&s!==""?s:null,onChange:(l,m)=>o(m??""),onBlur:a,placeholder:"None",fullWidth:!1,sx:{minWidth:120}}):t.jsx(It,{valueType:e,value:s,onCommit:o,onBlur:a,dataVyPrefix:n,showConfirmButtons:i}),wt=({index:s,valueType:e,allowedValues:o})=>{const{control:a}=re();return t.jsx(Ae,{control:a,name:`customFieldValues.${s}.value`,render:({field:n})=>t.jsx(Rt,{value:n.value,valueType:e,onCommit:n.onChange,onBlur:n.onBlur,dataVyPrefix:`customer-settings-custom-field-value-${s}`,allowedValues:o})})},z=s=>s.customFieldDefinitionId,Vt=({customFields:s})=>{const e=h.useMemo(()=>{const a=new Map;
1return s.forEach((n,i)=>{a.set(z(n),i)}),a},[s]),o=h.useMemo(()=>[{field:"source",headerName:"Source",flex:2,sortable:!1,valueGetter:(a,n)=>{var i;return((i=n.definition)==null?void 0:i.integrationSource)??"Vayu"},renderCell:a=>{var n;return t.jsx(M,{value:((n=a.row.definition)==null?void 0:n.integrationSource)??"Vayu",align:"left"})}},{field:"fieldPath",headerName:"Source field",flex:2,sortable:!1,valueGetter:(a,n)=>{var i;return((i=n.definition)==null?void 0:i.fieldPath)??"---"},renderCell:a=>{var n;return t.jsx(M,{value:(n=a.row.definition)==null?void 0:n.fieldPath,align:"left"})}},{field:"fieldName",headerName:"Vayu field",flex:3,sortable:!1,valueGetter:(a,n)=>v(n.fieldName)?n.fieldName:"---",renderCell:a=>t.jsx(M,{value:a.row.fieldName,align:"left"})},{field:"value",headerName:"Value",flex:3,sortable:!1,renderCell:a=>{var l,m,g;const n=e.get(z(a.row)),i=((l=a.row.definition)==null?void 0:l.valueType)??"String",r=(m=a.row.definition)==null?void 0:m.defaultValue;return je(n)?t.jsx(M,{value:"---",align:"left"}):t.jsxs(T,{direction:"row",sx:{alignItems:"center",gap:1},children:[t.jsx(wt,{index:n,valueType:i,allowedValues:((g=a.row.definition)==null?void 0:g.allowedValues)??[]}),r&&t.jsx(N,{variant:"caption",component:pe,sx:{color:"text.secondary"},children:`Default: ${r}`})]})}}],[e]);return t.jsx(fe,{title:"Custom fields",description:"Used for payment verification and invoices",children:t.jsx(lt,{rows:s,columns:o,getRowId:z,hideFooter:!0,autoHeight:!0})})},Ft=s=>{const{value:e}=s;if(k(e))return!1;const o=String(e).trim();return v(o)},Mt=Te.extend({contacts:xe(Ce({receiveInvoiceEmail:H(),email:V().regex(Ie,ve).optional(),name:V().optional(),title:V().optional(),phone:V().regex(Re,we).optional(),isFromDb:H()}).refine(s=>s.isFromDb?v(s.email):!0,{message:"Email is required for an existing contact",path:["email"]}).refine(q.refine,q.options))});function At(s){return s.map(({customFieldDefinitionId:e,fieldName:o,value:a})=>({customFieldDefinitionId:e,fieldName:o,value:a}))}const Dt=(s,e,o,a)=>{const n=mt(s),i=ye(),r=De({resolver:ke(Mt),defaultValues:P(e)});h.useEffect(()=>{if(j(e)){const c=(j(e.contacts)?e.contacts:[]).map(x=>({...x,isFromDb:!0})),f=Ve(c);r.reset({...P(e),contacts:[...c,...f?[{email:"",name:"",title:"",phone:"",receiveInvoiceEmail:!0,isFromDb:!1}]:[]],customFieldValues:At(a??[])})}},[e,o,a,r]);const l=async()=>{await i.invalidateQueries(le.customer(s)),r.reset(P(r.getValues()))},m=async()=>{const u=r.getValues("crmMetadata.crmId"),c=r.getValues("erpMetadata.erpId");return K(c)&&r.setValue("erpMetadata",void 0),K(u)&&r.setValue("crmMetadata",void 0),Be(r.getValues("settings.cloudProviderSettings"))&&r.setValue("settings.cloudProviderSettings",null),await r.trigger()?!0:(U("error","Please fix the errors before saving"),!1)},g=()=>{const u=r.getValues(),c=r.formState.dirtyFields,f=(e==null?void 0:e.contacts)??[],x=u.contacts??[],d=x.filter(he=>v(he.email)),p=f.length!==d.length,b=(e==null?void 0:e.aliases)??[],w=u.aliases??[],_=b.length!==w.length;let C=null;if(Me(c)||(C=Le(c,u)),p&&(C={...C,contacts:x}),_&&(C={...C,aliases:w}),Q.isNull(C))return null;const I=j(C==null?void 0:C.aliases)?{aliases:u.aliases}:{};return{...C,...I}};return{methods:r,onSubmit:async()=>{if(!await m())return;const c=g();if(!c){U("success","Customer saved");return}const{contacts:f,customFieldValues:x,externalId:d,...p}=c,b=d===""?null:d,w=f==null?void 0:f.reduce((C,I)=>(v(I.email)&&C.push({email:I.email,name:I.name,title:I.title,phone:I.phone,receiveInvoiceEmail:I.receiveInvoiceEmail}),C),[]),_=x==null?void 0:x.filter(Ft);await $e(n,{...p,externalId:b,contacts:w,customFieldValues:_},{pending:"Saving customer...",success:"Customer saved",error:"Failed to save customer"},{onSuccess:l,onError:C=>{Fe(C)&&U("error",C.message)}})},checkBackmatchTriggered:()=>{const u=r.getValues("aliases")??[],c=r.getValues("externalId")||null,f=(e==null?void 0:e.aliases)??[],x=(e==null?void 0:e.externalId)??null;return!Q.isEqual(f,u)||x!==c}}},kt=()=>t.jsx(ce,{height:700,sx:{borderRadius:`${ue.lg}px`,marginTop:1,position:"relative"}}),ie="update-customer-settings-form",Nt=()=>{const{customerId:s}=We("customerId"),{data:e}
1=He(s),{activeId:o,setActiveId:a,containerRef:n,anchorOffset:i}=et(Y),r=h.useMemo(()=>ft(e==null?void 0:e.customFieldsWithDefinitions,e==null?void 0:e.customFieldDefinitions),[e==null?void 0:e.customFieldsWithDefinitions,e==null?void 0:e.customFieldDefinitions]),{methods:l,onSubmit:m,checkBackmatchTriggered:g}=Dt(s,e==null?void 0:e.customer,e==null?void 0:e.children,r),[E,y]=h.useState(!1),u=async()=>{await m();const d=nt(l.formState.errors,o||F.companyDetails);j(d)&&a(d)},c=async d=>{if(d.preventDefault(),g()){y(!0);return}await u()},f=async()=>{y(!1),await u()},x=()=>{y(!1)};return t.jsxs(t.Fragment,{children:[t.jsx(Ne,{children:t.jsx("title",{children:"Customer settings"})}),t.jsx(me,{open:E,onClose:x,title:"Recalculate measured units?",actions:t.jsxs(t.Fragment,{children:[t.jsx(R,{emphasis:"secondary",onClick:x,children:"Cancel"}),t.jsx(R,{emphasis:"primary",onClick:f,children:"Continue"})]}),children:t.jsx(N,{variant:"body2",children:"Saving these changes will recalculate measured units for the affected customer. This may update existing usage charges. Continue?"})}),t.jsx(_e,{...l,children:t.jsxs(Ke,{id:ie,onSubmit:c,children:[t.jsx(tt,{sections:Y,activeId:o,containerRef:n,onSectionChange:a}),t.jsxs(Qe,{children:[t.jsx(T,{[$]:F.companyDetails,sx:{gap:3,scrollMarginTop:i},children:t.jsx(Et,{})}),t.jsx(A,{}),t.jsx(T,{[$]:F.configuration,sx:{gap:3,scrollMarginTop:i},children:j(e==null?void 0:e.customer)&&t.jsx(St,{customer:e.customer})}),t.jsx(A,{}),t.jsxs(T,{[$]:F.advanced,sx:{gap:3,scrollMarginTop:i},children:[t.jsx(st,{mode:"update"}),j(e==null?void 0:e.customer)&&t.jsxs(t.Fragment,{children:[t.jsx(A,{}),t.jsx(Ct,{customerId:e.customer.id,customerName:e.customer.name,customerChildren:e==null?void 0:e.children,childrenRelations:e==null?void 0:e.childrenRelations})]}),oe(r)&&t.jsxs(t.Fragment,{children:[t.jsx(A,{}),t.jsx(Vt,{customFields:r})]})]})]}),t.jsx(Xe,{children:t.jsx(Ye,{formId:ie,onCancel:()=>l.reset(),saveDataVy:D.save,cancelDataVy:D.cancel})})]})})]})},hs=Ge(ze(Nt),{suspenseProps:{fallback:t.jsx(kt,{})}});export{hs as UpdateCustomerSettings};

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.