Skip to content

Commit

Permalink
Migrate leave_team_modal to typescript (mattermost#4810)
Browse files Browse the repository at this point in the history
* Migrate leave_team_modal to typescript

* Remove the obsolete snapshot

* Change the return type of onHide function to void.
  • Loading branch information
sowmiyamuthuraman committed Feb 4, 2020
1 parent 20f24f8 commit 819475a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
// See LICENSE.txt for license information.

import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {bindActionCreators, Dispatch} from 'redux';
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {removeUserFromTeam as leaveTeam} from 'mattermost-redux/actions/teams';
import {GlobalState} from 'mattermost-redux/types/store';
import {GenericAction} from 'mattermost-redux/types/actions';

import {toggleSideBarRightMenuAction} from 'actions/global_actions.jsx';
import {ModalIdentifiers} from 'utils/constants';

import {isModalOpen} from 'selectors/views/modals';

import LeaveTeamModal from './leave_team_modal.jsx';
import LeaveTeamModal from './leave_team_modal';

function mapStateToProps(state) {
function mapStateToProps(state: GlobalState) {
const modalId = ModalIdentifiers.LEAVE_TEAM;
const currentUserId = getCurrentUserId(state);
const currentTeamId = getCurrentTeamId(state);
Expand All @@ -26,7 +28,7 @@ function mapStateToProps(state) {
};
}

function mapDispatchToProps(dispatch) {
function mapDispatchToProps(dispatch: Dispatch<GenericAction>) {
return {
actions: bindActionCreators({
leaveTeam,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {shallow} from 'enzyme';
import React from 'react';

import LeaveTeamModal from 'components/leave_team_modal/leave_team_modal.jsx';
import LeaveTeamModal from 'components/leave_team_modal/leave_team_modal';

describe('components/LeaveTeamModal', () => {
const requiredProps = {
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('components/LeaveTeamModal', () => {
document.removeEventListener = jest.fn();

const wrapper = shallow(<LeaveTeamModal {...{...requiredProps, show: true}}/>);
const instance = wrapper.instance();
const instance = wrapper.instance() as LeaveTeamModal;

expect(document.addEventListener).toHaveBeenCalledTimes(1);
expect(document.removeEventListener).not.toBeCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,24 @@
import React from 'react';
import {Modal} from 'react-bootstrap';
import {FormattedMessage} from 'react-intl';
import PropTypes from 'prop-types';
import {ActionFunc} from 'mattermost-redux/types/actions';

import Constants from 'utils/constants';
import {isKeyPressed} from 'utils/utils';

export default class LeaveTeamModal extends React.PureComponent {
static propTypes = {

/**
* Current user id.
*/
currentUserId: PropTypes.string.isRequired,

/**
* Current team id.
*/
currentTeamId: PropTypes.string.isRequired,

/**
* hide action
*/

onHide: PropTypes.func.isRequired,

/**
* show or hide modal
*/

show: PropTypes.bool.isRequired,

actions: PropTypes.shape({

/**
* An action to remove user from team
*/

leaveTeam: PropTypes.func.isRequired,

/**
* An action to toggle the right menu
*/

toggleSideBarRightMenu: PropTypes.func.isRequired,
}),
type Props = {
currentUserId: string;
currentTeamId: string;
onHide: () => void;
show: boolean;
actions: {
leaveTeam: (teamId: string, userId: string) => ActionFunc;
toggleSideBarRightMenu: () => void;
};

}

export default class LeaveTeamModal extends React.PureComponent<Props> {
componentDidMount() {
if (this.props.show) {
document.addEventListener('keypress', this.handleKeyPress);
Expand All @@ -60,9 +32,9 @@ export default class LeaveTeamModal extends React.PureComponent {
document.removeEventListener('keypress', this.handleKeyPress);
}

handleKeyPress = (e) => {
handleKeyPress = (e: KeyboardEvent) => {
if (isKeyPressed(e, Constants.KeyCodes.ENTER)) {
this.handleSubmit(e);
this.handleSubmit();
}
};

Expand Down

0 comments on commit 819475a

Please sign in to comment.