Michelle Sepkap Sime | 51c0045 | 2022-10-31 21:26:38 -0400 | [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 { useState } from 'react'; |
| 21 | |
| 22 | import JamiWelcomeLogo from '../components/JamiWelcomeLogo'; |
| 23 | import JamiLogin from './JamiLogin'; |
| 24 | import JamiRegistration from './JamiRegistration'; |
| 25 | |
| 26 | const borderRadius = 30; |
| 27 | |
| 28 | export default function Home() { |
| 29 | const theme: Theme = useTheme(); |
| 30 | const [isRegistrationDisplayed, setIsRegistrationDisplayed] = useState<boolean>(false); |
| 31 | |
| 32 | const child = !isRegistrationDisplayed ? ( |
| 33 | <JamiLogin register={() => setIsRegistrationDisplayed(true)} /> |
| 34 | ) : ( |
| 35 | <JamiRegistration login={() => setIsRegistrationDisplayed(false)} /> |
| 36 | ); |
| 37 | |
| 38 | const isDesktopOrLaptop: boolean = useMediaQuery(theme.breakpoints.up('md')); |
| 39 | const isMobile: boolean = useMediaQuery(theme.breakpoints.only('xs')); |
| 40 | |
| 41 | return ( |
| 42 | <Box |
| 43 | sx={{ |
| 44 | width: '100%', |
| 45 | height: '100%', |
| 46 | display: 'flex', |
| 47 | backgroundColor: `${isDesktopOrLaptop ? theme.palette.primary.dark : 'white'}`, |
| 48 | }} |
| 49 | > |
| 50 | <Paper |
| 51 | elevation={10} |
| 52 | sx={{ |
| 53 | width: '100%', |
| 54 | backgroundColor: 'white', |
| 55 | margin: `${isDesktopOrLaptop ? theme.typography.pxToRem(100) : 0}`, |
| 56 | borderRadius: `${isDesktopOrLaptop ? theme.typography.pxToRem(borderRadius) : 0}`, |
| 57 | }} |
| 58 | > |
| 59 | <Grid container spacing={0} sx={{ height: '100%' }}> |
| 60 | {!isMobile && ( |
| 61 | <Grid |
| 62 | item |
| 63 | xs={6} |
| 64 | id="logo" |
| 65 | sx={{ |
| 66 | height: '100%', |
| 67 | backgroundColor: theme.palette.secondary.main, |
| 68 | borderRadius: `${ |
| 69 | isDesktopOrLaptop |
| 70 | ? `${theme.typography.pxToRem(borderRadius)} 0 0 ${theme.typography.pxToRem(borderRadius)}` |
| 71 | : 0 |
| 72 | }`, // To follow paper border-radius |
| 73 | }} |
| 74 | > |
| 75 | <JamiWelcomeLogo logoWidth="90%" sx={{ height: '100%' }} /> |
| 76 | </Grid> |
| 77 | )} |
| 78 | <Grid item xs={isMobile ? 12 : 6} sx={{ height: '100%' }}> |
| 79 | {isMobile && ( |
| 80 | <JamiWelcomeLogo |
| 81 | logoWidth={theme.typography.pxToRem(100)} |
| 82 | logoHeight={theme.typography.pxToRem(100)} |
| 83 | sx={{ mt: theme.typography.pxToRem(30), mb: theme.typography.pxToRem(20) }} |
| 84 | /> |
| 85 | )} |
| 86 | <Box className="home-child" sx={{ height: `${isMobile ? 'auto' : '100%'}` }}> |
| 87 | {child} |
| 88 | </Box> |
| 89 | </Grid> |
| 90 | </Grid> |
| 91 | </Paper> |
| 92 | </Box> |
| 93 | ); |
| 94 | } |