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 { Stepper } from '@woocommerce/components';
|
2020-08-13 02:05:22 +00:00
|
|
|
import { updateQueryString } from '@woocommerce/navigation';
|
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
|
|
|
|
);
|
2020-03-09 23:16:21 +00:00
|
|
|
|
|
|
|
if ( ! currentStep || ! currentStep.label ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
return (
|
2020-03-09 23:16:21 +00:00
|
|
|
<div className="woocommerce-profile-wizard__header">
|
|
|
|
{ this.renderStepper() }
|
2020-02-14 02:23:21 +00:00
|
|
|
</div>
|
|
|
|
);
|
2019-05-17 03:04:52 +00:00
|
|
|
}
|
|
|
|
}
|