diff --git a/frontend/src/AppBuilder/Header/RightTopHeaderButtons/ManageAppUsers copy.jsx b/frontend/src/AppBuilder/Header/RightTopHeaderButtons/ManageAppUsers copy.jsx deleted file mode 100644 index 89f5e90352..0000000000 --- a/frontend/src/AppBuilder/Header/RightTopHeaderButtons/ManageAppUsers copy.jsx +++ /dev/null @@ -1,416 +0,0 @@ -import React from 'react'; -import { appService, appsService, authenticationService } from '@/_services'; -import Modal from 'react-bootstrap/Modal'; -import { toast } from 'react-hot-toast'; -import { CopyToClipboard } from 'react-copy-to-clipboard'; -import _, { debounce } from 'lodash'; -import { validateName } from '@/_helpers/utils'; -import { withTranslation } from 'react-i18next'; -import { Link } from 'react-router-dom'; -import { getPrivateRoute, replaceEditorURL, getHostURL } from '@/_helpers/routes'; -import { ToolTip } from '@/_components/ToolTip'; -import SolidIcon from '@/_ui/Icon/SolidIcons'; -import cx from 'classnames'; -import { TOOLTIP_MESSAGES } from '@/_helpers/constants'; -import { useAppDataStore } from '@/_stores/appDataStore'; -import { retrieveWhiteLabelText } from '@white-label/whiteLabelling'; -import useStore from '@/AppBuilder/_stores/store'; - -class ManageAppUsersComponent extends React.Component { - constructor(props) { - super(props); - this.isUserAdmin = authenticationService.currentSessionValue?.admin; - this.whiteLabelText = retrieveWhiteLabelText(); - - this.state = { - showModal: false, - appId: null, - isSlugVerificationInProgress: false, - addingUser: false, - newUser: {}, - newSlug: { - value: null, - error: '', - }, - isSlugUpdated: false, - }; - } - - /* - Only will fail for existed apps before the app/workspace url revamp which has - special chars or spaces in their app slugs - */ - validateThePreExistingSlugs = () => { - const existedSlugErrors = validateName(this.props.slug, 'App slug', true, false, false, false); - this.setState({ - newSlug: { - value: this.props.slug, - error: existedSlugErrors.errorMsg, - }, - }); - }; - - componentDidMount() { - const appId = this.props.appId; - this.setState({ appId }); - } - - hideModal = () => { - this.setState({ - showModal: false, - newSlug: { - value: this.props.slug, - error: '', - }, - isSlugVerificationInProgress: false, - isSlugUpdated: false, - }); - }; - - addUser = () => { - this.setState({ - addingUser: true, - }); - - const { organizationUserId, role } = this.state.newUser; - - appService - .createAppUser(this.state.appId, organizationUserId, role) - .then(() => { - this.setState({ addingUser: false, newUser: {} }); - toast.success('Added user successfully'); - }) - .catch(({ error }) => { - this.setState({ addingUser: false }); - toast.error(error); - }); - }; - - toggleAppVisibility = () => { - const newState = !this.props.isPublic; - this.setState({ - ischangingVisibility: true, - }); - useStore.getState().setIsPublic(newState); - - // eslint-disable-next-line no-unused-vars - appsService - .setVisibility(this.state.appId, newState) - .then(() => { - this.setState({ - ischangingVisibility: false, - }); - - if (newState) { - toast('Application is now public.'); - } else { - toast('Application visibility set to private'); - } - }) - .catch((error) => { - this.setState({ - ischangingVisibility: false, - }); - toast.error(error); - }); - }; - - delayedSlugChange = debounce((e) => { - this.handleInputChange(e.target.value, 'slug'); - }, 500); - - handleInputChange = (value, field) => { - this.setState({ - newSlug: { - value: this.state.newSlug?.value, - error: '', - isSlugUpdated: false, - }, - }); - - const error = validateName(value, `App ${field}`, true, false, !(field === 'slug'), !(field === 'slug')); - - if (!_.isEmpty(value) && value !== this.props.slug && _.isEmpty(error.errorMsg)) { - this.setState({ - isSlugVerificationInProgress: true, - }); - appsService - .setSlug(this.state.appId, value) - .then(() => { - this.setState({ - newSlug: { - value: value, - error: '', - }, - isSlugVerificationInProgress: false, - isSlugUpdated: true, - }); - - replaceEditorURL(value, this.props.pageHandle); - useStore.getState().setSlug(value); - }) - .catch(({ error }) => { - this.setState({ - newSlug: { - value, - error, - }, - isSlugVerificationInProgress: false, - isSlugUpdated: false, - }); - }); - } else { - this.setState({ - newSlug: { - value, - error: error?.errorMsg, - }, - isSlugVerificationInProgress: false, - isSlugUpdated: false, - }); - } - }; - - render() { - const { appId, isSlugVerificationInProgress, newSlug, isSlugUpdated } = this.state; - - const appLink = `${getHostURL()}/applications/`; - const shareableLink = appLink + (this.props.slug || appId); - const slugButtonClass = !_.isEmpty(newSlug.error) ? 'is-invalid' : 'is-valid'; - const embeddableLink = ``; - - const shouldShowShareModal = this.props.isVersionReleased - ? this.props.multiEnvironmentEnabled - ? this.props.currentEnvironment?.isDefault - ? true - : false - : this.props.currentEnvironment?.priority === 1 - : false; - - const envTooltipFlag = - (!this.props.isVersionReleased && this.props.currentEnvironment?.isDefault) || - (!this.props.multiEnvironmentEnabled && this.props.currentEnvironment?.priority === 1); - - return ( - -
- { - this.validateThePreExistingSlugs(); - shouldShowShareModal && this.setState({ showModal: true }); - }} - > - - - - - {this.props.t('editor.share', 'Share')} - - - - - - { - - } - - - - {this.isUserAdmin && ( - - Manage users - - )} - - -
-
- ); - } -} - -export const ManageAppUsers = withTranslation()(ManageAppUsersComponent);