You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
7 years ago
|
import * as React from 'react';
|
||
7 years ago
|
import { connect } from 'react-redux';
|
||
7 years ago
|
import { withRouter } from 'react-router';
|
||
7 years ago
|
|
||
7 years ago
|
import Container from './widgets/Container';
|
||
7 years ago
|
import SyncGate from './SyncGate';
|
||
7 years ago
|
import LoginForm from './LoginForm';
|
||
7 years ago
|
|
||
7 years ago
|
import { store, StoreState, CredentialsType } from './store';
|
||
|
import { fetchCredentials } from './store/actions';
|
||
7 years ago
|
|
||
7 years ago
|
import * as C from './constants';
|
||
7 years ago
|
|
||
7 years ago
|
class Root extends React.PureComponent {
|
||
7 years ago
|
props: {
|
||
7 years ago
|
credentials: CredentialsType;
|
||
7 years ago
|
};
|
||
|
|
||
7 years ago
|
constructor(props: any) {
|
||
|
super(props);
|
||
7 years ago
|
this.onFormSubmit = this.onFormSubmit.bind(this);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
onFormSubmit(username: string, password: string, encryptionPassword: string, serviceApiUrl: string) {
|
||
|
store.dispatch(fetchCredentials(username, password, encryptionPassword, serviceApiUrl));
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
render() {
|
||
7 years ago
|
if (this.props.credentials.value === null) {
|
||
7 years ago
|
const style = {
|
||
7 years ago
|
isSafe: {
|
||
|
textDecoration: 'none',
|
||
7 years ago
|
display: 'block',
|
||
7 years ago
|
},
|
||
7 years ago
|
divider: {
|
||
|
margin: '30px 0',
|
||
|
color: '#00000025',
|
||
|
}
|
||
7 years ago
|
};
|
||
|
|
||
7 years ago
|
return (
|
||
7 years ago
|
<Container style={{maxWidth: 400}}>
|
||
7 years ago
|
<h2>Please Log In</h2>
|
||
7 years ago
|
<LoginForm
|
||
|
onSubmit={this.onFormSubmit}
|
||
|
error={this.props.credentials.error}
|
||
|
loading={this.props.credentials.fetching}
|
||
|
/>
|
||
7 years ago
|
<hr style={style.divider}/>
|
||
|
<ul>
|
||
|
<li><a style={style.isSafe} href={C.faq + '#web-client'}>Is the web client safe to use?</a></li>
|
||
|
<li><a style={style.isSafe} href={C.sourceCode}>Source code</a></li>
|
||
|
</ul>
|
||
7 years ago
|
</Container>
|
||
7 years ago
|
);
|
||
7 years ago
|
}
|
||
|
|
||
|
return (
|
||
7 years ago
|
<SyncGate etesync={this.props.credentials.value} />
|
||
7 years ago
|
);
|
||
|
}
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
const mapStateToProps = (state: StoreState) => {
|
||
7 years ago
|
return {
|
||
|
credentials: state.credentials,
|
||
|
};
|
||
|
};
|
||
|
|
||
7 years ago
|
// FIXME: withRouter is only needed here because of https://github.com/ReactTraining/react-router/issues/5795
|
||
7 years ago
|
export default withRouter(connect(
|
||
7 years ago
|
mapStateToProps
|
||
7 years ago
|
)(Root));
|