-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "feat: 🔥 remove tour guide from tradershub"
This reverts commit fed9653.
- Loading branch information
1 parent
6f5fc89
commit ada5cb2
Showing
15 changed files
with
333 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import React from 'react'; | ||
import { Step, Locale } from 'react-joyride'; | ||
import { Text, SpanButton, Icon } from '@deriv/components'; | ||
import { Localize, localize } from '@deriv/translations'; | ||
import { isMobile } from '@deriv/shared'; | ||
import 'Components/toggle-account-type/toggle-account-type.scss'; | ||
|
||
const stepProps = { | ||
disableBeacon: true, | ||
disableOverlayClose: true, | ||
}; | ||
|
||
export const tour_step_config: Step[] = [ | ||
{ | ||
title: ( | ||
<React.Fragment> | ||
<Text as='p' weight='bold' color='brand-red-coral'> | ||
<Localize i18n_default_text='Switch accounts' /> | ||
</Text> | ||
<div className='toggle-account-type__divider' /> | ||
</React.Fragment> | ||
), | ||
content: ( | ||
<Text as='p'> | ||
<Localize i18n_default_text='You can switch between real and demo accounts.' /> | ||
</Text> | ||
), | ||
target: '.account-type-dropdown--parent', | ||
...stepProps, | ||
}, | ||
{ | ||
title: ( | ||
<React.Fragment> | ||
<Text as='p' weight='bold' color='brand-red-coral'> | ||
<Localize i18n_default_text='Choice of regulation' /> | ||
</Text> | ||
<div className='toggle-account-type__divider' /> | ||
</React.Fragment> | ||
), | ||
content: ( | ||
<Text as='p'> | ||
<Localize | ||
i18n_default_text='You can create real accounts under EU or non-EU regulation. Click the <0><0/> icon to learn more about these accounts.' | ||
components={[ | ||
<Text key={0}> | ||
<Icon icon='IcInfoOutline' /> | ||
</Text>, | ||
]} | ||
/> | ||
</Text> | ||
), | ||
target: isMobile() ? '.main-title-bar-mobile--regulator' : '.regulators-switcher__container', | ||
...stepProps, | ||
}, | ||
{ | ||
title: ( | ||
<React.Fragment> | ||
<Text as='p' weight='bold' color='brand-red-coral'> | ||
<Localize i18n_default_text="Trader's Hub tour" /> | ||
</Text> | ||
<div className='toggle-account-type__divider' /> | ||
</React.Fragment> | ||
), | ||
content: ( | ||
<Text as='p'> | ||
<Localize i18n_default_text='Click here if you ever need to repeat this tour.' /> | ||
</Text> | ||
), | ||
target: '.traders-hub-header__tradershub--onboarding--logo', | ||
...stepProps, | ||
}, | ||
]; | ||
|
||
export const tour_step_config_high_risk: Step[] = [ | ||
{ | ||
title: ( | ||
<React.Fragment> | ||
<Text as='p' weight='bold' color='brand-red-coral'> | ||
<Localize i18n_default_text='Switch accounts' /> | ||
</Text> | ||
<div className='toggle-account-type__divider' /> | ||
</React.Fragment> | ||
), | ||
content: ( | ||
<Text as='p'> | ||
<Localize i18n_default_text='You can switch between real and demo accounts.' /> | ||
</Text> | ||
), | ||
target: '.account-type-dropdown--parent', | ||
...stepProps, | ||
}, | ||
{ | ||
title: ( | ||
<React.Fragment> | ||
<Text as='p' weight='bold' color='brand-red-coral'> | ||
<Localize i18n_default_text="Trader's Hub tour" /> | ||
</Text> | ||
<div className='toggle-account-type__divider' /> | ||
</React.Fragment> | ||
), | ||
content: ( | ||
<Text as='p'> | ||
<Localize i18n_default_text='Click here if you ever need to repeat this tour.' /> | ||
</Text> | ||
), | ||
target: '.traders-hub-header__tradershub--onboarding--logo', | ||
...stepProps, | ||
}, | ||
]; | ||
|
||
export const getHighRiskTourStepLocale = (): Locale => ({ | ||
back: <SpanButton has_effect text={localize('Repeat tour')} secondary medium />, | ||
last: <Localize i18n_default_text='OK' />, | ||
next: <Localize i18n_default_text='Next' />, | ||
}); | ||
|
||
export const getTourStepLocale = (): Locale => ({ | ||
back: <SpanButton has_effect text={localize('Back')} secondary medium />, | ||
last: <Localize i18n_default_text='OK' />, | ||
next: <Localize i18n_default_text='Next' />, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Styles } from 'react-joyride'; | ||
|
||
type TJoyrideStyles = Pick<Styles, 'options' | 'tooltipTitle' | 'tooltipContent' | 'buttonNext'>; | ||
|
||
const tourStyles = { | ||
options: { | ||
width: 350, | ||
}, | ||
tooltipTitle: { | ||
color: 'var(--brand-red-coral)', | ||
textAlign: 'left', | ||
}, | ||
tooltipContent: { | ||
textAlign: 'left', | ||
fontSize: '1.6rem', | ||
padding: '3rem 0 1.6rem 0', | ||
wordBreak: 'break-word', | ||
whiteSpace: 'pre-wrap', | ||
}, | ||
buttonNext: { | ||
padding: '0.9rem', | ||
fontSize: '1.5rem', | ||
fontWeight: 'bold', | ||
outline: 'none', | ||
}, | ||
} as const; | ||
|
||
export const tour_styles: TJoyrideStyles = { | ||
options: tourStyles.options, | ||
tooltipTitle: tourStyles.tooltipTitle, | ||
tooltipContent: tourStyles.tooltipContent, | ||
buttonNext: tourStyles.buttonNext, | ||
}; | ||
|
||
export const tour_styles_dark_mode: TJoyrideStyles = { | ||
options: { | ||
...tourStyles.options, | ||
backgroundColor: 'var(--general-section-3)', | ||
arrowColor: 'var(--general-section-3)', | ||
}, | ||
tooltipTitle: tourStyles.tooltipTitle, | ||
tooltipContent: tourStyles.tooltipContent, | ||
buttonNext: tourStyles.buttonNext, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react'; | ||
import Joyride, { CallBackProps, STATUS, EVENTS, ACTIONS } from 'react-joyride'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { | ||
tour_step_config, | ||
getTourStepLocale, | ||
tour_step_config_high_risk, | ||
getHighRiskTourStepLocale, | ||
} from 'Constants/tour-steps-config'; | ||
import { tour_styles, tour_styles_dark_mode } from 'Constants/tour-steps-styles'; | ||
import { useStores } from 'Stores/index'; | ||
import { ContentFlag } from '@deriv/shared'; | ||
import { useTradersHubTracking } from 'Hooks/index'; | ||
import { localize } from '@deriv/translations'; | ||
import { SpanButton } from '@deriv/components'; | ||
|
||
const TourGuide = () => { | ||
const { traders_hub, ui } = useStores(); | ||
const { is_tour_open, toggleIsTourOpen, content_flag, setIsFirstTimeVisit } = traders_hub; | ||
const { is_dark_mode_on, should_trigger_tour_guide, setShouldTriggerTourGuide } = ui; | ||
|
||
const [joyride_index, setJoyrideIndex] = React.useState(0); | ||
const tour_step_locale = getTourStepLocale(); | ||
const high_risk_tour_step_locale = getHighRiskTourStepLocale(); | ||
const low_risk = content_flag === ContentFlag.LOW_RISK_CR_NON_EU || content_flag === ContentFlag.LOW_RISK_CR_EU; | ||
|
||
const { trackLastStep, trackStepForward, trackOnboardingRestart } = useTradersHubTracking(); | ||
|
||
const handleNextAction = (index: number) => { | ||
trackStepForward(7); | ||
setJoyrideIndex(index + 1); | ||
}; | ||
|
||
const handlePrevAction = (index: number) => { | ||
if (tour_step_config.length === joyride_index + 1) { | ||
trackLastStep(); | ||
trackOnboardingRestart(); | ||
setIsFirstTimeVisit(false); | ||
setJoyrideIndex(0); | ||
} else { | ||
setJoyrideIndex(index - 1); | ||
} | ||
}; | ||
|
||
const callbackHandle = (data: CallBackProps) => { | ||
const { action, index, type, status } = data; | ||
const finishedStatuses: string[] = [STATUS.FINISHED]; | ||
const skipTypes: string[] = [EVENTS.STEP_AFTER, EVENTS.TARGET_NOT_FOUND]; | ||
|
||
if (finishedStatuses.includes(status)) { | ||
toggleIsTourOpen(false); | ||
setShouldTriggerTourGuide(false); | ||
setJoyrideIndex(0); | ||
return; | ||
} | ||
|
||
if (!skipTypes.includes(type)) { | ||
return; | ||
} | ||
|
||
if (action === ACTIONS.NEXT) { | ||
handleNextAction(index); | ||
} else if (action === ACTIONS.PREV) { | ||
handlePrevAction(index); | ||
} | ||
}; | ||
|
||
if (tour_step_config.length === joyride_index + 1) { | ||
tour_step_locale.back = <SpanButton has_effect text={localize('Repeat tour')} secondary medium />; | ||
} | ||
|
||
return ( | ||
<Joyride | ||
run={is_tour_open || should_trigger_tour_guide} | ||
continuous | ||
disableScrolling | ||
hideCloseButton | ||
disableCloseOnEsc | ||
steps={low_risk ? tour_step_config : tour_step_config_high_risk} | ||
stepIndex={joyride_index} | ||
locale={low_risk ? tour_step_locale : high_risk_tour_step_locale} | ||
styles={is_dark_mode_on ? tour_styles_dark_mode : tour_styles} | ||
floaterProps={{ disableAnimation: true }} | ||
callback={callbackHandle} | ||
/> | ||
); | ||
}; | ||
export default observer(TourGuide); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.