diff --git a/src/components/App.js b/src/components/App.js index 76dbf57c..b51a631e 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -12,6 +12,8 @@ import theme from 'styles/theme' import i18n from 'renderer/i18n/electron' +import Onboarding from 'components/Onboarding' + import ThrowBlock from 'components/ThrowBlock' import Default from 'components/layout/Default' import Dev from 'components/layout/Dev' @@ -32,6 +34,7 @@ const App = ({ + {(__DEV__ || DEV_TOOLS) && } diff --git a/src/components/Onboarding/index.js b/src/components/Onboarding/index.js new file mode 100644 index 00000000..0a429687 --- /dev/null +++ b/src/components/Onboarding/index.js @@ -0,0 +1,145 @@ +// @flow + +import React, { PureComponent } from 'react' +import { compose } from 'redux' +import { translate } from 'react-i18next' +import { connect } from 'react-redux' +import styled from 'styled-components' + +import type { T } from 'types/common' + +import { saveSettings } from 'actions/settings' + +import Box from 'components/base/Box' +import Button from 'components/base/Button' + +const STEPS = [ + { + title: ({ t }) => t('onboarding:step1.title'), + render: ({ t }: StepProps) => {t('onboarding:step1.greetings')}, + }, + { + title: ({ t }) => t('onboarding:step2.title'), + render: ({ t }: StepProps) => {t('onboarding:step2.greetings')}, + }, + { + title: ({ t }) => t('onboarding:step3.title'), + render: ({ t }: StepProps) => ( + + {t('onboarding:step3.greetings')} + + {'step 3 image'} + + {t('onboarding:step3.description')} + + ), + }, + { + title: ({ t }) => t('onboarding:step4.title'), + render: ({ t }: StepProps) => {t('onboarding:step4.greetings')}, + }, +] + +const mapStateToProps = state => ({ + hasCompletedOnboarding: state.settings.hasCompletedOnboarding, +}) + +const mapDispatchToProps = { + saveSettings, +} + +type Props = { + t: T, + hasCompletedOnboarding: boolean, + saveSettings: Function, +} + +type StepProps = { + t: T, +} + +type State = { + stepIndex: number, +} + +class Onboarding extends PureComponent { + state = { + stepIndex: 0, + } + + prev = () => this.setState({ stepIndex: Math.max(0, this.state.stepIndex - 1) }) + next = () => this.setState({ stepIndex: Math.min(STEPS.length - 1, this.state.stepIndex + 1) }) + finish = () => this.props.saveSettings({ hasCompletedOnboarding: true }) + + render() { + const { hasCompletedOnboarding, t } = this.props + const { stepIndex } = this.state + + if (hasCompletedOnboarding) { + return null + } + + const step = STEPS[stepIndex] + + if (!step) { + return null + } + + const stepProps = { + t, + } + + return ( + + + + + {stepIndex === STEPS.length - 1 ? ( + + ) : ( + + )} + + {step.title(stepProps)} + {step.render(stepProps)} + + + ) + } +} + +const Container = styled(Box).attrs({ + bg: 'white', + p: 6, + align: 'center', + justify: 'center', +})` + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + z-index: 100; +` + +const Inner = styled(Box).attrs({ + bg: 'lightGraphite', + p: 4, +})` + border: 1px solid rgba(0, 0, 0, 0.1); + height: 400px; + width: 400px; + border-radius: 3px; +` + +const StepTitle = styled(Box).attrs({ + fontSize: 8, +})`` + +export default compose(connect(mapStateToProps, mapDispatchToProps), translate())(Onboarding) diff --git a/src/reducers/settings.js b/src/reducers/settings.js index 7fe0b7ce..a0885465 100644 --- a/src/reducers/settings.js +++ b/src/reducers/settings.js @@ -12,6 +12,7 @@ import type { State } from 'reducers' export type SettingsState = Object const defaultState: SettingsState = { + hasCompletedOnboarding: false, username: 'Anonymous', counterValue: 'USD', language: 'en', diff --git a/src/types/common.js b/src/types/common.js index 5435fd60..2f8de8f0 100644 --- a/src/types/common.js +++ b/src/types/common.js @@ -29,6 +29,7 @@ export type CurrenciesSettings = { } export type Settings = { + hasCompletedOnboarding: boolean, language: string, orderAccounts: string, username: string,