-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/cm 933 AddFunds onboarding drawer (#2293)
- Loading branch information
Showing
23 changed files
with
2,501 additions
and
165 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
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
111 changes: 111 additions & 0 deletions
111
...eckout/widgets-lib/src/widgets/add-funds/components/OnboardingDrawer/OnboardingDrawer.tsx
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,111 @@ | ||
import { | ||
Button, | ||
Divider, | ||
Drawer, | ||
Heading, | ||
OnboardingPagination, | ||
vFlex, | ||
} from '@biom3/react'; | ||
import { | ||
useCallback, useEffect, useMemo, useState, | ||
} from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { | ||
getCacheItem, | ||
SEEN_ONBOARDING_KEY, | ||
setCacheItem, | ||
} from '../../functions/onboardingState'; | ||
import { OnboardingIllustration1 } from './OnboardingIllustration1'; | ||
import { OnboardingIllustration2 } from './OnboardingIllustration2'; | ||
import { OnboardingIllustration3 } from './OnboardingIllustration3'; | ||
|
||
const HERO_IMAGES = [ | ||
OnboardingIllustration1, | ||
OnboardingIllustration2, | ||
OnboardingIllustration3, | ||
]; | ||
|
||
export function OnboardingDrawer() { | ||
const { t } = useTranslation(); | ||
const [visible, setVisible] = useState(false); | ||
const [screenIndex, setScreenIndex] = useState<1 | 2 | 3>(1); | ||
|
||
useEffect(() => { | ||
async function checkToInitialiseDrawer() { | ||
const cachedValue = await getCacheItem(SEEN_ONBOARDING_KEY); | ||
return cachedValue ? setVisible(false) : setVisible(true); | ||
} | ||
|
||
checkToInitialiseDrawer(); | ||
}, []); | ||
|
||
const handleCtaOnClick = useCallback(() => { | ||
switch (screenIndex) { | ||
case 2: { | ||
// @NOTE: once they have "seen" the final slide, mark it as such | ||
// in the cache so that we don't show this to users again | ||
setCacheItem(SEEN_ONBOARDING_KEY, true); | ||
return setScreenIndex(3); | ||
} | ||
case 3: | ||
// @NOTE: they have "seen" all slides - so this drawer can be closed | ||
return setVisible(false); | ||
|
||
case 1: | ||
default: | ||
return setScreenIndex(2); | ||
} | ||
}, [screenIndex]); | ||
|
||
const ScreenHeroImage = useMemo( | ||
() => HERO_IMAGES[screenIndex - 1], | ||
[screenIndex], | ||
); | ||
|
||
return ( | ||
<Drawer size="threeQuarter" visible={visible} showHeaderBar={false}> | ||
<Drawer.Content | ||
sx={{ | ||
...vFlex, | ||
alignItems: 'center', | ||
textAlign: 'center', | ||
px: 'base.spacing.x6', | ||
}} | ||
> | ||
<ScreenHeroImage /> | ||
<Divider | ||
size="xSmall" | ||
textAlign="center" | ||
sx={{ mt: 'base.spacing.x6', mb: 'base.spacing.x4' }} | ||
> | ||
{t(`views.ADD_FUNDS.onboarding.screen${screenIndex}.caption`)} | ||
</Divider> | ||
<Heading | ||
size="small" | ||
sx={{ | ||
// @NOTE: this preserves newlines inside any strings, which | ||
// come out of the translation layer | ||
whiteSpace: 'pre-line', | ||
}} | ||
> | ||
{t(`views.ADD_FUNDS.onboarding.screen${screenIndex}.title`)} | ||
</Heading> | ||
<OnboardingPagination | ||
disabled | ||
size="small" | ||
currentPage={screenIndex} | ||
totalPages={3} | ||
sx={{ mt: 'base.spacing.x11', mb: 'base.spacing.x8' }} | ||
/> | ||
<Button | ||
variant={screenIndex === 3 ? 'primary' : 'tertiary'} | ||
onClick={handleCtaOnClick} | ||
size="large" | ||
sx={{ alignSelf: 'stretch' }} | ||
> | ||
{t(`views.ADD_FUNDS.onboarding.screen${screenIndex}.buttonText`)} | ||
</Button> | ||
</Drawer.Content> | ||
</Drawer> | ||
); | ||
} |
Oops, something went wrong.