<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">"use strict";(self.__LOADABLE_LOADED_CHUNKS__=self.__LOADABLE_LOADED_CHUNKS__||[]).push([[4137],{76909:function(e,t,n){n.r(t),n.d(t,{default:function(){return j}});var o=n(4942),a=n(1413),r=n(29439),c=n(12611),i=n(87363),s=n(24839),l=n(45987),u=n(83742),d=n(29173),x=n(56552),h=["children","provider","onSuccess","onError"],_=function(e){var t=e.children,n=e.provider,o=e.onSuccess,r=void 0===o?c.identity:o,i=e.onError,_=void 0===i?c.identity:i,m=(0,l.Z)(e,h);return(0,x.jsx)(s.Button,(0,a.Z)((0,a.Z)({"data-test-name":"OAuth2Button",size:"small",onClick:function(){(function(e,t){var n="oauth2-provider/".concat(e);return(0,u.t_)("GET",n,{}).then((function(e){var o,a=e.json;if(a.error)throw new Error(a.error);if(a.authorization_url)var r=d.u9.screen,i=r.height,s=r.width,l=(0,c.min)([s,800]),u=(0,c.min)([i,800]),x=(i-u)/2,h=(s-l)/2,_=d.u9.open(a.authorization_url,"OAuth2 Popup",(o={width:l,height:u,top:x,left:h},(0,c.map)(o,(function(e,t){return"".concat(t,"=").concat(e)})).join(","))),m=setInterval((function(){if(!_||_.closed)clearInterval(m);else try{_.location.pathname==="/v1/".concat(n)&amp;&amp;(clearInterval(m),_.close(),t())}catch(e){if("SecurityError"!==e.name)throw e}}),500);else t()})).catch((function(e){throw e instanceof Error?e:new Error((0,c.get)(e,"json.error",JSON.stringify(e)))}))})(n,r).catch((function(e){console.log(e),_(e)}))}},m),{},{children:t||"Connect to ".concat((0,c.capitalize)(n))}))},m=n(73193),f=function(){var e=(0,i.useState)([]),t=(0,r.Z)(e,2),n=t[0],s=t[1],l=(0,i.useState)({}),d=(0,r.Z)(l,2),h=d[0],_=d[1];return(0,i.useEffect)((function(){(0,u.t_)("GET","line-item-type",{}).then((function(e){var t=e.json;_((0,c.keyBy)((0,c.filter)((0,c.map)(t.line_item_types,"xero_account")),"xero_account_id"))})),(0,u.t_)("POST","xero",{action:"get_accounts"}).then((function(e){var t=e.json;s(t.accounts)}))}),[]),(0,x.jsxs)("table",{"data-test-name":"XeroAccountsTable",children:[(0,x.jsx)("thead",{children:(0,x.jsxs)("tr",{children:[(0,x.jsx)("th",{children:"Line item type"}),(0,x.jsx)("th",{children:"Xero Account Code"})]})}),(0,x.jsx)("tbody",{children:(0,c.map)(h,(function(e,t){var r=e.line_item_type_label,i=e.xero_account_code;return(0,x.jsxs)("tr",{"data-test-name":"XeroAccountsTable",children:[(0,x.jsx)("td",{children:(0,x.jsx)("input",{name:"line_item_type_label",disabled:"disabled",type:"text",value:r})}),(0,x.jsxs)("td",{className:"xero-account-code",children:[(0,x.jsx)("input",{name:"xero_account_id",type:"hidden",value:t}),(0,x.jsxs)("select",{name:"xero_account_code","data-placeholder":"Select an Account",value:i,onChange:function(e){(0,u.t_)("PUT","xero-account/".concat(t),{xero_account_code:e.target.value}).then((function(e){var t=e.json,n=(0,c.get)(t,"xero_account");_((0,a.Z)((0,a.Z)({},h),{},(0,o.Z)({},(0,c.get)(n,"xero_account_id"),n)))}))},children:[(0,x.jsx)("option",{}),(0,c.map)(n,(function(e,t){var n=e.Code,o=e.Name;return(0,x.jsxs)("option",{"data-test-name":"XeroAccountsTable",value:n,children:[n," - ",o]},t)}))]})]})]},t)}))})]})},p=function(){var e=(0,i.useState)({}),t=(0,r.Z)(e,2),n=t[0],l=t[1];return(0,i.useEffect)((function(){Promise.all([(0,u.t_)("POST","xero",{action:"get_tax_rates"}),(0,u.t_)("GET","xero-tax",{})]).then((function(e){var t=(0,r.Z)(e,2),n=t[0],o=t[1],a=(0,c.keyBy)((0,c.get)(n,"json.tax_rates"),"TaxType"),i=o.json.xero_taxes,s=(0,c.pick)((0,c.keyBy)(i,"xero_tax_type"),(0,c.keys)(a));(0,c.map)(s,(function(e,t){e.xero_tax_label=(0,c.get)(a,[t,"Name"]),e.tax_ids||(e.tax_ids=[])})),l(s)}))}),[]),(0,x.jsxs)("table",{"data-test-name":"XeroTaxesTable",children:[(0,x.jsx)("thead",{children:(0,x.jsxs)("tr",{children:[(0,x.jsx)("th",{children:"Xero Tax Rate Name"}),(0,x.jsx)("th",{children:"commonsku Tax Codes"})]})}),(0,x.jsx)("tbody",{children:(0,c.map)(n,(function(e,t){var r=e.xero_tax_id,i=e.xero_tax_type,d=e.xero_tax_label,h=e.tax_ids,_=(0,c.map)(window.TAX_CODES,(function(e){return{value:e.tax_id,label:e.label}}));return(0,x.jsxs)("tr",{"data-test-name":"XeroTaxesTable",children:[(0,x.jsx)("td",{className:"xero-tax",children:(0,x.jsx)("input",{name:"xero_tax_label",type:"text",disabled:"disabled",value:d})}),(0,x.jsx)("td",{className:"commonsku-tax-codes",style:{minWidth:400},children:(0,x.jsx)(s.Select,{isMulti:!0,placeholder:"Select some commonsku Tax Codes",value:(0,c.filter)(_,(function(e){var t=e.value;return h.indexOf(t)&gt;-1})),options:_,onChange:function(e){var t={xero_tax_type:i,tax_ids:(0,c.map)(e,"value")};(r?(0,u.t_)("PUT","xero-tax/".concat(r),t):(0,u.t_)("POST","xero-tax",t)).then((function(e){var t=e.json,r=(0,c.get)(t,"xero_tax");l((0,a.Z)((0,a.Z)({},n),{},(0,o.Z)({},(0,c.get)(r,"xero_tax_type",""),r)))}))}})})]},t)}))})]})},j=function(){var e=(0,i.useState)("loading"),t=(0,r.Z)(e,2),n=t[0],o=t[1];return(0,i.useEffect)((function(){(0,u.t_)("POST","xero",{action:"get_connections"}).then((function(e){var t=e.json;o((0,c.isEmpty)(t.connections)?"disconnected":"connected")}))}),[]),(0,x.jsx)("div",{"data-test-name":"XeroAdmin",className:"expandable",children:"loading"===n?(0,x.jsx)(m.Z,{}):"disconnected"===n?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(s.LightIndicator,{name:"Not connected",on:!1}),(0,x.jsx)("p",{children:"By authorizing commonsku, you'll create a session that will let us integrate some of our features with Xero. You will be able to disconnect your account whenever you want to. After completing the authorization process, we'll display your Xero Tax Rates and Accounts here."}),(0,x.jsxs)("p",{children:["For further information, check out "," ",(0,x.jsx)("a",{href:"https://help.commonsku.com/knowledge/connect-to-xero",target:"_blank",rel:"noreferrer",children:"our support article"}),"."]}),(0,x.jsx)("br",{}),(0,x.jsx)(_,{provider:"xero",onSuccess:function(){o("connected")}})]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(s.LightIndicator,{name:"Connected to Xero",on:!0}),(0,x.jsx)(s.Button,{size:"small",onClick:function(){(0,u.t_)("POST","xero",{action:"disconnect"}).then((function(){o("disconnected")}))},children:"Disconnect from Xero"}),(0,x.jsx)(f,{}),(0,x.jsx)(p,{})]})})}}}]);
//# sourceMappingURL=components-XeroAdmin.9e1a21a6.chunk.js.map</pre></body></html>