blob: 59899ea294548324166a095133c987964ddc8ad7 [file] [log] [blame]
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -04001/*
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 */
18import { Box, Grid, Paper, useMediaQuery } from '@mui/material';
19import { Theme, useTheme } from '@mui/material/styles';
20import { useState } from 'react';
Michelle Sepkap Simee580f422022-10-31 23:27:04 -040021import { Navigate } from 'react-router-dom';
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040022
23import JamiWelcomeLogo from '../components/JamiWelcomeLogo';
Michelle Sepkap Simee580f422022-10-31 23:27:04 -040024import { getAccessToken } from '../utils/auth';
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040025import JamiLogin from './JamiLogin';
26import JamiRegistration from './JamiRegistration';
27
28const borderRadius = 30;
29
simon416d0792022-11-03 02:46:18 -040030export default function Welcome() {
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040031 const theme: Theme = useTheme();
32 const [isRegistrationDisplayed, setIsRegistrationDisplayed] = useState<boolean>(false);
33
34 const child = !isRegistrationDisplayed ? (
35 <JamiLogin register={() => setIsRegistrationDisplayed(true)} />
36 ) : (
37 <JamiRegistration login={() => setIsRegistrationDisplayed(false)} />
38 );
39
40 const isDesktopOrLaptop: boolean = useMediaQuery(theme.breakpoints.up('md'));
41 const isMobile: boolean = useMediaQuery(theme.breakpoints.only('xs'));
42
Michelle Sepkap Simee580f422022-10-31 23:27:04 -040043 const accessToken = getAccessToken();
44
45 if (accessToken) {
46 return <Navigate to="/settings" replace />;
47 }
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040048 return (
49 <Box
50 sx={{
51 width: '100%',
52 height: '100%',
53 display: 'flex',
54 backgroundColor: `${isDesktopOrLaptop ? theme.palette.primary.dark : 'white'}`,
55 }}
56 >
57 <Paper
58 elevation={10}
59 sx={{
60 width: '100%',
61 backgroundColor: 'white',
62 margin: `${isDesktopOrLaptop ? theme.typography.pxToRem(100) : 0}`,
63 borderRadius: `${isDesktopOrLaptop ? theme.typography.pxToRem(borderRadius) : 0}`,
64 }}
65 >
66 <Grid container spacing={0} sx={{ height: '100%' }}>
67 {!isMobile && (
68 <Grid
69 item
70 xs={6}
71 id="logo"
72 sx={{
73 height: '100%',
74 backgroundColor: theme.palette.secondary.main,
75 borderRadius: `${
76 isDesktopOrLaptop
77 ? `${theme.typography.pxToRem(borderRadius)} 0 0 ${theme.typography.pxToRem(borderRadius)}`
78 : 0
79 }`, // To follow paper border-radius
80 }}
81 >
82 <JamiWelcomeLogo logoWidth="90%" sx={{ height: '100%' }} />
83 </Grid>
84 )}
85 <Grid item xs={isMobile ? 12 : 6} sx={{ height: '100%' }}>
86 {isMobile && (
87 <JamiWelcomeLogo
88 logoWidth={theme.typography.pxToRem(100)}
89 logoHeight={theme.typography.pxToRem(100)}
90 sx={{ mt: theme.typography.pxToRem(30), mb: theme.typography.pxToRem(20) }}
91 />
92 )}
simon416d0792022-11-03 02:46:18 -040093 <Box sx={{ height: `${isMobile ? 'auto' : '100%'}` }}>{child}</Box>
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040094 </Grid>
95 </Grid>
96 </Paper>
97 </Box>
98 );
99}