diff --git a/src/App.jsx b/src/App.jsx
index 043b61b..a8f7711 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -7,16 +7,14 @@ import ruLocaleData from 'react-intl/locale-data/ru';
import beLocaleData from 'react-intl/locale-data/be';
import ukLocaleData from 'react-intl/locale-data/uk';
-// till we have not so many locales, we can require their data at once
addLocaleData(enLocaleData);
addLocaleData(ruLocaleData);
addLocaleData(beLocaleData);
addLocaleData(ukLocaleData);
-const SUPPORTED_LANGUAGES = ['ru', 'en', 'be', 'uk'];
-const DEFAULT_LANGUAGE = 'en';
+import { SUPPORTED_LANGUAGES, DEFAULT_LANGUAGE } from './constants';
-export default function App({type, payload = {}, debug = false}) {
+export default function App({type, payload = {}}) {
let {locale} = payload;
if (!locale || SUPPORTED_LANGUAGES.indexOf(locale) === -1) {
@@ -28,16 +26,7 @@ export default function App({type, payload = {}, debug = false}) {
return (
- {debug
- ? (
-
- Hello world
-
-
- ) : (
-
- )
- }
+
);
}
@@ -46,6 +35,5 @@ App.propTypes = {
type: PropTypes.string.isRequired,
payload: PropTypes.shape({
locale: PropTypes.string
- }),
- debug: PropTypes.bool
+ })
};
diff --git a/src/constants.js b/src/constants.js
new file mode 100644
index 0000000..d241e0a
--- /dev/null
+++ b/src/constants.js
@@ -0,0 +1,2 @@
+export const SUPPORTED_LANGUAGES = ['ru', 'en', 'be', 'uk'];
+export const DEFAULT_LANGUAGE = 'en';
diff --git a/src/devTools/DevApp.jsx b/src/devTools/DevApp.jsx
new file mode 100644
index 0000000..2f63e64
--- /dev/null
+++ b/src/devTools/DevApp.jsx
@@ -0,0 +1,94 @@
+import { Component } from 'react';
+
+import App from 'App';
+
+import List from './List';
+
+import { DEFAULT_LANGUAGE, SUPPORTED_LANGUAGES } from 'constants';
+
+const EVAILABLE_EMAILS = require.context('emails', true, /index\.js$/).keys().map((path) => path.split('/')[1]);
+
+export default class DevApp extends Component {
+ state = {
+ locale: DEFAULT_LANGUAGE,
+ type: EVAILABLE_EMAILS[0],
+ fixture: 'default',
+ isMinimized: false
+ };
+
+ componentWillMount() {
+ try {
+ const lastState = JSON.parse(localStorage.getItem('emailRendererState'));
+ this.setState(lastState);
+ } catch (err) {/* no state was saved */}
+ }
+
+ componentWillUpdate(nextProps, nextState) {
+ localStorage.setItem('emailRendererState', JSON.stringify(nextState));
+ }
+
+ render() {
+ const {locale, type, isMinimized} = this.state;
+ let {fixture} = this.state;
+
+ let fixturesAvailable = {};
+ try {
+ fixturesAvailable = require(`emails/${type}/fixtures`).default;
+ } catch (err) {/* no fixtures available */}
+
+ if (!fixturesAvailable[fixture]) {
+ fixture = 'default';
+ }
+
+ const payload = {
+ locale,
+ ...(fixturesAvailable[fixture] || {})
+ };
+
+ return (
+
+ );
+ }
+
+ onLocaleChange = (locale) => this.setState({locale});
+ onTypeChange = (type) => this.setState({type});
+ onFixtureChange = (fixture) => this.setState({fixture});
+ onMinimizeToggle = (event) => {
+ event.preventDefault();
+
+ this.setState({
+ isMinimized: !this.state.isMinimized
+ });
+ }
+}
diff --git a/src/devTools/List.jsx b/src/devTools/List.jsx
new file mode 100644
index 0000000..89b417a
--- /dev/null
+++ b/src/devTools/List.jsx
@@ -0,0 +1,30 @@
+import { PropTypes } from 'react';
+
+export default function List({label, items, active, onChange}) {
+ return (
+
+ );
+}
+
+List.propTypes = {
+ label: PropTypes.string.isRequired,
+ items: PropTypes.arrayOf(PropTypes.string).isRequired,
+ active: PropTypes.string,
+ onChange: PropTypes.func
+};
diff --git a/src/devTools/index.js b/src/devTools/index.js
new file mode 100644
index 0000000..605753e
--- /dev/null
+++ b/src/devTools/index.js
@@ -0,0 +1,3 @@
+import DevApp from './DevApp';
+
+export default DevApp;
diff --git a/src/emails/activation/Activation.jsx b/src/emails/activation/Activation.jsx
new file mode 100644
index 0000000..2f3a430
--- /dev/null
+++ b/src/emails/activation/Activation.jsx
@@ -0,0 +1,7 @@
+export default function Activation() {
+ return (
+
+ Activated!
+
+ );
+}
diff --git a/src/emails/activation/index.js b/src/emails/activation/index.js
new file mode 100644
index 0000000..d7979d6
--- /dev/null
+++ b/src/emails/activation/index.js
@@ -0,0 +1,3 @@
+import Activation from './Activation';
+
+export default Activation;
diff --git a/src/emails/register/fixtures.js b/src/emails/register/fixtures.js
new file mode 100644
index 0000000..ab99df6
--- /dev/null
+++ b/src/emails/register/fixtures.js
@@ -0,0 +1,9 @@
+export default {
+ default: {
+ username: 'ErickSkrauch'
+ },
+
+ SleepWalker: {
+ username: 'SleepWalker'
+ }
+};
diff --git a/src/index.js b/src/index.js
index 41cb848..5630bb0 100644
--- a/src/index.js
+++ b/src/index.js
@@ -5,16 +5,16 @@ import ReactDOMServer from 'react-dom/server';
import App from 'App';
-const isCli = typeof window === 'undefined';
+/* global process: false */
+if (process.env.NODE_ENV !== 'production') {
+ const DevApp = require('devTools').default;
-if (isCli) {
- module.exports = {
- default: (props) =>
- ReactDOMServer.renderToStaticMarkup()
- };
-} else {
ReactDOM.render(
- ,
+ ,
document.getElementById('app')
);
}
+
+export default function(props) {
+ return ReactDOMServer.renderToStaticMarkup();
+}