Liferay.Loader.define("commerce-organization-web@5.0.37/js/modals/InviteUsersModal",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/icon","@frontend-taglib-clay$clayui/modal","@frontend-taglib-clay$clayui/multi-select","liferay!frontend-js-react-web$classnames","frontend-js-web","liferay!frontend-js-react-web$react","../ChartContext","../data/users"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function({closeModal:e,observer:t,parentData:a}){const[m,y]=(0,s.useState)(""),[p,g]=(0,s.useState)([]),{chartInstanceRef:O}=(0,s.useContext)(f.default),[E,h]=(0,s.useState)([]),[j,v]=(0,s.useState)([]),[w,L]=(0,s.useState)([]);return(0,s.useEffect)((()=>{if(a){("organization"===a.type?(0,d.getOrganizationRoles)():(0,d.getAccountRoles)(a.id)).then(v)}}),[a]),s.default.createElement(u.default,{center:!0,observer:t,size:"md"},s.default.createElement(u.default.Header,null,Liferay.Language.get("invite-users")),s.default.createElement(u.default.Body,null,s.default.createElement(n.default.Group,{className:(0,c.default)(!!w.length&&"has-error")},s.default.createElement("label",{htmlFor:"inviteUsersEmailInput"},Liferay.Language.get("emails"),s.default.createElement(l.default,{className:"ml-1 reference-mark",symbol:"asterisk"})),s.default.createElement(n.ClayInput.Group,null,s.default.createElement(n.ClayInput.GroupItem,null,s.default.createElement(o.default,{id:"inviteUsersEmailInput",items:p,locator:{label:"emailAddress",value:"emailAddress"},onChange:y,onItemsChange:g,placeholder:Liferay.Language.get("users-emails"),value:m})))),s.default.createElement(n.default.Group,{className:(0,c.default)(!!w.length&&"has-error")},s.default.createElement("label",{htmlFor:"inviteUsersRoleInput"},Liferay.Language.get("roles"),s.default.createElement(l.default,{className:"ml-1 reference-mark",symbol:"asterisk"})),s.default.createElement(n.ClaySelectBox,{id:"inviteUsersRoleInput",items:j.map((e=>({label:e.name,value:e.id}))),multiple:!0,onSelectChange:h,size:5,value:E}),s.default.createElement(n.ClayInput.Group,null,s.default.createElement(n.ClayInput.GroupItem,null,!!w.length&&s.default.createElement(n.default.FeedbackGroup,null,w.map(((e,t)=>s.default.createElement(n.default.FeedbackItem,{key:t},s.default.createElement(n.default.FeedbackIndicator,{symbol:"info-circle"}),e)))))))),s.default.createElement(u.default.Footer,{last:s.default.createElement(r.default.Group,{spaced:!0},s.default.createElement(r.default,{displayType:"secondary",onClick:e},Liferay.Language.get("cancel")),s.default.createElement(r.default,{displayType:"primary",onClick:function(){const t=p.map((e=>e.emailAddress)).sort();m&&t.push(m);("organization"===a.type?d.addUserEmailsToOrganization:d.addUserEmailsToAccount)(a.id,E.join(","),t).then((t=>{const r=1===t.length?(0,i.sub)(Liferay.Language.get("1-user-was-added-to-x"),a.name):(0,i.sub)(Liferay.Language.get("x-users-were-added-to-x"),t.length,a.name);(0,i.openToast)({message:r,type:"success"}),O.current.addNodes(t,"user",a),O.current.updateNodeContent(b(b({},a),{},{numberOfUsers:a.numberOfUsers+t.length})),e()})).catch((e=>{L([e.title])}))}},Liferay.Language.get("save")))}))};var r=p(a("@frontend-taglib-clay$clayui/button")),n=y(a("@frontend-taglib-clay$clayui/form")),l=p(a("@frontend-taglib-clay$clayui/icon")),u=p(a("@frontend-taglib-clay$clayui/modal")),o=p(a("@frontend-taglib-clay$clayui/multi-select")),c=p(a("liferay!frontend-js-react-web$classnames")),i=a("frontend-js-web"),s=y(a("liferay!frontend-js-react-web$react")),f=p(a("../ChartContext")),d=a("../data/users");function m(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return m=function(){return e},e}function y(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=m();if(t&&t.has(e))return t.get(e);var a={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var l=r?Object.getOwnPropertyDescriptor(e,n):null;l&&(l.get||l.set)?Object.defineProperty(a,n,l):a[n]=e[n]}return a.default=e,t&&t.set(e,a),a}function p(e){return e&&e.__esModule?e:{default:e}}function g(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function b(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?g(Object(a),!0).forEach((function(t){O(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):g(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function O(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}}}));
//# sourceMappingURL=InviteUsersModal.js.map