diff --git a/frontend/src/Editor/Editor.jsx b/frontend/src/Editor/Editor.jsx index 117cbb5914..636a17c91b 100644 --- a/frontend/src/Editor/Editor.jsx +++ b/frontend/src/Editor/Editor.jsx @@ -40,14 +40,12 @@ import RunjsIcon from './Icons/runjs.svg'; import EditIcon from './Icons/edit.svg'; import MobileSelectedIcon from './Icons/mobile-selected.svg'; import DesktopSelectedIcon from './Icons/desktop-selected.svg'; -import Modal from 'react-bootstrap/Modal'; -import Button from 'react-bootstrap/Button'; import { AppVersionsManager } from './AppVersionsManager'; import { SearchBoxComponent } from '@/_ui/Search'; -import { initEditorWalkThrough } from '@/_helpers/createWalkThrough'; import { createWebsocketConnection } from '@/_helpers/websocketConnection'; import Tooltip from 'react-bootstrap/Tooltip'; import OverlayTrigger from 'react-bootstrap/OverlayTrigger'; +import InitVersionCreateModal from './InitVersionCreateModal'; setAutoFreeze(false); enablePatches(); @@ -121,8 +119,6 @@ class Editor extends React.Component { showHiddenOptionsForDataQueryId: null, showQueryConfirmation: false, showInitVersionCreateModal: false, - isCreatingInitVersion: false, - initVersionName: 'v1', isSavingEditingVersion: false, showSaveDetail: false, hasAppDefinitionChanged: false, @@ -786,38 +782,6 @@ class Editor extends React.Component { ); }; - handleKeyPress = (event) => { - if (event.key === 'Enter') { - // eslint-disable-next-line no-undef - this.createInitVersion(); - } - }; - - createInitVersion = () => { - const newVersionName = this.state.initVersionName; - const appId = this.state.appId; - - if (!isEmpty(newVersionName?.trim())) { - this.setState({ isCreatingInitVersion: true }); - appVersionService.create(appId, newVersionName).then(() => { - this.setState( - { - showInitVersionCreateModal: false, - isCreatingInitVersion: false, - }, - () => { - initEditorWalkThrough(); - } - ); - toast.success('Version Created'); - this.fetchApp(); - }); - } else { - toast.error('The name of version should not be empty'); - this.setState({ isCreatingInitVersion: false }); - } - }; - saveEditingVersion = () => { if (this.isVersionReleased()) { this.setState({ showCreateVersionModalPrompt: true }); @@ -837,54 +801,6 @@ class Editor extends React.Component { } }; - renderInitVersionCreateModal = (showModal) => { - return ( - - - Create Version - - -
-
- this.setState({ initVersionName: e.target.value })} - onKeyPress={(e) => this.handleKeyPress(e)} - autoFocus={true} - /> -
-
- -
-
- Create a version to start building your app -
-
-
- - - -
- ); - }; - handleOnComponentOptionChanged = (component, optionName, value) => { return onComponentOptionChanged(this, component, optionName, value); }; @@ -939,7 +855,6 @@ class Editor extends React.Component { app, showQueryConfirmation, queryPaneHeight, - // showQueryEditor, showLeftSidebar, currentState, isLoading, @@ -954,7 +869,6 @@ class Editor extends React.Component { defaultComponentStateComputed, showComments, editingVersion, - showInitVersionCreateModal, isSavingEditingVersion, showSaveDetail, showCreateVersionModalPrompt, @@ -1359,7 +1273,13 @@ class Editor extends React.Component { /> )} - {this.renderInitVersionCreateModal(showInitVersionCreateModal)} + this.setState({ showInitVersionCreateModal: false })} + fetchApp={this.fetchApp} + darkMode={this.props.darkMode} + appId={this.state.appId} + /> ); diff --git a/frontend/src/Editor/InitVersionCreateModal.jsx b/frontend/src/Editor/InitVersionCreateModal.jsx new file mode 100644 index 0000000000..8d149a3a24 --- /dev/null +++ b/frontend/src/Editor/InitVersionCreateModal.jsx @@ -0,0 +1,81 @@ +import React from 'react'; +import cx from 'classnames'; +// eslint-disable-next-line import/no-named-as-default +import toast from 'react-hot-toast'; +import Modal from 'react-bootstrap/Modal'; +import Button from 'react-bootstrap/Button'; +import { isEmpty } from 'lodash'; +import { appVersionService } from '@/_services'; +import { initEditorWalkThrough } from '@/_helpers/createWalkThrough'; + +const InitVersionCreateModal = ({ appId, showModal, hideModal, fetchApp, darkMode }) => { + const [initVersionName, setInitVersionName] = React.useState('v1'); + const [isCreatingInitVersion, setIsCreatingInitVersion] = React.useState(false); + + const handleKeyPress = (event) => { + if (event.key === 'Enter') { + // eslint-disable-next-line no-undef + createInitVersion(); + } + }; + + const createInitVersion = async () => { + if (!isEmpty(initVersionName?.trim())) { + setIsCreatingInitVersion(true); + await appVersionService.create(appId, initVersionName); + setIsCreatingInitVersion(false); + initEditorWalkThrough(); + fetchApp(); + hideModal(); + toast.success('Version Created'); + } else { + setIsCreatingInitVersion(false); + toast.error('The name of version should not be empty'); + } + }; + + return ( + + + Create Version + + +
+
+ setInitVersionName(e.target.value)} + onKeyPress={(e) => handleKeyPress(e)} + autoFocus={true} + /> +
+
+ +
+
+ Create a version to start building your app +
+
+
+ + + +
+ ); +}; + +export default InitVersionCreateModal;