|
1 | 1 | import Box from '@mui/material/Box'
|
| 2 | +import Stack from '@mui/material/Stack' |
| 3 | +import Button from '@mui/material/Button' |
2 | 4 | import Typography from '@mui/material/Typography'
|
3 |
| -import { ReactElement } from 'react' |
| 5 | +import { ReactElement, useState } from 'react' |
| 6 | +import dynamic from 'next/dynamic' |
| 7 | + |
| 8 | +import OpenInNewIcon from '@mui/icons-material/OpenInNew' |
| 9 | +import ShareIcon from '@mui/icons-material/Share' |
| 10 | +import EditIcon from '@mui/icons-material/Edit' |
| 11 | +import { useJourney } from '@core/journeys/ui/JourneyProvider' |
| 12 | +import { useRouter } from 'next/router' |
| 13 | +import { useTranslation } from 'react-i18next' |
| 14 | +import NextImage from 'next/image' |
| 15 | +const ShareDrawer = dynamic( |
| 16 | + async () => |
| 17 | + await import( |
| 18 | + /* webpackChunkName: "TemplateCustomization/DoneScreen/ShareDrawer" */ './ShareDrawer' |
| 19 | + ).then((mod) => mod.ShareDrawer), |
| 20 | + { ssr: false } |
| 21 | +) |
4 | 22 |
|
5 | 23 | export function DoneScreen(): ReactElement {
|
| 24 | + const [openShareDrawer, setOpenShareDrawer] = useState<boolean | null>(null) |
| 25 | + |
| 26 | + const { t } = useTranslation('apps-journeys-admin') |
| 27 | + const { journey } = useJourney() |
| 28 | + const router = useRouter() |
| 29 | + const journeyPath = `/api/preview?slug=${journey?.slug}` |
| 30 | + const href = journey?.slug != null ? journeyPath : undefined |
| 31 | + |
| 32 | + // needed to preload the drawer chunk to preserve first-open animations |
| 33 | + // only run on hover events |
| 34 | + function handlePreloadShareDrawer(): void { |
| 35 | + setOpenShareDrawer(false) |
| 36 | + } |
| 37 | + |
| 38 | + function handleShare(): void { |
| 39 | + setOpenShareDrawer(true) |
| 40 | + } |
| 41 | + |
| 42 | + function handleContinueEditing(): void { |
| 43 | + if (journey?.id != null) void router.push(`/journeys/${journey.id}`) |
| 44 | + } |
| 45 | + |
6 | 46 | return (
|
7 |
| - <Box> |
8 |
| - <Typography variant="h4" component="h1" gutterBottom> |
9 |
| - Setup Complete |
10 |
| - </Typography> |
11 |
| - <Typography variant="body1" color="text.secondary"> |
12 |
| - Your journey template has been successfully configured! |
13 |
| - </Typography> |
14 |
| - </Box> |
| 47 | + <> |
| 48 | + <Stack alignItems="center" gap={4} sx={{ pb: 4 }}> |
| 49 | + <Typography variant="h4" component="h1"> |
| 50 | + {t('Ready!')} |
| 51 | + </Typography> |
| 52 | + |
| 53 | + <Box |
| 54 | + sx={{ |
| 55 | + width: { xs: 300 }, |
| 56 | + borderRadius: 2, |
| 57 | + bgcolor: 'background.paper', |
| 58 | + boxShadow: 3, |
| 59 | + p: 2, |
| 60 | + mt: 6 |
| 61 | + }} |
| 62 | + > |
| 63 | + <Box sx={{ height: 160, position: 'relative' }}> |
| 64 | + <NextImage |
| 65 | + src={journey?.primaryImageBlock?.src ?? ''} |
| 66 | + alt={journey?.seoTitle ?? ''} |
| 67 | + fill |
| 68 | + objectFit="cover" |
| 69 | + style={{ |
| 70 | + borderRadius: 2 |
| 71 | + }} |
| 72 | + /> |
| 73 | + </Box> |
| 74 | + <Typography variant="subtitle1" fontWeight={600} noWrap> |
| 75 | + {journey?.seoTitle ?? journey?.displayTitle ?? ''} |
| 76 | + </Typography> |
| 77 | + <Typography |
| 78 | + variant="caption" |
| 79 | + color="text.secondary" |
| 80 | + sx={{ |
| 81 | + display: '-webkit-box', |
| 82 | + WebkitLineClamp: 2, |
| 83 | + WebkitBoxOrient: 'vertical', |
| 84 | + overflow: 'hidden' |
| 85 | + }} |
| 86 | + > |
| 87 | + {journey?.seoDescription ?? ''} |
| 88 | + </Typography> |
| 89 | + </Box> |
| 90 | + |
| 91 | + <Stack gap={4} sx={{ width: { xs: '100%', sm: 300 }, mt: 6 }}> |
| 92 | + <Button |
| 93 | + fullWidth |
| 94 | + variant="contained" |
| 95 | + href={href} |
| 96 | + component={href != null ? 'a' : 'button'} |
| 97 | + target={href != null ? '_blank' : undefined} |
| 98 | + startIcon={<OpenInNewIcon />} |
| 99 | + sx={{ |
| 100 | + borderRadius: 3, |
| 101 | + backgroundColor: 'secondary.main' |
| 102 | + }} |
| 103 | + > |
| 104 | + <Typography variant="h6">{t('Preview in new tab')}</Typography> |
| 105 | + </Button> |
| 106 | + |
| 107 | + <Button |
| 108 | + fullWidth |
| 109 | + variant="contained" |
| 110 | + onClick={handleShare} |
| 111 | + onMouseEnter={handlePreloadShareDrawer} |
| 112 | + onFocus={handlePreloadShareDrawer} |
| 113 | + onTouchStart={handlePreloadShareDrawer} |
| 114 | + startIcon={<ShareIcon />} |
| 115 | + sx={{ |
| 116 | + borderRadius: 3, |
| 117 | + backgroundColor: 'secondary.main' |
| 118 | + }} |
| 119 | + > |
| 120 | + <Typography variant="h6">{t('Share')}</Typography> |
| 121 | + </Button> |
| 122 | + |
| 123 | + <Button |
| 124 | + fullWidth |
| 125 | + variant="contained" |
| 126 | + onClick={handleContinueEditing} |
| 127 | + startIcon={<EditIcon />} |
| 128 | + sx={{ |
| 129 | + borderRadius: 3, |
| 130 | + backgroundColor: 'secondary.main' |
| 131 | + }} |
| 132 | + > |
| 133 | + <Typography variant="h6">{t('Continue Editing')}</Typography> |
| 134 | + </Button> |
| 135 | + </Stack> |
| 136 | + </Stack> |
| 137 | + {openShareDrawer != null && ( |
| 138 | + <ShareDrawer |
| 139 | + open={openShareDrawer} |
| 140 | + onClose={() => setOpenShareDrawer(false)} |
| 141 | + /> |
| 142 | + )} |
| 143 | + </> |
15 | 144 | )
|
16 | 145 | }
|
0 commit comments