Skip to content

Commit

Permalink
Migrates terms of service and how to pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrés González Muñoz authored and agnlez committed Mar 18, 2019
1 parent 369748c commit 1121303
Show file tree
Hide file tree
Showing 22 changed files with 200 additions and 256 deletions.
40 changes: 9 additions & 31 deletions pages/app/Howto.js → layout/app/how-to/component.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
import React, { PureComponent } from 'react';
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import renderHTML from 'react-render-html';
import { connect } from 'react-redux';
import { getStaticData } from 'redactions/static_pages';

// components
import Layout from 'layout/layout/layout-app';

class Howto extends PureComponent {
static async getInitialProps({ store }) {
// Get static data
await store.dispatch(getStaticData('how-to'));
return {};
}
class LayoutHowTo extends PureComponent {
static propTypes = { data: PropTypes.object.isRequired }

render() {
const { data } = this.props;
const styles = {};
const styles = { ...(data && data.photo) && { backgroundImage: `url(${process.env.STATIC_SERVER_URL}${data.photo.cover})` } };

if (!data) return null;

if (data && data.photo) {
styles.backgroundImage = `url(${process.env.STATIC_SERVER_URL}${data.photo.cover})`;
}

return (
<Layout
title="How to"
// TO-DO: fill description
description="How to description"
url={this.props.url}
user={this.props.user}
className="l-static"
>
<section className="l-content">
Expand All @@ -50,7 +41,7 @@ class Howto extends PureComponent {
<div className="row align-center">
<div className="column small-12 medium-8">
<div className="c-terms">
{renderHTML(data.content || '')}
{renderHTML(data.content)}
</div>
</div>
</div>
Expand All @@ -64,17 +55,4 @@ class Howto extends PureComponent {
}
}

Howto.propTypes = {
data: PropTypes.object,
getStaticData: PropTypes.func
};

const mapStateToProps = state => ({
data: state.staticPages['how-to']
});

const mapDispatchToProps = {
getStaticData
};

export default connect(mapStateToProps, mapDispatchToProps)(Howto);
export default LayoutHowTo;
9 changes: 9 additions & 0 deletions layout/app/how-to/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { connect } from 'react-redux';

// component
import LayoutHowTo from './component';

export default connect(
state => ({ data: state.staticPages['how-to'] }),
null
)(LayoutHowTo);
52 changes: 13 additions & 39 deletions pages/app/Terms.js → layout/app/terms-of-service/component.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
import React from 'react';
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import renderHTML from 'react-render-html';

import withRedux from 'next-redux-wrapper';
import { initStore } from 'store';
import { getStaticData } from 'redactions/static_pages';

import Page from 'layout/page';
// components
import Layout from 'layout/layout/layout-app';

class Terms extends Page {
static async getInitialProps(context) {
const props = await super.getInitialProps(context);

// Get static data
await context.store.dispatch(getStaticData('terms-of-service'));
return { ...props };
}
class LayoutTermsOfService extends PureComponent {
static propTypes = { data: PropTypes.object.isRequired }

render() {
const { data } = this.props;
const styles = {};
const styles = { ...(data && data.photo) && { backgroundImage: `url(${process.env.STATIC_SERVER_URL}${data.photo.cover})` } };

if (!data) return null;

if (data && data.photo) {
styles.backgroundImage = `url(${process.env.STATIC_SERVER_URL}${data.photo.cover})`;
}

return (
<Layout
title="Terms of service"
// TO-DO: fill description
description="Terms of service description"
url={this.props.url}
user={this.props.user}
className="l-static"
>
<section className="l-content">
<header className="l-content-header">
<div className="cover" style={styles}>
<div
className="cover"
style={styles}
>
<div className="row">
<div className="column small-12">
<div className="content">
Expand All @@ -56,31 +44,17 @@ class Terms extends Page {
<div className="row align-center">
<div className="column small-12 medium-8">
<div className="c-terms">
{renderHTML(data.content || '')}
{renderHTML(data.content)}
</div>
</div>
</div>
</article>
</div>
}
</div>}
</div>
</section>
</Layout>
);
}
}

Terms.propTypes = {
data: PropTypes.object,
getStaticData: PropTypes.func
};

const mapStateToProps = state => ({
data: state.staticPages['terms-of-service']
});

const mapDispatchToProps = {
getStaticData
};

export default withRedux(initStore, mapStateToProps, mapDispatchToProps)(Terms);
export default LayoutTermsOfService;
8 changes: 8 additions & 0 deletions layout/app/terms-of-service/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { connect } from 'react-redux';

import LayoutTermsOfService from './component';

export default connect(
state => ({ data: state.staticPages['terms-of-service'] }),
null
)(LayoutTermsOfService);
2 changes: 2 additions & 0 deletions modules/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { handleModule } from 'redux-tools';

import dashboardsModule from './dashboards';
import staticPagesModules from './static-pages';
import topicsModule from './topics';

export default {
dashboards: handleModule(dashboardsModule),
staticPages: handleModule(staticPagesModules),
topics: handleModule(topicsModule)
};

32 changes: 32 additions & 0 deletions modules/static-pages/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createAction, createThunkAction } from 'redux-tools';

// service
import { fetchStaticPage } from 'services/static-page';

// actions
export const setContentPage = createAction('STATIC-PAGES__SET-CONTENT-PAGE');
export const setLoading = createAction('STATIC-PAGES__SET-LOADING');
export const setError = createAction('STATIC-PAGES__SET-ERROR');

export const getStaticPage = createThunkAction('STATIC-PAGES__GET-STATIC-PAGE',
page => (dispatch) => {
dispatch(setLoading({ key: page, value: true }));
dispatch(setError(true));

return fetchStaticPage(page)
.then((contentPage) => {
dispatch(setContentPage({ key: page, value: contentPage }));
dispatch(setLoading(false));
})
.catch((err) => {
dispatch(setError(err));
dispatch(setLoading(false));
});
});

export default {
setContentPage,
setLoading,
setError,
getStaticPage
};
5 changes: 5 additions & 0 deletions modules/static-pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as actions from './actions';
import * as reducers from './reducers';
import initialState from './initial-state';

export default { actions, reducers, initialState };
14 changes: 14 additions & 0 deletions modules/static-pages/initial-state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
loading: true,
error: null,
about: {},
apps: {},
'contribute-data': {},
'develop-app': {},
getInvolved: {},
'how-to': {},
'join-community': {},
'submit-an-insight': {},
'terms-of-service': {},
topics: {}
};
23 changes: 23 additions & 0 deletions modules/static-pages/reducers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as actions from './actions';

export default {
[actions.setContentPage]: (state, { payload }) =>
({
...state,
[payload.key]: {
...state[payload.key],
...payload.value
}
}),

[actions.setLoading]: (state, { payload }) =>
({
...state,
loading: payload
}),
[actions.setError]: (state, { payload }) =>
({
...state,
error: payload
})
};
88 changes: 0 additions & 88 deletions pages/app/Dashboards.js

This file was deleted.

4 changes: 2 additions & 2 deletions pages/app/about/component.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { PureComponent } from 'react';

// actions
import { getStaticData } from 'redactions/static_pages';
import { getStaticPage } from 'modules/static-pages/actions';

// components
import AboutLayout from 'layout/app/about';

class AboutPage extends PureComponent {
static async getInitialProps({ store }) {
// fetchs static data for about page
await store.dispatch(getStaticData('about'));
await store.dispatch(getStaticPage('about'));

return {};
}
Expand Down
4 changes: 2 additions & 2 deletions pages/app/attribution-requirements/component.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { PureComponent } from 'react';

// actions
import { getStaticData } from 'redactions/static_pages';
import { getStaticPage } from 'modules/static-pages/actions';

// components
import LayoutAttributionRequirements from 'layout/app/attribution-requirements';

class AttributionRequirementsPage extends PureComponent {
static async getInitialProps({ store }) {
// fetchs static data for attribution & requirements page
await store.dispatch(getStaticData('api-attribution-requirements'));
await store.dispatch(getStaticPage('api-attribution-requirements'));
return {};
}

Expand Down
Loading

0 comments on commit 1121303

Please sign in to comment.