2019-05-17 03:04:52 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Component } from '@wordpress/element';
|
2019-05-27 16:37:02 +00:00
|
|
|
import { filter } from 'lodash';
|
|
|
|
import classnames from 'classnames';
|
2019-05-17 03:04:52 +00:00
|
|
|
|
2019-11-06 00:26:08 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { updateQueryString } from '@woocommerce/navigation';
|
|
|
|
|
2019-05-17 03:04:52 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-05-27 16:37:02 +00:00
|
|
|
import { Stepper } from '@woocommerce/components';
|
2019-05-17 03:04:52 +00:00
|
|
|
import HeaderLogo from './header-logo';
|
2019-05-27 16:37:02 +00:00
|
|
|
|
2019-05-17 03:04:52 +00:00
|
|
|
export default class ProfileWizardHeader extends Component {
|
2019-05-27 16:37:02 +00:00
|
|
|
renderStepper() {
|
2019-11-06 00:26:08 +00:00
|
|
|
const { currentStep, steps } = this.props;
|
2020-02-14 02:23:21 +00:00
|
|
|
const visibleSteps = filter( steps, ( step ) => !! step.label );
|
|
|
|
const currentStepIndex = visibleSteps.findIndex(
|
|
|
|
( step ) => step.key === currentStep
|
|
|
|
);
|
2019-11-06 00:26:08 +00:00
|
|
|
|
|
|
|
visibleSteps.map( ( step, index ) => {
|
|
|
|
const previousStep = visibleSteps[ index - 1 ];
|
|
|
|
|
|
|
|
if ( index < currentStepIndex ) {
|
|
|
|
step.isComplete = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! previousStep || previousStep.isComplete ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
step.onClick = ( key ) => updateQueryString( { step: key } );
|
2019-11-06 00:26:08 +00:00
|
|
|
}
|
|
|
|
return step;
|
|
|
|
} );
|
|
|
|
|
|
|
|
return <Stepper steps={ visibleSteps } currentStep={ currentStep } />;
|
2019-05-27 16:37:02 +00:00
|
|
|
}
|
2019-11-06 00:26:08 +00:00
|
|
|
|
2019-05-17 03:04:52 +00:00
|
|
|
render() {
|
2020-02-14 02:23:21 +00:00
|
|
|
const currentStep = this.props.steps.find(
|
|
|
|
( s ) => s.key === this.props.currentStep
|
|
|
|
);
|
2019-05-27 16:37:02 +00:00
|
|
|
const showStepper = ! currentStep || ! currentStep.label ? false : true;
|
|
|
|
const classes = classnames( 'woocommerce-profile-wizard__header', {
|
|
|
|
'is-stepper': showStepper,
|
|
|
|
} );
|
2020-02-14 02:23:21 +00:00
|
|
|
return (
|
|
|
|
<div className={ classes }>
|
|
|
|
{ showStepper ? this.renderStepper() : <HeaderLogo /> }
|
|
|
|
</div>
|
|
|
|
);
|
2019-05-17 03:04:52 +00:00
|
|
|
}
|
|
|
|
}
|