163 lines
5.6 KiB
JavaScript
Raw Normal View History

2016-08-18 11:41:13 +02:00
/*
* HomePage
*
* This is the first thing users see of our App, at the '/' route
2016-08-18 11:47:26 +02:00
*
* NOTE: while this component should technically be a stateless functional
* component (SFC), hot reloading does not currently support SFCs. If hot
* reloading is not a neccessity for you then you can refactor it and remove
* the linting exception.
2016-08-18 11:41:13 +02:00
*/
import React from 'react';
2016-09-25 21:54:59 +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 RightContentSectionTitle from 'components/RightContentSectionTitle';
import Container from 'components/Container';
2016-09-08 23:38:29 +02:00
import RightContentTitle from 'components/RightContentTitle';
2016-09-25 21:54:59 +02:00
import {
2016-09-26 17:28:40 +02:00
selectName,
2016-09-26 18:28:32 +02:00
selectDescription,
selectVersion,
2016-09-25 21:54:59 +02:00
selectLoading,
selectError,
} from 'containers/HomePage/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,
} from 'containers/HomePage/actions';
2016-09-25 21:54:59 +02:00
2016-09-08 23:38:29 +02:00
import styles from './styles.css';
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-09-27 18:06:35 +02:00
const error = this.props.error && <div className="row"><div className="alert alert-danger" role="alert"><strong>An error occurred.</strong> {this.props.error.message}</div></div>;
const success = this.props.success && <div className="row"><div className="alert alert-success" role="alert"><strong>Success!</strong> {this.props.success.message}</div></div>;
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
{success}
{error}
<PluginHeader {...this.props}></PluginHeader>
2016-09-09 10:45:58 +02:00
<Container>
<RightContentTitle title="General" description="Configure your general settings."></RightContentTitle>
<RightContentSectionTitle title="Application" description="The general settings of your Strapi application."></RightContentSectionTitle>
2016-09-26 17:28:40 +02:00
<form onSubmit={this.props.onFormSubmit}>
<div className={`form-group row ${styles.homePageRightContentFormGroup}`}>
<label htmlFor="applicationName" className="col-xs-7 col-form-label">Name</label>
<div className="col-xs-5">
<input
className="form-control"
type="text"
placeholder="My Application"
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-09-27 18:06:35 +02:00
autoFocus={true}
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}`}>
<label htmlFor="applicationDescription" className="col-xs-7 col-form-label">Description</label>
<div className="col-xs-5">
2016-09-26 18:28:32 +02:00
<input
className="form-control"
type="text"
placeholder="A Strapi application"
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}`}>
<label htmlFor="applicationVersion" className="col-xs-7 col-form-label">Version</label>
<div className="col-xs-5">
2016-09-26 18:28:32 +02:00
<input
className="form-control"
type="text"
placeholder="0.0.1"
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-09-27 18:06:35 +02:00
changeRoute: React.PropTypes.func,
loading: React.PropTypes.bool,
error: React.PropTypes.oneOfType([
React.PropTypes.object,
React.PropTypes.bool,
]),
2016-09-26 17:28:40 +02:00
name: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.bool,
]),
2016-09-26 18:28:32 +02:00
description: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.bool,
]),
version: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.bool,
]),
2016-09-26 17:28:40 +02:00
onPageLoad: React.PropTypes.func,
onFormSubmit: React.PropTypes.func,
2016-09-26 18:28:32 +02:00
onChangeName: React.PropTypes.func,
onChangeDescription: React.PropTypes.func,
onChangeVersion: React.PropTypes.func,
2016-09-25 21:54:59 +02:00
};
2016-09-30 18:24:46 +02:00
export function mapDispatchToProps(dispatch) {
2016-09-26 17:28:40 +02:00
return {
2016-09-26 18:28:32 +02:00
onChangeName: (evt) => dispatch(changeName(evt.target.value)),
onChangeDescription: (evt) => dispatch(changeDescription(evt.target.value)),
onChangeVersion: (evt) => dispatch(changeVersion(evt.target.value)),
2016-09-27 18:06:35 +02:00
onFormSubmit: (evt) => {
if (evt !== undefined && evt.preventDefault) evt.preventDefault();
2016-09-26 17:28:40 +02:00
dispatch(updateGeneralSettings());
},
2016-09-27 18:06:35 +02:00
changeRoute: (url) => dispatch(push(url)),
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(),
version: selectVersion(),
2016-09-27 18:06:35 +02:00
loading: selectLoading(),
error: selectError(),
2016-09-25 21:54:59 +02:00
});
// Wrap the component to inject dispatch and state into it
export default connect(mapStateToProps, mapDispatchToProps)(HomePage);