import React, { useCallback } from "react"; import { useWizard } from "react-use-wizard"; import { ArrowBackIcon, Pressable, View } from "native-base"; import { ErrorModal } from "../../../core/web3"; import { TransText } from "../../../core/layout"; /* Step Reference ## Segmentation 0. SegmentationScreen 1. SegmentationDispute 2. SegmentationThanks 3. OffersAgreement 4. SegmentationConfirmation */ export const WizardHeader = ({ onDone, withNavBar, error, onClose, stepHistory, onExit, ...props }: { onDone: (error?: Error) => Promise; withNavBar: boolean; error: any; stepHistory?: number[]; onClose?: any; onExit?: () => void; }) => { const { activeStep, isFirstStep, isLastStep, stepCount, goToStep, previousStep } = useWizard(); const handleBack = useCallback(() => { if (onExit) { onExit(); return; } if (isFirstStep) { void onDone(); return; } //wip. alternative flow needed for segmentation flow if (stepHistory) { const hasDisputed = [2].some(value => stepHistory.includes(value)); if (activeStep === 3 && !hasDisputed) { goToStep(0); return; } if (activeStep === 4 && hasDisputed) { goToStep(2); return; } } previousStep(); }, [isFirstStep, stepHistory]); return ( <> goToStep(0))} overlay="dark" /> {withNavBar ? ( 1 ? 0 : 4} paddingRight={4} mb={6} {...props} > {(isLastStep && stepCount > 1) || // handling wizard with only one step where first/last is equal (eg. onboardwizard) (isFirstStep && !onExit) || // no onExit handler, user has to finish flow to exit // for segmentation: // if user disputes, we don't want the user to navigate back from DisputeThanks (stepHistory && [1, 2].some(value => stepHistory.includes(value)) && activeStep === 2) ? null : ( )} ) : null} ); };