committed by
NastiaS
6 changed files with 193 additions and 80 deletions
@ -0,0 +1,32 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
import React from 'react' |
||||
|
import { connect } from 'react-redux' |
||||
|
import findIndex from 'lodash/findIndex' |
||||
|
|
||||
|
import type { OnboardingState } from 'reducers/onboarding' |
||||
|
|
||||
|
import Breadcrumb from 'components/Breadcrumb' |
||||
|
|
||||
|
const mapStateToProps = state => ({ |
||||
|
onboarding: state.onboarding, |
||||
|
}) |
||||
|
|
||||
|
type Props = { |
||||
|
onboarding: OnboardingState, |
||||
|
} |
||||
|
|
||||
|
function OnboardingBreadcrumb(props: Props) { |
||||
|
const { onboarding } = props |
||||
|
const { stepName } = onboarding |
||||
|
|
||||
|
const filteredSteps = onboarding.steps |
||||
|
.filter(step => !step.external) |
||||
|
.map(step => ({ ...step, label: step.label })) // TODO: translate
|
||||
|
|
||||
|
const stepIndex = findIndex(filteredSteps, s => s.name === stepName) |
||||
|
|
||||
|
return <Breadcrumb currentStep={stepIndex} items={filteredSteps} /> |
||||
|
} |
||||
|
|
||||
|
export default connect(mapStateToProps)(OnboardingBreadcrumb) |
@ -0,0 +1,18 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
import React from 'react' |
||||
|
|
||||
|
import Button from 'components/base/Button' |
||||
|
import Box from 'components/base/Box' |
||||
|
|
||||
|
import type { StepProps } from '..' |
||||
|
|
||||
|
export default (props: StepProps) => { |
||||
|
const { nextStep } = props |
||||
|
return ( |
||||
|
<Box> |
||||
|
hey im step init |
||||
|
<Button onClick={() => nextStep()}>press me for going to prev</Button> |
||||
|
</Box> |
||||
|
) |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
import React from 'react' |
||||
|
|
||||
|
import Button from 'components/base/Button' |
||||
|
|
||||
|
import type { StepProps } from '..' |
||||
|
|
||||
|
export default (props: StepProps) => { |
||||
|
const { jumpStep } = props |
||||
|
return ( |
||||
|
<div> |
||||
|
hey im step user choice |
||||
|
<Button onClick={() => jumpStep('init')}>press me for going to prev</Button> |
||||
|
</div> |
||||
|
) |
||||
|
} |
@ -0,0 +1,84 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
import { handleActions, createAction } from 'redux-actions' |
||||
|
|
||||
|
type Step = { |
||||
|
name: string, |
||||
|
external?: boolean, |
||||
|
label?: string, |
||||
|
options: { |
||||
|
showFooter: boolean, |
||||
|
showBackground: boolean, |
||||
|
showBreadcrumb: boolean, |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
export type OnboardingState = { |
||||
|
stepIndex: number, |
||||
|
stepName: string, // TODO: specify that the string comes from Steps type
|
||||
|
steps: Step[], |
||||
|
} |
||||
|
|
||||
|
const state: OnboardingState = { |
||||
|
stepIndex: 0, |
||||
|
stepName: 'init', |
||||
|
steps: [ |
||||
|
{ |
||||
|
name: 'init', |
||||
|
external: true, |
||||
|
options: { |
||||
|
showFooter: false, |
||||
|
showBackground: true, |
||||
|
showBreadcrumb: false, |
||||
|
}, |
||||
|
}, |
||||
|
{ |
||||
|
name: 'userChoice', |
||||
|
label: 'something:translated', |
||||
|
options: { |
||||
|
showFooter: false, |
||||
|
showBackground: true, |
||||
|
showBreadcrumb: true, |
||||
|
}, |
||||
|
}, |
||||
|
], |
||||
|
} |
||||
|
|
||||
|
const handlers = { |
||||
|
ONBOARDING_NEXT_STEP: state => { |
||||
|
const step = state.steps.find(step => step.name === state.stepName) |
||||
|
if (!step) { |
||||
|
return state |
||||
|
} |
||||
|
const index = state.steps.indexOf(step) |
||||
|
if (index > state.steps.length - 2) { |
||||
|
return state |
||||
|
} |
||||
|
return { ...state, stepName: state.steps[index + 1].name, stepIndex: index + 1 } |
||||
|
}, |
||||
|
ONBOARDING_PREV_STEP: state => { |
||||
|
const step = state.steps.find(step => step.name === state.stepName) |
||||
|
if (!step) { |
||||
|
return state |
||||
|
} |
||||
|
const index = state.steps.indexOf(step) |
||||
|
if (index < 1) { |
||||
|
return state |
||||
|
} |
||||
|
return { ...state, stepName: state.steps[index - 1].name, stepIndex: index - 1 } |
||||
|
}, |
||||
|
ONBOARDING_JUMP_STEP: (state, { payload: stepName }) => { |
||||
|
const step = state.steps.find(step => step.name === stepName) |
||||
|
if (!step) { |
||||
|
return state |
||||
|
} |
||||
|
const index = state.steps.indexOf(step) |
||||
|
return { ...state, stepName: step.name, stepIndex: index } |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
export default handleActions(handlers, state) |
||||
|
|
||||
|
export const nextStep = createAction('ONBOARDING_NEXT_STEP') |
||||
|
export const prevStep = createAction('ONBOARDING_PREV_STEP') |
||||
|
export const jumpStep = createAction('ONBOARDING_JUMP_STEP') |
Loading…
Reference in new issue