Add ability to blacklist onboarding steps
This commit is contained in:
@@ -6,9 +6,11 @@ import { zIndex } from 'ts/utils/style';
|
|||||||
|
|
||||||
export interface OnboardingFlowProps {
|
export interface OnboardingFlowProps {
|
||||||
steps: Step[];
|
steps: Step[];
|
||||||
|
blacklistedStepIndices: number[];
|
||||||
stepIndex: number;
|
stepIndex: number;
|
||||||
isRunning: boolean;
|
isRunning: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
|
setOnboardingStep: (stepIndex: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const joyrideStyleOptions: StyleOptions = {
|
const joyrideStyleOptions: StyleOptions = {
|
||||||
@@ -17,16 +19,17 @@ const joyrideStyleOptions: StyleOptions = {
|
|||||||
|
|
||||||
// Wrapper around Joyride with defaults and styles set
|
// Wrapper around Joyride with defaults and styles set
|
||||||
export class OnboardingFlow extends React.Component<OnboardingFlowProps> {
|
export class OnboardingFlow extends React.Component<OnboardingFlowProps> {
|
||||||
private _joyrideRef: React.RefObject<Joyride>;
|
public componentDidMount(): void {
|
||||||
constructor(props: OnboardingFlowProps) {
|
this._setOnboardingStepBasedOnBlacklist(this.props.stepIndex);
|
||||||
super(props);
|
}
|
||||||
this._joyrideRef = React.createRef();
|
|
||||||
|
public componentWillReceiveProps(nextProps: OnboardingFlowProps): void {
|
||||||
|
this._setOnboardingStepBasedOnBlacklist(nextProps.stepIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
return (
|
return (
|
||||||
<Joyride
|
<Joyride
|
||||||
ref={this._joyrideRef}
|
|
||||||
run={this.props.isRunning}
|
run={this.props.isRunning}
|
||||||
debug={true}
|
debug={true}
|
||||||
steps={this.props.steps}
|
steps={this.props.steps}
|
||||||
@@ -37,6 +40,49 @@ export class OnboardingFlow extends React.Component<OnboardingFlowProps> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _setOnboardingStepBasedOnBlacklist(nextIndex: number): void {
|
||||||
|
const blacklistedSteps = this.props.blacklistedStepIndices;
|
||||||
|
const newStepIndex = this._adjustedStepBasedOnBlacklist(
|
||||||
|
this.props.stepIndex,
|
||||||
|
nextIndex,
|
||||||
|
this.props.steps.length,
|
||||||
|
blacklistedSteps,
|
||||||
|
);
|
||||||
|
this.props.setOnboardingStep(newStepIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _adjustedStepBasedOnBlacklist(
|
||||||
|
currentStep: number,
|
||||||
|
nextStep: number,
|
||||||
|
totalSteps: number,
|
||||||
|
blacklistedSteps: number[],
|
||||||
|
): number {
|
||||||
|
if (!blacklistedSteps.includes(nextStep)) {
|
||||||
|
return nextStep;
|
||||||
|
}
|
||||||
|
let newStep = nextStep;
|
||||||
|
const op = nextStep >= currentStep ? _.add : _.subtract;
|
||||||
|
let didSearch = false;
|
||||||
|
while (blacklistedSteps.includes(newStep)) {
|
||||||
|
newStep = op(newStep, 1);
|
||||||
|
if (newStep < 0) {
|
||||||
|
if (didSearch) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
newStep = totalSteps - 1;
|
||||||
|
didSearch = true;
|
||||||
|
}
|
||||||
|
if (newStep >= totalSteps) {
|
||||||
|
if (didSearch) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
newStep = 0;
|
||||||
|
didSearch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newStep;
|
||||||
|
}
|
||||||
|
|
||||||
private _handleChange(data: CallbackData): void {
|
private _handleChange(data: CallbackData): void {
|
||||||
switch (data.action) {
|
switch (data.action) {
|
||||||
case 'close':
|
case 'close':
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import * as _ from 'lodash';
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Step } from 'react-joyride';
|
import { Step } from 'react-joyride';
|
||||||
|
|
||||||
|
import { black } from 'material-ui/styles/colors';
|
||||||
import { OnboardingFlow } from 'ts/components/onboarding/onboarding_flow';
|
import { OnboardingFlow } from 'ts/components/onboarding/onboarding_flow';
|
||||||
import { ProviderType } from 'ts/types';
|
import { ProviderType } from 'ts/types';
|
||||||
import { utils } from 'ts/utils/utils';
|
import { utils } from 'ts/utils/utils';
|
||||||
@@ -9,21 +10,47 @@ import { utils } from 'ts/utils/utils';
|
|||||||
export interface PortalOnboardingFlowProps {
|
export interface PortalOnboardingFlowProps {
|
||||||
stepIndex: number;
|
stepIndex: number;
|
||||||
isRunning: boolean;
|
isRunning: boolean;
|
||||||
onClose: () => void;
|
|
||||||
userAddress: string;
|
userAddress: string;
|
||||||
providerType: ProviderType;
|
providerType: ProviderType;
|
||||||
injectedProviderName: string;
|
injectedProviderName: string;
|
||||||
blockchainIsLoaded: boolean;
|
blockchainIsLoaded: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
setOnboardingStep: (stepIndex: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const steps: Step[] = [
|
||||||
|
{
|
||||||
|
target: '.wallet',
|
||||||
|
content:
|
||||||
|
'Before you begin, you need to connect to a wallet. This will be used across all 0x relayers and dApps',
|
||||||
|
placement: 'right',
|
||||||
|
disableBeacon: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
target: '.wallet',
|
||||||
|
content: 'Unlock your metamask extension to begin',
|
||||||
|
placement: 'right',
|
||||||
|
disableBeacon: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
target: '.wallet',
|
||||||
|
content:
|
||||||
|
'In order to start trading on any 0x relayer in the 0x ecosystem, you need to complete two simple steps',
|
||||||
|
placement: 'right',
|
||||||
|
disableBeacon: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
export class PortalOnboardingFlow extends React.Component<PortalOnboardingFlowProps> {
|
export class PortalOnboardingFlow extends React.Component<PortalOnboardingFlowProps> {
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
return (
|
return (
|
||||||
<OnboardingFlow
|
<OnboardingFlow
|
||||||
steps={this._getSteps()}
|
steps={steps}
|
||||||
|
blacklistedStepIndices={this._getBlacklistedStepIndices()}
|
||||||
stepIndex={this.props.stepIndex}
|
stepIndex={this.props.stepIndex}
|
||||||
isRunning={this.props.isRunning}
|
isRunning={this.props.isRunning}
|
||||||
onClose={this.props.onClose}
|
onClose={this.props.onClose}
|
||||||
|
setOnboardingStep={this.props.setOnboardingStep}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -32,40 +59,18 @@ export class PortalOnboardingFlow extends React.Component<PortalOnboardingFlowPr
|
|||||||
return !_.isEmpty(this.props.userAddress);
|
return !_.isEmpty(this.props.userAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getSteps(): Step[] {
|
private _getBlacklistedStepIndices(): number[] {
|
||||||
const allSteps: Step[] = [
|
|
||||||
{
|
|
||||||
target: '.wallet',
|
|
||||||
content:
|
|
||||||
'Before you begin, you need to connect to a wallet. This will be used across all 0x relayers and dApps',
|
|
||||||
placement: 'right',
|
|
||||||
disableBeacon: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
target: '.wallet',
|
|
||||||
content: 'Unlock your metamask extension to begin',
|
|
||||||
placement: 'right',
|
|
||||||
disableBeacon: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
target: '.wallet',
|
|
||||||
content:
|
|
||||||
'In order to start trading on any 0x relayer in the 0x ecosystem, you need to complete two simple steps',
|
|
||||||
placement: 'right',
|
|
||||||
disableBeacon: true,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
const [noMetamaskStep, lockedMetamaskStep, ...restOfSteps] = allSteps;
|
|
||||||
if (this._isAddressAvailable()) {
|
if (this._isAddressAvailable()) {
|
||||||
return restOfSteps;
|
return [0, 1];
|
||||||
}
|
}
|
||||||
const isExternallyInjected = utils.isExternallyInjected(
|
const isExternallyInjected = utils.isExternallyInjected(
|
||||||
this.props.providerType,
|
this.props.providerType,
|
||||||
this.props.injectedProviderName,
|
this.props.injectedProviderName,
|
||||||
);
|
);
|
||||||
|
const twoAndOn = _.range(2, steps.length);
|
||||||
if (isExternallyInjected) {
|
if (isExternallyInjected) {
|
||||||
return [lockedMetamaskStep, ...restOfSteps];
|
return [0].concat(twoAndOn);
|
||||||
}
|
}
|
||||||
return allSteps;
|
return twoAndOn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ interface ConnectedState {
|
|||||||
|
|
||||||
interface ConnectedDispatch {
|
interface ConnectedDispatch {
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
|
setOnboardingStep: (stepIndex: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state: State): ConnectedState => ({
|
const mapStateToProps = (state: State): ConnectedState => ({
|
||||||
@@ -37,6 +38,12 @@ const mapDispatchToProps = (dispatch: Dispatch<State>): ConnectedDispatch => ({
|
|||||||
data: false,
|
data: false,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
setOnboardingStep: (stepIndex: number): void => {
|
||||||
|
dispatch({
|
||||||
|
type: ActionTypes.UpdatePortalOnboardingStep,
|
||||||
|
data: stepIndex,
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const PortalOnboardingFlow: React.ComponentClass<PortalOnboardingFlowProps> = connect(
|
export const PortalOnboardingFlow: React.ComponentClass<PortalOnboardingFlowProps> = connect(
|
||||||
|
|||||||
Reference in New Issue
Block a user