176 lines
5.7 KiB
JavaScript
Raw Normal View History

2016-08-18 11:41:13 +02:00
/*
* HomePage
*/
import React from 'react';
2016-10-04 17:49:40 +02:00
import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect';
2016-09-08 23:38:29 +02:00
import PluginHeader from 'components/PluginHeader';
2016-09-09 10:45:58 +02:00
import Container from 'components/Container';
2016-09-08 23:38:29 +02:00
import RightContentTitle from 'components/RightContentTitle';
2016-11-18 13:09:15 +01:00
import RightContentSectionTitle from 'components/RightContentSectionTitle';
import { injectIntl, intlShape, FormattedMessage } from 'react-intl';
import appMessages from 'containers/App/messages.json';
import messages from './messages.json';
import { define } from '../../i18n';
define(messages);
2016-09-25 21:54:59 +02:00
import {
2016-11-18 16:18:29 +01:00
// selectHome,
2016-11-18 13:09:15 +01:00
selectLoading,
selectError,
2016-11-18 16:18:29 +01:00
// selectGeneralSettings,
2016-09-26 17:28:40 +02:00
selectName,
2016-09-26 18:28:32 +02:00
selectDescription,
selectVersion,
2016-11-18 16:18:29 +01:00
// selectLocationState,
2016-11-18 13:09:15 +01:00
} from './selectors';
2016-09-26 17:28:40 +02:00
import {
loadGeneralSettings,
changeName,
2016-09-26 18:28:32 +02:00
changeDescription,
changeVersion,
2016-09-26 17:28:40 +02:00
updateGeneralSettings,
2016-10-04 17:09:03 +02:00
cancelGeneralSettings,
2016-11-18 13:09:15 +01:00
} from './actions';
2016-09-25 21:54:59 +02:00
2016-10-05 18:13:02 +02:00
import styles from './styles.scss';
2016-08-18 11:41:13 +02:00
2016-09-25 21:54:59 +02:00
export class HomePage extends React.Component {
componentDidMount() {
this.props.onPageLoad();
}
2016-08-18 11:41:13 +02:00
render() {
2016-10-12 12:07:26 +02:00
const { formatMessage } = this.props.intl;
2016-08-18 11:41:13 +02:00
return (
2016-08-26 14:42:58 +02:00
<div>
2016-09-08 23:38:29 +02:00
<div className="container">
2016-09-27 18:06:35 +02:00
<PluginHeader {...this.props}></PluginHeader>
2016-09-09 10:45:58 +02:00
<Container>
2016-10-12 12:07:26 +02:00
<RightContentTitle
title={formatMessage(appMessages.generalSectionTitle)}
description={formatMessage(messages.rightSectionDescription)}
/>
<RightContentSectionTitle
title={formatMessage(messages.rightContentSectionTitle)}
description={formatMessage(messages.rightContentSectionDescription)}
/>
2016-09-26 17:28:40 +02:00
<form onSubmit={this.props.onFormSubmit}>
<div className={`form-group row ${styles.homePageRightContentFormGroup}`}>
2016-10-12 12:07:26 +02:00
<label htmlFor="applicationName" className="col-xs-7 col-form-label">
<FormattedMessage {...messages.nameLabel} />
</label>
2016-09-26 17:28:40 +02:00
<div className="col-xs-5">
<input
className="form-control"
type="text"
2016-10-12 12:07:26 +02:00
placeholder={formatMessage(messages.namePlaceholder)}
2016-09-26 17:28:40 +02:00
id="applicationName"
2016-09-27 18:06:35 +02:00
value={this.props.name || ''}
2016-09-26 18:28:32 +02:00
onChange={this.props.onChangeName}
2016-10-04 17:49:40 +02:00
autoFocus
2016-09-26 17:28:40 +02:00
/>
</div>
2016-09-08 23:38:29 +02:00
</div>
2016-09-26 17:28:40 +02:00
<div className={`form-group row ${styles.homePageRightContentFormGroup}`}>
2016-10-12 12:07:26 +02:00
<label htmlFor="applicationDescription" className="col-xs-7 col-form-label">
<FormattedMessage {...messages.descriptionLabel} />
</label>
2016-09-26 17:28:40 +02:00
<div className="col-xs-5">
2016-09-26 18:28:32 +02:00
<input
className="form-control"
type="text"
2016-10-12 12:07:26 +02:00
placeholder={formatMessage(messages.descriptionPlaceholder)}
2016-09-26 18:28:32 +02:00
id="applicationDescription"
2016-09-27 18:06:35 +02:00
value={this.props.description || ''}
2016-09-26 18:28:32 +02:00
onChange={this.props.onChangeDescription}
/>
2016-09-26 17:28:40 +02:00
</div>
2016-09-08 23:38:29 +02:00
</div>
2016-09-26 17:28:40 +02:00
<div className={`form-group row ${styles.homePageRightContentFormGroup}`}>
2016-10-12 12:07:26 +02:00
<label htmlFor="applicationVersion" className="col-xs-7 col-form-label">
<FormattedMessage {...messages.versionLabel} />
</label>
2016-09-26 17:28:40 +02:00
<div className="col-xs-5">
2016-09-26 18:28:32 +02:00
<input
className="form-control"
type="text"
2016-10-12 12:07:26 +02:00
placeholder={formatMessage(messages.versionPlaceholder)}
2016-09-26 18:28:32 +02:00
id="applicationVersion"
2016-09-27 18:06:35 +02:00
value={this.props.version || ''}
2016-09-26 18:28:32 +02:00
onChange={this.props.onChangeVersion}
/>
2016-09-26 17:28:40 +02:00
</div>
2016-09-08 23:38:29 +02:00
</div>
2016-09-27 18:06:35 +02:00
<button className="btn btn-primary hidden-xs-up" type="submit">Submit</button>
2016-09-26 17:28:40 +02:00
</form>
2016-09-09 10:45:58 +02:00
</Container>
2016-09-08 23:38:29 +02:00
</div>
2016-08-26 14:42:58 +02:00
</div>
2016-08-18 11:41:13 +02:00
);
}
}
2016-09-25 21:54:59 +02:00
HomePage.propTypes = {
2016-11-18 13:09:15 +01:00
// changeRoute: React.PropTypes.func,
2016-10-04 17:49:40 +02:00
description: React.PropTypes.oneOfType([
2016-09-26 17:28:40 +02:00
React.PropTypes.string,
React.PropTypes.bool,
]),
2016-11-18 16:18:29 +01:00
// error: React.PropTypes.oneOfType([
// React.PropTypes.object,
// React.PropTypes.bool,
// ]),
2016-10-12 12:07:26 +02:00
intl: intlShape.isRequired,
2016-11-18 16:18:29 +01:00
// loading: React.PropTypes.bool,
2016-10-04 17:49:40 +02:00
name: React.PropTypes.oneOfType([
2016-09-26 18:28:32 +02:00
React.PropTypes.string,
React.PropTypes.bool,
]),
2016-11-18 16:18:29 +01:00
// onCancel: React.PropTypes.func,
2016-09-26 18:28:32 +02:00
onChangeName: React.PropTypes.func,
onChangeDescription: React.PropTypes.func,
onChangeVersion: React.PropTypes.func,
2016-10-04 17:49:40 +02:00
onFormSubmit: React.PropTypes.func,
onPageLoad: React.PropTypes.func,
version: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.bool,
]),
2016-09-25 21:54:59 +02:00
};
2016-09-30 18:24:46 +02:00
export function mapDispatchToProps(dispatch) {
2016-10-04 16:31:52 +02:00
return {
2016-10-04 17:49:40 +02:00
onCancel: () => dispatch(cancelGeneralSettings()),
2016-10-04 16:31:52 +02:00
onChangeName: (evt) => dispatch(changeName(evt.target.value)),
onChangeDescription: (evt) => dispatch(changeDescription(evt.target.value)),
onChangeVersion: (evt) => dispatch(changeVersion(evt.target.value)),
onFormSubmit: (evt) => {
if (evt !== undefined && evt.preventDefault) evt.preventDefault();
dispatch(updateGeneralSettings());
},
2016-09-25 21:54:59 +02:00
onPageLoad: (evt) => {
2016-09-27 18:06:35 +02:00
if (evt !== undefined && evt.preventDefault) evt.preventDefault();
2016-09-25 21:54:59 +02:00
dispatch(loadGeneralSettings());
},
dispatch,
};
}
const mapStateToProps = createStructuredSelector({
2016-09-26 17:28:40 +02:00
name: selectName(),
2016-09-26 18:28:32 +02:00
description: selectDescription(),
2016-09-27 18:06:35 +02:00
error: selectError(),
2016-10-04 17:49:40 +02:00
loading: selectLoading(),
version: selectVersion(),
2016-09-25 21:54:59 +02:00
});
// Wrap the component to inject dispatch and state into it
2016-10-12 12:07:26 +02:00
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(HomePage));