|
| 1 | +import { useEffect } from 'react'; |
| 2 | +import { Trans } from 'react-i18next'; |
| 3 | +import { Link, useNavigate } from 'react-router-dom'; |
| 4 | +import { useQueryDemoSiteStatus } from '@queries/demo-site-status'; |
| 5 | +import { PAGE_PATH_DEMO_SITE } from 'constants/routing'; |
| 6 | +import { useTranslation } from 'i18n'; |
| 7 | +import { getDemoTokenStorage } from 'storage/demo-token'; |
| 8 | +import { IconBackspace } from '@icons'; |
| 9 | +import AuthWrapper from 'pages/signin/elements/auth-wrapper'; |
| 10 | +import Button from 'components/button'; |
| 11 | +import Icon from 'components/icon'; |
| 12 | +import DemoForm from './demo-form'; |
| 13 | + |
| 14 | +const CreateDemoPage = () => { |
| 15 | + const navigate = useNavigate(); |
| 16 | + const { t } = useTranslation(['common', 'auth', 'message']); |
| 17 | + |
| 18 | + const demoAuthToken = getDemoTokenStorage(); |
| 19 | + const { data: demoSiteStatusData, isSuccess } = useQueryDemoSiteStatus(); |
| 20 | + |
| 21 | + const isDemoSiteEnabled = demoSiteStatusData?.isDemoSiteEnabled; |
| 22 | + |
| 23 | + useEffect(() => { |
| 24 | + if (!demoAuthToken || (isSuccess && !isDemoSiteEnabled)) { |
| 25 | + navigate(PAGE_PATH_DEMO_SITE); |
| 26 | + } |
| 27 | + }, [isDemoSiteEnabled]); |
| 28 | + |
| 29 | + return ( |
| 30 | + <AuthWrapper> |
| 31 | + <div className="-mt-2"> |
| 32 | + <Button |
| 33 | + variant="secondary-2" |
| 34 | + onClick={() => navigate(PAGE_PATH_DEMO_SITE)} |
| 35 | + className="p-2 h-auto" |
| 36 | + > |
| 37 | + <Icon icon={IconBackspace} size="sm" /> |
| 38 | + </Button> |
| 39 | + <h1 className="text-gray-900 typo-head-bold-huge mt-8"> |
| 40 | + {t('auth:demo-organization')} |
| 41 | + </h1> |
| 42 | + |
| 43 | + <h3 className="text-gray-900 typo-head-light-medium mt-6"> |
| 44 | + {t('auth:privacy-notice')} |
| 45 | + </h3> |
| 46 | + <div className="text-gray-600 typo-para-medium mt-2"> |
| 47 | + <Trans |
| 48 | + i18nKey="message:demo-privacy-description" |
| 49 | + components={{ |
| 50 | + comp: ( |
| 51 | + <Link |
| 52 | + target="_blank" |
| 53 | + to={`https://app.slack.com/client/T08PSQ7BQ/C043026BME1`} |
| 54 | + className="text-primary-500 underline" |
| 55 | + /> |
| 56 | + ) |
| 57 | + }} |
| 58 | + /> |
| 59 | + </div> |
| 60 | + <DemoForm isDemoSiteEnabled={isDemoSiteEnabled} /> |
| 61 | + </div> |
| 62 | + </AuthWrapper> |
| 63 | + ); |
| 64 | +}; |
| 65 | + |
| 66 | +export default CreateDemoPage; |
0 commit comments