diff options
Diffstat (limited to 'src/components/auth/ChangeServer.js')
-rw-r--r-- | src/components/auth/ChangeServer.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/components/auth/ChangeServer.js b/src/components/auth/ChangeServer.js new file mode 100644 index 000000000..433334b6c --- /dev/null +++ b/src/components/auth/ChangeServer.js | |||
@@ -0,0 +1,80 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { observer } from 'mobx-react'; | ||
4 | import { defineMessages, intlShape } from 'react-intl'; | ||
5 | |||
6 | import Form from '../../lib/Form'; | ||
7 | import Input from '../ui/Input'; | ||
8 | import Button from '../ui/Button'; | ||
9 | |||
10 | const messages = defineMessages({ | ||
11 | headline: { | ||
12 | id: 'changeserver.headline', | ||
13 | defaultMessage: '!!!Change server', | ||
14 | }, | ||
15 | label: { | ||
16 | id: 'changeserver.label', | ||
17 | defaultMessage: '!!!Server', | ||
18 | }, | ||
19 | submit: { | ||
20 | id: 'changeserver.submit', | ||
21 | defaultMessage: '!!!Submit', | ||
22 | }, | ||
23 | }); | ||
24 | |||
25 | export default @observer class ChangeServer extends Component { | ||
26 | static propTypes = { | ||
27 | onSubmit: PropTypes.func.isRequired, | ||
28 | server: PropTypes.string.isRequired, | ||
29 | }; | ||
30 | |||
31 | static contextTypes = { | ||
32 | intl: intlShape, | ||
33 | }; | ||
34 | |||
35 | form = new Form({ | ||
36 | fields: { | ||
37 | server: { | ||
38 | label: this.context.intl.formatMessage(messages.label), | ||
39 | value: '', | ||
40 | }, | ||
41 | }, | ||
42 | }, this.context.intl); | ||
43 | |||
44 | componentDidMount() { | ||
45 | this.form.$('server').value = this.props.server; | ||
46 | } | ||
47 | |||
48 | submit(e) { | ||
49 | e.preventDefault(); | ||
50 | this.form.submit({ | ||
51 | onSuccess: (form) => { | ||
52 | this.props.onSubmit(form.values()); | ||
53 | }, | ||
54 | onError: () => { }, | ||
55 | }); | ||
56 | } | ||
57 | |||
58 | render() { | ||
59 | const { form } = this; | ||
60 | const { intl } = this.context; | ||
61 | |||
62 | return ( | ||
63 | <div className="auth__container"> | ||
64 | <form className="franz-form auth__form" onSubmit={e => this.submit(e)}> | ||
65 | <h1>{intl.formatMessage(messages.headline)}</h1> | ||
66 | |||
67 | <Input | ||
68 | field={form.$('server')} | ||
69 | focus | ||
70 | /> | ||
71 | <Button | ||
72 | type="submit" | ||
73 | className="auth__button" | ||
74 | label={intl.formatMessage(messages.submit)} | ||
75 | /> | ||
76 | </form> | ||
77 | </div> | ||
78 | ); | ||
79 | } | ||
80 | } | ||