aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/basicAuth/Component.js
blob: 13395fb402bf954db5f0a7ed7315acbaf74e894f (plain) (blame)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import injectSheet from 'react-jss';
import { observer } from 'mobx-react';
import classnames from 'classnames';

import Modal from '../../components/ui/Modal';
import Input from '../../components/ui/Input';
import Button from '../../components/ui/Button';

import {
  state,
  resetState,
  sendCredentials,
  cancelLogin,
} from '.';
import Form from './Form';

import styles from './styles';

export default @injectSheet(styles) @observer class BasicAuthModal extends Component {
  static propTypes = {
    classes: PropTypes.object.isRequired,
  }

  submit(e) {
    e.preventDefault();

    const values = Form.values();
    console.log('form submit', values);

    sendCredentials(values.user, values.password);
    resetState();
  }

  cancel() {
    cancelLogin();
    this.close();
  }

  close() {
    resetState();
    state.isModalVisible = false;
  }

  render() {
    const {
      classes,
    } = this.props;

    const {
      isModalVisible,
      authInfo,
    } = state;

    if (!authInfo) {
      return null;
    }

    return (
      <Modal
        isOpen={isModalVisible}
        className={classes.modal}
        close={this.cancel.bind(this)}
      >
        <h1>Sign in</h1>
        <p>
          http
          {authInfo.port === 443 && 's'}
          ://
          {authInfo.host}
        </p>
        <form
          onSubmit={this.submit.bind(this)}
          className={classnames('franz-form', classes.form)}
        >
          <Input
            field={Form.$('user')}
            showLabel={false}
          />
          <Input
            field={Form.$('password')}
            showLabel={false}
            showPasswordToggle
          />
          <div className={classes.buttons}>
            <Button
              type="button"
              label="Cancel"
              buttonType="secondary"
              onClick={this.cancel.bind(this)}
            />
            <Button
              type="submit"
              label="Sign In"
            />
          </div>
        </form>
      </Modal>
    );
  }
}