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 cc4db40220..f241db21cc 100644 --- a/products/ASC.People/Client/src/components/Article/MainButton/index.js +++ b/products/ASC.People/Client/src/components/Article/MainButton/index.js @@ -7,12 +7,20 @@ import { DropDownItem, toastr } from "asc-web-components"; +import InviteDialog from './../../dialogs/Invite'; import { isAdmin } from '../../../store/auth/selectors'; import { withTranslation, I18nextProvider } from 'react-i18next'; import i18n from '../i18n'; import { typeUser, typeGuest, department } from './../../../helpers/customNames'; class PureArticleMainButtonContent extends React.Component { + constructor(props) { + super(props); + this.state = { + dialogVisible: false, + } + } + onDropDownItemClick = (link) => { this.props.history.push(link); }; @@ -21,48 +29,57 @@ class PureArticleMainButtonContent extends React.Component { toastr.success(text); }; + toggleDialogVisible = () => this.setState({ dialogVisible: !this.state.dialogVisible }); + render() { console.log("People ArticleMainButtonContent render"); const { isAdmin, settings, t } = this.props; return ( isAdmin ? - - + + + + + + + + + + - - - - - - - + : <> ); diff --git a/products/ASC.People/Client/src/components/dialogs/Invite/i18n.js b/products/ASC.People/Client/src/components/dialogs/Invite/i18n.js new file mode 100644 index 0000000000..5d4fb211bb --- /dev/null +++ b/products/ASC.People/Client/src/components/dialogs/Invite/i18n.js @@ -0,0 +1,57 @@ +import i18n from "i18next"; +import Backend from "i18next-xhr-backend"; +import config from "../../../../package.json"; + +const newInstance = i18n.createInstance(); + +if (process.env.NODE_ENV === "production") { + newInstance + .use(Backend) + .init({ + lng: 'en', + fallbackLng: "en", + + interpolation: { + escapeValue: false, // not needed for react as it escapes by default + format: function (value, format) { + if (format === 'lowercase') return value.toLowerCase(); + return value; + } + }, + + react: { + useSuspense: true + }, + backend: { + loadPath: `${config.homepage}/locales/Invite/{{lng}}/{{ns}}.json` + } + }); +} else if (process.env.NODE_ENV === "development") { + + const resources = { + en: { + translation: require("./locales/en/translation.json") + } + }; + + newInstance.init({ + resources: resources, + lng: 'en', + fallbackLng: "en", + debug: true, + + interpolation: { + escapeValue: false, // not needed for react as it escapes by default + format: function (value, format) { + if (format === 'lowercase') return value.toLowerCase(); + return value; + } + }, + + react: { + useSuspense: true + } + }); +} + +export default newInstance; \ No newline at end of file diff --git a/products/ASC.People/Client/src/components/dialogs/Invite/index.js b/products/ASC.People/Client/src/components/dialogs/Invite/index.js new file mode 100644 index 0000000000..aa519e0f1f --- /dev/null +++ b/products/ASC.People/Client/src/components/dialogs/Invite/index.js @@ -0,0 +1,224 @@ +import React from 'react'; +import { connect } from 'react-redux'; +import PropTypes from 'prop-types'; +import { withRouter } from 'react-router'; +import { + toastr, + ModalDialog, + Link, + Checkbox, + Button, + Textarea, + Text +} from "asc-web-components"; +import { getInvitationLink, getShortenedLink } from '../../../store/profile/actions'; +import { withTranslation, I18nextProvider } from 'react-i18next'; +import i18n from './i18n'; +import { typeGuests } from './../../../helpers/customNames'; +import styled from 'styled-components' + +const ModalDialogContainer = styled.div` + .margin-text { + margin: 12px 0; + } + + .margin-link { + margin-right: 12px; + } + + .margin-textarea { + margin-top: 12px; + } + + .flex{ + display: flex; + justify-content: space-between; + } +`; + +const textAreaName = 'link-textarea'; + +class PureInviteDialog extends React.Component { + constructor(props) { + super(props); + this.state = { + isGuest: false, + peopleInvitationLink: '', + guestInvitationLink: '', + isLoading: true, + isLinkShort: false + } + } + + onCopyLinkToClipboard = () => { + const { t } = this.props; + const link = document.getElementsByName(textAreaName)[0]; + link.select(); + document.execCommand('copy'); + 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; + + getShortenedLink(this.state.peopleInvitationLink) + .then((res) => { + // console.log("getShortInvitationLinkPeople success", res.data.response); + this.setState({ peopleInvitationLink: res.data.response }); + }) + .catch(e => { + console.error("getShortInvitationLink error", e); + this.setState({ isLoading: false }); + }); + + getShortenedLink(this.state.guestInvitationLink) + .then((res) => { + // console.log("getShortInvitationLinkGuest success", res.data.response); + this.setState({ + guestInvitationLink: res.data.response, + isLoading: false, + isLinkShort: true + }); + }) + .catch(e => { + console.error("getShortInvitationLink error", e); + }); + + }; + + componentDidUpdate(prevProps, prevState) { + if (!prevProps.visible && !prevState.peopleInvitationLink && !prevState.guestInvitationLink) { + // console.log('INVITE DIALOG DidUpdate'); + const { getInvitationLink } = this.props; + const isGuest = true; + + getInvitationLink() + .then((res) => { + // console.log("getInvitationLinkPeople success", res.data.response); + this.setState({ + peopleInvitationLink: res.data.response, + isLoading: false + }); + this.onCopyLinkToClipboard(); + }) + .catch(e => { + console.error("getInvitationLinkPeople error", e); + this.setState({ isLoading: false }); + }); + + 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 }); + }); + }; + } + + onClickToCloseButton = () => this.props.onCloseButton && this.props.onCloseButton(); + + render() { + console.log("InviteDialog render"); + const { t, visible, onClose } = this.props; + const fakeSettings = { hasShortenService: false }; + + return ( + + onClose && onClose()} + + headerContent={t('InviteLinkTitle')} + + bodyContent={( + <> + + {t('HelpAnswerLinkInviteSettings')} + + + {t('InviteLinkValidInterval', { count: 7 })} + +
+
+ + {t('CopyToClipboard')} + + { + fakeSettings.hasShortenService && !this.state.isLinkShort && + + {t('GetShortenLink')} + + } +
+ +
+