[MM-39491] Force Add Server modal to stay until server has been added (#1869)
* [MM-39491] Force Add Server modal to stay until server has been added * Make the parameter optional * Actually do the logic, add a test for the logic * Add remove event listener
This commit is contained in:
@@ -10,7 +10,7 @@ import {TeamWithIndex} from 'types/config';
|
||||
import urlUtils from 'common/utils/url';
|
||||
|
||||
type Props = {
|
||||
onClose: () => void;
|
||||
onClose?: () => void;
|
||||
onSave?: (team: TeamWithIndex) => void;
|
||||
team?: TeamWithIndex;
|
||||
editMode?: boolean;
|
||||
@@ -175,7 +175,7 @@ export default class NewTeamModal extends React.PureComponent<Props, State> {
|
||||
e.stopPropagation();
|
||||
break;
|
||||
case 'Escape':
|
||||
this.props.onClose();
|
||||
this.props.onClose?.();
|
||||
break;
|
||||
}
|
||||
}}
|
||||
@@ -237,17 +237,25 @@ export default class NewTeamModal extends React.PureComponent<Props, State> {
|
||||
{this.getError()}
|
||||
</div>
|
||||
|
||||
<Button
|
||||
id='cancelNewServerModal'
|
||||
onClick={this.props.onClose}
|
||||
variant='link'
|
||||
>{'Cancel'}</Button>
|
||||
<Button
|
||||
id='saveNewServerModal'
|
||||
onClick={this.save}
|
||||
disabled={!this.validateForm()}
|
||||
variant='primary'
|
||||
>{this.getSaveButtonLabel()}</Button>
|
||||
{this.props.onClose &&
|
||||
<Button
|
||||
id='cancelNewServerModal'
|
||||
onClick={this.props.onClose}
|
||||
variant='link'
|
||||
>
|
||||
{'Cancel'}
|
||||
</Button>
|
||||
}
|
||||
{this.props.onSave &&
|
||||
<Button
|
||||
id='saveNewServerModal'
|
||||
onClick={this.save}
|
||||
disabled={!this.validateForm()}
|
||||
variant='primary'
|
||||
>
|
||||
{this.getSaveButtonLabel()}
|
||||
</Button>
|
||||
}
|
||||
</Modal.Footer>
|
||||
|
||||
</Modal>
|
||||
|
@@ -4,12 +4,13 @@
|
||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||
import 'renderer/css/modals.css';
|
||||
|
||||
import React from 'react';
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
import {TeamWithIndex} from 'types/config';
|
||||
import {ModalMessage} from 'types/modals';
|
||||
|
||||
import {MODAL_CANCEL, MODAL_RESULT} from 'common/communication';
|
||||
import {GET_MODAL_UNCLOSEABLE, MODAL_CANCEL, MODAL_RESULT, MODAL_UNCLOSEABLE} from 'common/communication';
|
||||
|
||||
import NewTeamModal from '../../components/NewTeamModal'; //'./addServer.jsx';
|
||||
|
||||
@@ -25,14 +26,42 @@ const onSave = (data: TeamWithIndex) => {
|
||||
window.postMessage({type: MODAL_RESULT, data}, window.location.href);
|
||||
};
|
||||
|
||||
const start = async () => {
|
||||
ReactDOM.render(
|
||||
const NewServerModalWrapper: React.FC = () => {
|
||||
const [unremoveable, setUnremovable] = useState<boolean>();
|
||||
|
||||
const handleNewServerMessage = (event: {data: ModalMessage<boolean>}) => {
|
||||
switch (event.data.type) {
|
||||
case MODAL_UNCLOSEABLE: {
|
||||
setUnremovable(event.data.data);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener('message', handleNewServerMessage);
|
||||
window.postMessage({type: GET_MODAL_UNCLOSEABLE}, window.location.href);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('message', handleNewServerMessage);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<NewTeamModal
|
||||
onClose={onClose}
|
||||
onClose={unremoveable ? undefined : onClose}
|
||||
onSave={onSave}
|
||||
editMode={false}
|
||||
show={true}
|
||||
/>,
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const start = async () => {
|
||||
ReactDOM.render(
|
||||
<NewServerModalWrapper/>,
|
||||
document.getElementById('app'),
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user