2016-08-18 11:41:13 +02:00
|
|
|
/*
|
|
|
|
*
|
2017-08-21 15:12:53 +02:00
|
|
|
* HomePage
|
2016-08-18 11:47:26 +02:00
|
|
|
*
|
2016-08-18 11:41:13 +02:00
|
|
|
*/
|
2019-07-02 08:37:41 +02:00
|
|
|
/* eslint-disable */
|
2017-09-26 16:36:28 +02:00
|
|
|
import React from 'react';
|
2016-08-19 13:57:50 +02:00
|
|
|
import { connect } from 'react-redux';
|
2017-08-21 15:12:53 +02:00
|
|
|
import Helmet from 'react-helmet';
|
2018-04-04 12:36:02 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2018-04-04 17:14:08 +02:00
|
|
|
import { bindActionCreators, compose } from 'redux';
|
|
|
|
import { createStructuredSelector } from 'reselect';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-04-16 18:57:08 +02:00
|
|
|
import { get, isEmpty, upperFirst } from 'lodash';
|
2018-04-03 17:56:19 +02:00
|
|
|
import cn from 'classnames';
|
2017-10-18 16:51:50 +02:00
|
|
|
|
2019-04-16 11:53:29 +02:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
InputText as Input,
|
|
|
|
auth,
|
|
|
|
validateInput,
|
|
|
|
} from 'strapi-helper-plugin';
|
2017-10-18 16:51:50 +02:00
|
|
|
|
2019-02-22 10:05:07 +01:00
|
|
|
import Block from '../../components/HomePageBlock';
|
|
|
|
import Sub from '../../components/Sub';
|
|
|
|
import SupportUsCta from '../../components/SupportUsCta';
|
|
|
|
import SupportUsTitle from '../../components/SupportUsTitle';
|
|
|
|
|
|
|
|
import { selectPlugins } from '../App/selectors';
|
|
|
|
|
|
|
|
import injectReducer from '../../utils/injectReducer';
|
|
|
|
import injectSaga from '../../utils/injectSaga';
|
|
|
|
|
2018-04-04 12:36:02 +02:00
|
|
|
import BlockLink from './BlockLink';
|
2018-04-04 15:24:09 +02:00
|
|
|
import CommunityContent from './CommunityContent';
|
2018-04-04 10:21:06 +02:00
|
|
|
import CreateContent from './CreateContent';
|
2018-04-04 15:24:09 +02:00
|
|
|
import SocialLink from './SocialLink';
|
2018-04-04 12:36:02 +02:00
|
|
|
import WelcomeContent from './WelcomeContent';
|
2018-04-04 10:21:06 +02:00
|
|
|
|
2018-04-16 18:13:36 +02:00
|
|
|
import { getArticles, onChange, submit } from './actions';
|
2018-04-04 17:14:08 +02:00
|
|
|
import makeSelectHomePage from './selectors';
|
|
|
|
import reducer from './reducer';
|
|
|
|
import saga from './saga';
|
2017-08-21 15:12:53 +02:00
|
|
|
import styles from './styles.scss';
|
2016-08-18 11:41:13 +02:00
|
|
|
|
2018-04-04 10:21:06 +02:00
|
|
|
const FIRST_BLOCK = [
|
|
|
|
{
|
|
|
|
title: {
|
|
|
|
id: 'app.components.HomePage.welcome',
|
|
|
|
},
|
|
|
|
content: () => <WelcomeContent />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: {
|
|
|
|
id: 'app.components.HomePage.create',
|
|
|
|
},
|
|
|
|
content: () => <CreateContent />,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-04-04 12:36:02 +02:00
|
|
|
const FIRST_BLOCK_LINKS = [
|
|
|
|
{
|
|
|
|
link: 'https://strapi.io/documentation/',
|
|
|
|
content: {
|
|
|
|
id: 'app.components.BlockLink.documentation.content',
|
|
|
|
},
|
|
|
|
isDocumentation: true,
|
|
|
|
title: {
|
|
|
|
id: 'app.components.BlockLink.documentation',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
link: 'https://github.com/strapi/strapi-examples',
|
|
|
|
content: {
|
|
|
|
id: 'app.components.BlockLink.code.content',
|
|
|
|
},
|
|
|
|
isDocumentation: false,
|
|
|
|
title: {
|
|
|
|
id: 'app.components.BlockLink.code',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-04-04 15:24:09 +02:00
|
|
|
const SECOND_BLOCK = {
|
|
|
|
title: {
|
|
|
|
id: 'app.components.HomePage.community',
|
|
|
|
},
|
|
|
|
content: () => <CommunityContent />,
|
|
|
|
};
|
|
|
|
|
|
|
|
const SOCIAL_LINKS = [
|
|
|
|
{
|
2018-04-06 12:11:27 +02:00
|
|
|
name: 'GitHub',
|
2018-04-04 15:24:09 +02:00
|
|
|
link: 'https://github.com/strapi/strapi/',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Slack',
|
|
|
|
link: 'https://slack.strapi.io/',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Medium',
|
|
|
|
link: 'https://medium.com/@strapi',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Twitter',
|
|
|
|
link: 'https://twitter.com/strapijs',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Reddit',
|
2019-08-05 16:55:50 +02:00
|
|
|
link: 'https://www.reddit.com/r/Strapi/',
|
2018-04-04 15:24:09 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Stack Overflow',
|
|
|
|
link: 'https://stackoverflow.com/questions/tagged/strapi',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-04-04 17:14:08 +02:00
|
|
|
export class HomePage extends React.PureComponent {
|
2018-04-04 12:36:02 +02:00
|
|
|
// eslint-disable-line react/prefer-stateless-function
|
2018-04-04 17:14:08 +02:00
|
|
|
state = { errors: [] };
|
2018-04-04 16:18:12 +02:00
|
|
|
|
2018-04-16 18:13:36 +02:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.getArticles();
|
|
|
|
}
|
|
|
|
|
2018-04-04 16:18:12 +02:00
|
|
|
handleSubmit = e => {
|
|
|
|
e.preventDefault();
|
2019-02-14 10:36:20 +01:00
|
|
|
const errors = validateInput(
|
|
|
|
this.props.homePage.body.email,
|
|
|
|
{ required: true },
|
2019-07-02 08:37:41 +02:00
|
|
|
'email'
|
2019-02-14 10:36:20 +01:00
|
|
|
);
|
2018-04-04 16:18:12 +02:00
|
|
|
this.setState({ errors });
|
2018-04-04 17:14:08 +02:00
|
|
|
|
|
|
|
if (isEmpty(errors)) {
|
|
|
|
return this.props.submit();
|
|
|
|
}
|
2018-04-04 16:18:12 +02:00
|
|
|
};
|
|
|
|
|
2018-04-04 17:14:08 +02:00
|
|
|
showFirstBlock = () =>
|
2019-04-03 13:05:18 +02:00
|
|
|
get(this.context.plugins, 'content-manager.leftMenuSections.0.links', [])
|
|
|
|
.length === 0;
|
2018-04-04 17:14:08 +02:00
|
|
|
|
2018-04-16 18:13:36 +02:00
|
|
|
renderButton = () => {
|
2019-04-03 13:05:18 +02:00
|
|
|
/* eslint-disable indent */
|
2018-04-16 18:13:36 +02:00
|
|
|
const data = this.showFirstBlock()
|
|
|
|
? {
|
2019-04-03 13:05:18 +02:00
|
|
|
className: styles.homePageTutorialButton,
|
|
|
|
href:
|
2019-02-27 14:49:04 +01:00
|
|
|
'https://strapi.io/documentation/getting-started/quick-start.html#_3-create-a-content-type',
|
2019-04-03 13:05:18 +02:00
|
|
|
id: 'app.components.HomePage.button.quickStart',
|
|
|
|
primary: true,
|
|
|
|
}
|
2018-04-16 18:13:36 +02:00
|
|
|
: {
|
2019-04-03 13:05:18 +02:00
|
|
|
className: styles.homePageBlogButton,
|
|
|
|
id: 'app.components.HomePage.button.blog',
|
|
|
|
href: 'https://blog.strapi.io/',
|
|
|
|
primary: false,
|
|
|
|
};
|
|
|
|
/* eslint-enable indent */
|
2018-04-16 18:13:36 +02:00
|
|
|
|
|
|
|
return (
|
2019-04-16 11:53:29 +02:00
|
|
|
<a href={data.href} target="_blank">
|
2018-04-16 18:13:36 +02:00
|
|
|
<Button className={data.className} primary={data.primary}>
|
|
|
|
<FormattedMessage id={data.id} />
|
|
|
|
</Button>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2016-08-18 11:41:13 +02:00
|
|
|
render() {
|
2019-02-14 10:36:20 +01:00
|
|
|
const {
|
|
|
|
homePage: { articles, body },
|
|
|
|
} = this.props;
|
2019-04-03 13:05:18 +02:00
|
|
|
|
2018-04-18 11:51:16 +02:00
|
|
|
const WELCOME_AGAIN_BLOCK = [
|
|
|
|
{
|
|
|
|
title: {
|
|
|
|
id: 'app.components.HomePage.welcome.again',
|
|
|
|
},
|
|
|
|
name: upperFirst(`${get(auth.getUserInfo(), 'username')}!`),
|
|
|
|
content: () => <WelcomeContent hasContent />,
|
|
|
|
},
|
|
|
|
];
|
2018-04-04 17:14:08 +02:00
|
|
|
|
2016-08-18 11:41:13 +02:00
|
|
|
return (
|
2018-04-03 17:56:19 +02:00
|
|
|
<div className={cn('container-fluid', styles.containerFluid)}>
|
2019-04-16 11:53:29 +02:00
|
|
|
<Helmet title="Home Page" />
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-md-8 col-lg-8">
|
2018-04-16 18:13:36 +02:00
|
|
|
<Block>
|
|
|
|
{this.showFirstBlock() &&
|
|
|
|
FIRST_BLOCK.map((value, key) => (
|
2019-02-14 10:36:20 +01:00
|
|
|
<Sub
|
|
|
|
key={key}
|
|
|
|
{...value}
|
|
|
|
underline={key === 0}
|
|
|
|
bordered={key === 0}
|
|
|
|
/>
|
2018-04-04 17:14:08 +02:00
|
|
|
))}
|
2018-04-16 18:13:36 +02:00
|
|
|
{!this.showFirstBlock() &&
|
2018-04-16 18:57:08 +02:00
|
|
|
WELCOME_AGAIN_BLOCK.concat(articles).map((value, key) => (
|
2018-04-16 18:13:36 +02:00
|
|
|
<Sub
|
|
|
|
key={key}
|
|
|
|
{...value}
|
|
|
|
bordered={key === 0}
|
2018-04-16 18:57:08 +02:00
|
|
|
style={key === 1 ? { marginBottom: '33px' } : {}}
|
|
|
|
underline={key === 0}
|
2018-04-16 18:13:36 +02:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
{this.renderButton()}
|
|
|
|
<div className={styles.homePageFlex}>
|
2019-02-14 10:36:20 +01:00
|
|
|
{FIRST_BLOCK_LINKS.map((value, key) => (
|
|
|
|
<BlockLink {...value} key={key} />
|
|
|
|
))}
|
2018-04-16 18:13:36 +02:00
|
|
|
</div>
|
|
|
|
</Block>
|
2018-04-04 15:24:09 +02:00
|
|
|
<Block>
|
|
|
|
<Sub {...SECOND_BLOCK} />
|
|
|
|
<div className={styles.homePageFlex}>
|
2019-02-14 10:36:20 +01:00
|
|
|
<div
|
2019-04-16 11:53:29 +02:00
|
|
|
className="row"
|
2019-02-14 10:36:20 +01:00
|
|
|
style={{ width: '100%', marginRight: '0' }}
|
|
|
|
>
|
|
|
|
{SOCIAL_LINKS.map((value, key) => (
|
|
|
|
<SocialLink key={key} {...value} />
|
|
|
|
))}
|
2018-04-04 15:24:09 +02:00
|
|
|
</div>
|
2018-04-04 16:18:12 +02:00
|
|
|
<div className={styles.newsLetterWrapper}>
|
|
|
|
<div>
|
2019-04-16 11:53:29 +02:00
|
|
|
<FormattedMessage id="app.components.HomePage.newsLetter" />
|
2018-04-04 16:18:12 +02:00
|
|
|
</div>
|
|
|
|
<form onSubmit={this.handleSubmit}>
|
|
|
|
<div className={cn(styles.homePageForm, 'row')}>
|
2019-04-16 11:53:29 +02:00
|
|
|
<div className="col-md-12">
|
2018-04-04 16:18:12 +02:00
|
|
|
<Input
|
2018-04-04 17:14:08 +02:00
|
|
|
value={body.email}
|
|
|
|
onChange={this.props.onChange}
|
2019-04-16 11:53:29 +02:00
|
|
|
name=""
|
|
|
|
placeholder="johndoe@gmail.com"
|
2018-04-04 16:18:12 +02:00
|
|
|
error={!isEmpty(this.state.errors)}
|
|
|
|
/>
|
2019-04-16 11:53:29 +02:00
|
|
|
<FormattedMessage id="app.components.HomePage.cta">
|
|
|
|
{message => <button type="submit">{message}</button>}
|
2018-04-04 16:18:12 +02:00
|
|
|
</FormattedMessage>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2018-04-04 15:24:09 +02:00
|
|
|
</div>
|
|
|
|
</Block>
|
2018-04-03 17:56:19 +02:00
|
|
|
</div>
|
2019-04-16 11:53:29 +02:00
|
|
|
<div className="col-lg-4 col-md-4">
|
2018-04-04 13:55:27 +02:00
|
|
|
<Block className={styles.blockShirt}>
|
|
|
|
<div>
|
2018-04-05 14:17:50 +02:00
|
|
|
<SupportUsTitle />
|
2019-04-16 11:53:29 +02:00
|
|
|
<FormattedMessage id="app.components.HomePage.support.content">
|
2018-04-04 13:55:27 +02:00
|
|
|
{message => <p>{message}</p>}
|
|
|
|
</FormattedMessage>
|
2018-04-05 14:17:50 +02:00
|
|
|
<SupportUsCta />
|
2018-04-04 13:55:27 +02:00
|
|
|
</div>
|
|
|
|
</Block>
|
2018-04-03 17:56:19 +02:00
|
|
|
</div>
|
2017-10-18 16:51:50 +02:00
|
|
|
</div>
|
2016-08-19 13:57:50 +02:00
|
|
|
</div>
|
2016-08-18 11:41:13 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-08-19 13:57:50 +02:00
|
|
|
|
2019-04-03 13:05:18 +02:00
|
|
|
HomePage.contextTypes = {
|
|
|
|
plugins: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
2017-10-18 16:51:50 +02:00
|
|
|
HomePage.propTypes = {
|
2018-04-16 18:13:36 +02:00
|
|
|
getArticles: PropTypes.func.isRequired,
|
2018-04-04 17:14:08 +02:00
|
|
|
homePage: PropTypes.object.isRequired,
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
submit: PropTypes.func.isRequired,
|
2017-10-18 16:51:50 +02:00
|
|
|
};
|
2016-08-19 13:57:50 +02:00
|
|
|
|
2018-04-04 17:14:08 +02:00
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
|
|
homePage: makeSelectHomePage(),
|
|
|
|
plugins: selectPlugins(),
|
|
|
|
});
|
|
|
|
|
2016-08-19 13:57:50 +02:00
|
|
|
function mapDispatchToProps(dispatch) {
|
2018-04-04 17:14:08 +02:00
|
|
|
return bindActionCreators(
|
|
|
|
{
|
2018-04-16 18:13:36 +02:00
|
|
|
getArticles,
|
2018-04-04 17:14:08 +02:00
|
|
|
onChange,
|
|
|
|
submit,
|
|
|
|
},
|
2019-07-02 08:37:41 +02:00
|
|
|
dispatch
|
2018-04-04 17:14:08 +02:00
|
|
|
);
|
2016-08-19 13:57:50 +02:00
|
|
|
}
|
|
|
|
|
2019-02-14 10:36:20 +01:00
|
|
|
const withConnect = connect(
|
|
|
|
mapStateToProps,
|
2019-07-02 08:37:41 +02:00
|
|
|
mapDispatchToProps
|
2019-02-14 10:36:20 +01:00
|
|
|
);
|
2018-04-04 17:14:08 +02:00
|
|
|
|
|
|
|
const withReducer = injectReducer({ key: 'homePage', reducer });
|
|
|
|
const withSaga = injectSaga({ key: 'homePage', saga });
|
|
|
|
|
|
|
|
// export default connect(mapDispatchToProps)(HomePage);
|
2019-02-14 10:36:20 +01:00
|
|
|
export default compose(
|
|
|
|
withReducer,
|
|
|
|
withSaga,
|
2019-07-02 08:37:41 +02:00
|
|
|
withConnect
|
2019-02-14 10:36:20 +01:00
|
|
|
)(HomePage);
|