diff --git a/products/ASC.People/Client/src/components/Article/MainButton/index.js b/products/ASC.People/Client/src/components/Article/MainButton/index.js index 542c95eb0d..106d4efce3 100644 --- a/products/ASC.People/Client/src/components/Article/MainButton/index.js +++ b/products/ASC.People/Client/src/components/Article/MainButton/index.js @@ -17,8 +17,7 @@ class PureArticleMainButtonContent extends React.Component { constructor(props) { super(props); this.state = { - dialogVisible: false, - clicked: false + dialogVisible: false } } @@ -30,14 +29,8 @@ class PureArticleMainButtonContent extends React.Component { toastr.success(text); }; - toggleDialogVisible = () => { - this.setState({ dialogVisible: !this.state.dialogVisible }, function () { - this.state.dialogVisible && this.clickChild(); - }); - } + onInvitationDialogClick = () => this.setState({ dialogVisible: !this.state.dialogVisible }); - onSetInviteDialogClick = click => this.clickChild = click; - onMainButtonClick = () => this.setState({ clicked: true }); render() { console.log("People ArticleMainButtonContent render"); const { isAdmin, settings, t } = this.props; @@ -48,7 +41,6 @@ class PureArticleMainButtonContent extends React.Component { isDisabled={false} isDropdown={true} text={t('Actions')} - onClick={this.onMainButtonClick} > - {this.state.clicked && - } : <> diff --git a/products/ASC.People/Client/src/components/dialogs/Invite/index.js b/products/ASC.People/Client/src/components/dialogs/Invite/index.js index 9785995e8d..150426f56d 100644 --- a/products/ASC.People/Client/src/components/dialogs/Invite/index.js +++ b/products/ASC.People/Client/src/components/dialogs/Invite/index.js @@ -16,6 +16,7 @@ import { withTranslation, I18nextProvider } from 'react-i18next'; import i18n from './i18n'; import { typeGuests } from './../../../helpers/customNames'; import styled from 'styled-components' +import copy from 'copy-to-clipboard'; const ModalDialogContainer = styled.div` .margin-text { @@ -43,41 +44,38 @@ class PureInviteDialog extends React.Component { super(props); this.state = { isGuest: false, - peopleInvitationLink: '', - guestInvitationLink: '', - isLoading: true, - isLinkShort: false + userInvitationLink: this.props.userInvitationLink, + guestInvitationLink: this.props.guestInvitationLink, + isLoading: false, + isLinkShort: false, + visible: false } } onCopyLinkToClipboard = () => { // console.log("COPY"); const { t } = this.props; - const link = document.getElementsByName(textAreaName)[0]; - link.select(); - document.execCommand('copy'); + copy(this.state.isGuest ? this.state.guestInvitationLink : this.state.userInvitationLink); toastr.success(t('LinkCopySuccess')); - window.getSelection().removeAllRanges(); - link.blur(); }; onCheckedGuest = () => this.setState({ isGuest: !this.state.isGuest }); onGetShortenedLink = () => { this.setState({ isLoading: true }); - const { getShortenedLink } = this.props; + const { getShortenedLink, userInvitationLink, guestInvitationLink } = this.props; - getShortenedLink(this.state.peopleInvitationLink) + getShortenedLink(userInvitationLink) .then((res) => { - // console.log("getShortInvitationLinkPeople success", res.data.response); - this.setState({ peopleInvitationLink: res.data.response }); + // console.log("getShortInvitationLinkuser success", res.data.response); + this.setState({ userInvitationLink: res.data.response }); }) .catch(e => { console.error("getShortInvitationLink error", e); this.setState({ isLoading: false }); }); - getShortenedLink(this.state.guestInvitationLink) + getShortenedLink(guestInvitationLink) .then((res) => { // console.log("getShortInvitationLinkGuest success", res.data.response); this.setState({ @@ -92,53 +90,25 @@ class PureInviteDialog extends React.Component { }; - componentDidUpdate() { - if (this.props.visible && this.state.peopleInvitationLink && !this.state.guestInvitationLink) { - // console.log('INVITE DIALOG DidUpdate'); - const { getInvitationLink } = this.props; - const isGuest = true; - - getInvitationLink(isGuest) - .then((res) => { - // console.log("getInvitationLinkGuest success", res.data.response); - this.setState({ guestInvitationLink: res.data.response }); - }) - .catch(e => { - console.error("getInvitationLinkGuest error", e); - this.setState({ isLoading: false }); - }); - }; - } - - componentDidMount() { - this.props.setClick(this.onCopyLinkToClipboard); - const { getInvitationLink } = this.props; - getInvitationLink() - .then((res) => { - console.log("getInvitationLinkPeople success", res.data.response); - this.setState({ - peopleInvitationLink: res.data.response, - isLoading: false - }); - }) - .catch(e => { - console.error("getInvitationLinkPeople error", e); - this.setState({ isLoading: false }); - }); + componentDidUpdate(prevProps) { + console.log('invitelink did UPDATE') + if (this.props.visible && !prevProps.visible) { + this.onCopyLinkToClipboard(); + } } onClickToCloseButton = () => this.props.onCloseButton && this.props.onCloseButton(); + onClose = () => this.props.onClose && this.props.onClose(); render() { console.log("InviteDialog render"); - const { t, visible, onClose } = this.props; - const fakeSettings = { hasShortenService: false }; + const { t, visible, settings } = this.props; return ( onClose && onClose()} + onClose={this.onClose} headerContent={t('InviteLinkTitle')} @@ -165,7 +135,7 @@ class PureInviteDialog extends React.Component { {t('CopyToClipboard')} { - fakeSettings.hasShortenService && !this.state.isLinkShort && + settings && !this.state.isLinkShort &&