summaryrefslogtreecommitdiff
path: root/sw-ui/src/components/home/ChooseNameForm.tsx
blob: 8292150b6b1417080137001e19fa73088885167e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Button, Classes, InputGroup, Intent } from '@blueprintjs/core';
import React, { ChangeEvent, Component, SyntheticEvent } from 'react';
import { connect } from 'react-redux';
import { actions } from '../../redux/actions/user';

type ChooseNameFormPresenterProps = {
  chooseUsername: (username: string) => void,
}

class ChooseNameFormPresenter extends Component<ChooseNameFormPresenterProps> {
  _username = '';

  play = (e: SyntheticEvent<any>) => {
    e.preventDefault();
    if (this._username !== undefined) {
      this.props.chooseUsername(this._username);
    }
  };

  render() {
    return (
        <form onSubmit={this.play}>
          <InputGroup
            className={Classes.LARGE}
            placeholder="Username"
            onChange={(e: ChangeEvent<HTMLInputElement>) => (this._username = e.target.value)}
            rightElement={this.renderSubmit()}
          />
        </form>
    );
  }

  renderSubmit = () => (
    <Button className={Classes.MINIMAL} onClick={this.play} intent={Intent.PRIMARY} icon="arrow-right" />
  );
}

const mapDispatchToProps = {
  chooseUsername: actions.chooseUsername,
};

export const ChooseNameForm = connect(null, mapDispatchToProps)(ChooseNameFormPresenter);
bgstack15