Ziwei Wang | 3ce1ac0 | 2023-02-03 11:59:03 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | import { Box, Grid, Paper, useMediaQuery } from '@mui/material'; |
| 19 | import { Theme, useTheme } from '@mui/material/styles'; |
| 20 | import React from 'react'; |
| 21 | import { Navigate } from 'react-router-dom'; |
| 22 | |
| 23 | import { getAccessToken } from '../utils/auth'; |
| 24 | import JamiWelcomeLogo from './JamiWelcomeLogo'; |
| 25 | |
| 26 | export default function withAuthUI(WrappedComponent: React.FunctionComponent): React.FunctionComponent { |
| 27 | return function WithAuthUI() { |
| 28 | const borderRadius = 30; |
| 29 | |
| 30 | const theme: Theme = useTheme(); |
| 31 | |
| 32 | const isDesktopOrLaptop: boolean = useMediaQuery(theme.breakpoints.up('md')); |
| 33 | const isMobile: boolean = useMediaQuery(theme.breakpoints.only('xs')); |
| 34 | |
| 35 | const accessToken = getAccessToken(); |
| 36 | |
| 37 | if (accessToken) { |
| 38 | return <Navigate to="/conversation" replace />; |
| 39 | } |
| 40 | return ( |
| 41 | <Box |
| 42 | sx={{ |
| 43 | width: '100%', |
| 44 | height: '100%', |
| 45 | display: 'flex', |
| 46 | backgroundColor: `${isDesktopOrLaptop ? theme.palette.primary.dark : 'white'}`, |
| 47 | }} |
| 48 | > |
| 49 | <Paper |
| 50 | elevation={10} |
| 51 | sx={{ |
| 52 | width: '100%', |
| 53 | backgroundColor: 'white', |
| 54 | margin: `${isDesktopOrLaptop ? theme.typography.pxToRem(100) : 0}`, |
| 55 | borderRadius: `${isDesktopOrLaptop ? theme.typography.pxToRem(borderRadius) : 0}`, |
| 56 | }} |
| 57 | > |
| 58 | <Grid container spacing={0} sx={{ height: '100%' }}> |
| 59 | {!isMobile && ( |
| 60 | <Grid |
| 61 | item |
| 62 | xs={6} |
| 63 | id="logo" |
| 64 | sx={{ |
| 65 | height: '100%', |
| 66 | backgroundColor: theme.palette.secondary.main, |
| 67 | borderRadius: `${ |
| 68 | isDesktopOrLaptop |
| 69 | ? `${theme.typography.pxToRem(borderRadius)} 0 0 ${theme.typography.pxToRem(borderRadius)}` |
| 70 | : 0 |
| 71 | }`, // To follow paper border-radius |
| 72 | }} |
| 73 | > |
| 74 | <JamiWelcomeLogo logoWidth="90%" sx={{ height: '100%' }} /> |
| 75 | </Grid> |
| 76 | )} |
| 77 | <Grid item xs={isMobile ? 12 : 6} sx={{ height: '100%' }}> |
| 78 | {isMobile && ( |
| 79 | <JamiWelcomeLogo |
| 80 | logoWidth={theme.typography.pxToRem(100)} |
| 81 | logoHeight={theme.typography.pxToRem(100)} |
| 82 | sx={{ mt: theme.typography.pxToRem(30), mb: theme.typography.pxToRem(20) }} |
| 83 | /> |
| 84 | )} |
| 85 | <Box sx={{ height: `${isMobile ? 'auto' : '100%'}` }}> |
| 86 | <WrappedComponent /> |
| 87 | </Box> |
| 88 | </Grid> |
| 89 | </Grid> |
| 90 | </Paper> |
| 91 | </Box> |
| 92 | ); |
| 93 | }; |
| 94 | } |