All files / src/pages VerificationResultPage.tsx

100% Statements 10/10
100% Branches 2/2
100% Functions 5/5
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                  4x 4x 4x   4x           1x               1x               1x               1x         4x   4x                              
import { useParams, useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
import { PageWrapper } from '../components/PageWrapper';
import Seo from '../components/Seo';
 
export default function VerificationResultPage() {
  const { status } = useParams<'status'>();
  const navigate = useNavigate();
  const { t } = useTranslation(['verification']);
 
  const config = {
    success: {
      title: t('success.title'),
      message: t('success.message'),
      action: {
        label: t('loginLink'),
        onClick: () => navigate('/login'),
      }
    },
    invalid: {
      title: t('invalid.title'),
      message: t('invalid.message'),
      action: {
        label: t('loginLink'),
        onClick: () => navigate('/login'),
      }
    },
    'already-verified': {
      title: t('alreadyVerified.title'),
      message: t('alreadyVerified.message'),
      action: {
        label: t('loginLink'),
        onClick: () => navigate('/login'),
      }
    },
    error: {
      title: t('verification:error.title'),
      message: t('verification:error.message'),
      action: {
        label: t('homeButton'),
        onClick: () => navigate('/'),
      }
    }
  };
 
  const ctx = config[status as keyof typeof config] || config.error;
 
  return (
    <>
      <Seo title={t('seo.title')} description={t('seo.description')} />
      <PageWrapper>
        <Box textAlign="center" mt={2}>
          <Typography variant="h4" gutterBottom>{ctx.title}</Typography>
          <Typography variant="body1" sx={{ mb: 4 }}>{ctx.message}</Typography>
          <Button variant="contained" onClick={ctx.action.onClick}>
            {ctx.action.label}
          </Button>
        </Box>
      </PageWrapper>
    </>
  );
}