(window.webpackJsonpPlesk=window.webpackJsonpPlesk||[]).push([["app/login/recovery-password"],{1058:function(e,t,s){"use strict";s.r(t);var n=s(154),r=s.n(n),i=s(156),a=s(155),o=s(145),c=s(1059);t.default=({renderTo:e,...t})=>{const s=o.Locale.getSection("components.login.recovery-password").messages;Object(a.render)(Object(a.createElement)(i.LocaleProvider,{messages:s},Object(a.createElement)(c.default,r()({messages:s},t))),document.getElementById(e))}},1059:function(e,t,s){"use strict";s.r(t);var n=s(149),r=s.n(n),i=s(156),a=s(155),o=s(276),c=s.n(o),l=s(145);class p extends a.Component{constructor(e){if(super(e),r()(this,"state",{recoveryLink:"",recoveryEmail:"",isActionInProgress:!1,isDialogOpen:!1,sendButtonState:"active"}),r()(this,"recoveryLinkContainer",Object(a.createRef)()),r()(this,"setLinkSelection",()=>{setTimeout(()=>{try{const e=document.createRange();e.selectNode(this.recoveryLinkContainer.current);const t=window.getSelection();t.removeAllRanges(),t.addRange(e)}catch(e){}},200)}),r()(this,"handleAction",()=>{if(this.state.isActionInProgress)return;if(this.state.recoveryLink)return this.setState({isDialogOpen:!0}),void this.setLinkSelection();this.setState({isActionInProgress:!0});const{userType:e,userId:t}=this.props;l.api.post(Object(l.prepareUrl)("".concat(this.endpoint,"/generate-secret")),{userType:e,userId:t}).then(e=>{"success"===e.status?(this.setState({recoveryLink:e.link,recoveryEmail:e.email,isActionInProgress:!1,isDialogOpen:!0}),this.setLinkSelection()):location.reload()})}),r()(this,"handleSend",()=>{if("active"!==this.state.sendButtonState)return;this.setState({sendButtonState:"loading"});const{messages:e}=this.props,{userType:t,userId:s}=this.props;l.api.post(Object(l.prepareUrl)("".concat(this.endpoint,"/send-secret")),{userType:t,userId:s,secret:this.state.recoveryLink}).then(t=>{"success"===t.status?(this.setState({isDialogOpen:!1}),Object(l.clearStatusMessages)(),Object(l.addStatusMessage)("info",e.linkSendedMessage),this.setState({sendButtonState:"active",recoveryLink:null})):location.reload()})}),r()(this,"handleClose",()=>{this.setState({isDialogOpen:!1,recoveryLink:null})}),2===this.props.userType)this.endpoint="/admin/reseller";else if(4===this.props.userType)this.endpoint="/admin/customer";else if(8===this.props.userType)this.endpoint="/smb/user";else{if(32!==this.props.userType)throw new Error("Unexpected user type.");this.endpoint="/smb/email-address"}}render(){return Object(a.createElement)(a.Fragment,null,Object(a.createElement)(i.Action,{onClick:this.handleAction,progress:this.state.isActionInProgress},Object(a.createElement)(i.Translate,{content:"action"})),Object(a.createElement)(i.Dialog,{isOpen:this.state.isDialogOpen,buttons:[this.state.recoveryEmail?Object(a.createElement)(i.Button,{key:"sendButton",intent:"primary",onClick:this.handleSend,state:this.state.sendButtonState},Object(a.createElement)(i.Translate,{content:"sendButton"})):null],title:Object(a.createElement)(i.Translate,{content:"title"}),cancelTitle:Object(a.createElement)(i.Translate,{content:"closeButton"}),onClose:this.handleClose},this.state.recoveryEmail?Object(a.createElement)(i.Paragraph,null,Object(a.createElement)(i.Translate,{content:"text",params:{email:Object(a.createElement)(i.Text,{bold:!0},this.state.recoveryEmail)}})):null,Object(a.createElement)(i.Alert,null,Object(a.createElement)("span",{ref:this.recoveryLinkContainer},this.state.recoveryLink))))}}p.propTypes={messages:c.a.object.isRequired,userType:c.a.number.isRequired,userId:c.a.number.isRequired},t.default=p}}]);
//# sourceMappingURL=recovery-password.js.map?f7afc0e3b216dda4b79b