Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Migrate 'components/claim' module and associated tests to TypeScript #7043

Merged
merged 3 commits into from Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,9 +1,9 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import PropTypes from 'prop-types';
import React from 'react';
import {Route, Switch} from 'react-router-dom';
import {ActionFunc} from 'mattermost-redux/types/actions';

import logoImage from 'images/logo.png';
import BackButton from 'components/common/back_button';
Expand All @@ -12,26 +12,33 @@ import EmailToOAuth from 'components/claim/components/email_to_oauth';
import LDAPToEmail from 'components/claim/components/ldap_to_email';
import EmailToLDAP from 'components/claim/components/email_to_ldap';

export default class ClaimController extends React.PureComponent {
static propTypes = {
location: PropTypes.object.isRequired,
siteName: PropTypes.string,
ldapLoginFieldName: PropTypes.string,
passwordConfig: PropTypes.object,
interface PasswordConfig {
minimumLength: number;
requireLowercase: boolean;
requireUppercase: boolean;
requireNumber: boolean;
requireSymbol: boolean;
}

/*
* Object from react-router
*/
match: PropTypes.shape({
url: PropTypes.string.isRequired,
}).isRequired,
type Location = {
search: string;
}

actions: PropTypes.shape({
switchLdapToEmail: PropTypes.func.isRequired,
}).isRequired,
};
type Props = {
location: Location;
siteName?: string;
ldapLoginFieldName?: string;
passwordConfig?: PasswordConfig;
match: {
url: string
},
actions: {
switchLdapToEmail: (ldapPassword: string, email: string, emailPassword: string, mfaCode?: string) => ActionFunc;
},
}

render() {
export default class ClaimController extends React.PureComponent<Props> {
render() : JSX.Element {
const email = (new URLSearchParams(this.props.location.search)).get('email');
const newType = (new URLSearchParams(this.props.location.search)).get('new_type');
const currentType = (new URLSearchParams(this.props.location.search)).get('old_type');
Expand Down
14 changes: 8 additions & 6 deletions components/claim/index.js → components/claim/index.ts
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 {switchLdapToEmail} from 'mattermost-redux/actions/users';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {GlobalState} from 'mattermost-redux/types/store';
import {GenericAction} from 'mattermost-redux/types/actions';

import {getPasswordConfig} from 'utils/utils.jsx';

import ClaimController from './claim_controller.jsx';
import ClaimController from './claim_controller';

function mapStateToProps(state) {
function mapStateToProps(state: GlobalState) {
const config = getConfig(state);
const siteName = config.SiteName;
const ldapLoginFieldName = config.LdapLoginFieldName;
const siteName = config.SiteName as string;
const ldapLoginFieldName = config.LdapLoginFieldName as string;

return {
siteName,
Expand All @@ -23,7 +25,7 @@ function mapStateToProps(state) {
};
}

function mapDispatchToProps(dispatch) {
function mapDispatchToProps(dispatch: Dispatch<GenericAction>) {
return {
actions: bindActionCreators({
switchLdapToEmail,
Expand Down