-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(onboarding-ui): create redirect page (#667)
- Loading branch information
1 parent
fc7974e
commit be2c9bd
Showing
5 changed files
with
113 additions
and
0 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
14 changes: 14 additions & 0 deletions
14
packages/onboarding-ui/src/pages/RedirectPage/RedirectPage.spec.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,14 @@ | ||
import ReactDOM from 'react-dom'; | ||
|
||
import RedirectPage from './RedirectPage'; | ||
|
||
const onRedirect = jest.fn(); | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render( | ||
<RedirectPage title='Ready' countDownSeconds={5} onRedirect={onRedirect} />, | ||
div | ||
); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/onboarding-ui/src/pages/RedirectPage/RedirectPage.stories.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,24 @@ | ||
import { action } from '@storybook/addon-actions'; | ||
import type { Story, Meta } from '@storybook/react'; | ||
import type { ComponentProps } from 'react'; | ||
|
||
import RedirectPage from './RedirectPage'; | ||
|
||
type Args = ComponentProps<typeof RedirectPage>; | ||
|
||
export default { | ||
title: 'pages/RedirectPage', | ||
component: RedirectPage, | ||
parameters: { | ||
actions: { argTypesRegex: '^on.*' }, | ||
layout: 'fullscreen', | ||
}, | ||
args: { | ||
title: 'Kapai workspace is ready! 🚀', | ||
countDownSeconds: 5, | ||
onRedirect: action('onRedirect'), | ||
}, | ||
} as Meta<Args>; | ||
|
||
export const _RedirectPage: Story<Args> = (args) => <RedirectPage {...args} />; | ||
_RedirectPage.storyName = 'RedirectPage'; |
70 changes: 70 additions & 0 deletions
70
packages/onboarding-ui/src/pages/RedirectPage/RedirectPage.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,70 @@ | ||
import { Box, Margins } from '@rocket.chat/fuselage'; | ||
import type { ReactElement } from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
import { useTranslation, Trans } from 'react-i18next'; | ||
|
||
import ActionLink from '../../common/ActionLink'; | ||
import BackgroundLayer from '../../common/BackgroundLayer'; | ||
import { OnboardingLogo } from '../../common/OnboardingLogo'; | ||
|
||
type RedirectPageProps = { | ||
title: string; | ||
countDownSeconds: number; | ||
onRedirect: () => void; | ||
}; | ||
|
||
const RedirectPage = ({ | ||
title, | ||
countDownSeconds, | ||
onRedirect, | ||
}: RedirectPageProps): ReactElement => { | ||
const { t } = useTranslation(); | ||
|
||
const [seconds, setSeconds] = useState(countDownSeconds); | ||
|
||
const countDown = () => { | ||
setInterval(() => { | ||
setSeconds((prev) => (prev === 0 ? 0 : prev - 1)); | ||
}, 1000); | ||
}; | ||
|
||
useEffect(() => { | ||
countDown(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (seconds === 0) onRedirect(); | ||
}, [seconds]); | ||
|
||
return ( | ||
<BackgroundLayer> | ||
<Box | ||
display='flex' | ||
flexDirection='column' | ||
alignItems='center' | ||
textAlign='center' | ||
width='100%' | ||
maxWidth={768} | ||
paddingBlock={32} | ||
paddingInline={16} | ||
> | ||
<Margins blockEnd={32}> | ||
<OnboardingLogo /> | ||
|
||
<Box fontScale='hero'>{title}</Box> | ||
|
||
<Box fontScale='p1b'>{t('page.redirect.subtitle', { seconds })}</Box> | ||
|
||
<Box fontScale='c1'> | ||
<Trans i18nKey='page.redirect.redirectNotWorking'> | ||
Redirect not working? | ||
<ActionLink onClick={onRedirect}>Open workspace</ActionLink> | ||
</Trans> | ||
</Box> | ||
</Margins> | ||
</Box> | ||
</BackgroundLayer> | ||
); | ||
}; | ||
|
||
export default RedirectPage; |
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 @@ | ||
export { default } from './RedirectPage'; |