generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from Arquisoft/feat/webapp/new-menu
New lateral menu
- Loading branch information
Showing
19 changed files
with
582 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Box, Drawer, DrawerOverlay, DrawerContent, DrawerCloseButton, DrawerHeader, DrawerBody, DrawerFooter, Select, Button, Text, IconButton, Flex, Image } from '@chakra-ui/react'; | ||
import { FaChartBar, FaBook, FaTachometerAlt } from 'react-icons/fa'; | ||
import { InfoIcon, SettingsIcon } from '@chakra-ui/icons'; | ||
|
||
import AuthManager from "components/auth/AuthManager"; | ||
|
||
const LateralMenu = ({ isOpen, onClose, changeLanguage, currentLanguage, isDashboard }) => { | ||
const navigate = useNavigate(); | ||
const [selectedLanguage, setSelectedLanguage] = useState(currentLanguage); | ||
const [isLoggedIn, setIsLoggedIn] = useState(false); | ||
const { t } = useTranslation(); | ||
|
||
useEffect(() => { | ||
setSelectedLanguage(currentLanguage); | ||
checkIsLoggedIn(); | ||
}, [currentLanguage]); | ||
|
||
const handleChangeLanguage = (e) => { | ||
const selectedLanguage = e.target.value; | ||
changeLanguage(selectedLanguage); | ||
}; | ||
|
||
const handleApiClick = () => { | ||
window.open("http://localhost:8080/swagger/swagger-ui/index.html#/auth-controller/registerUser", "_blank", "noopener"); | ||
}; | ||
|
||
const handleLogout = async () => { | ||
try { | ||
await new AuthManager().logout(); | ||
navigate("/"); | ||
} catch (error) { | ||
console.error("Error al cerrar sesión:", error); | ||
} | ||
}; | ||
|
||
const checkIsLoggedIn = async () => { | ||
try { | ||
const loggedIn = await new AuthManager().isLoggedIn(); | ||
setIsLoggedIn(loggedIn); | ||
} catch (error) { | ||
console.error("Error al verificar el estado de inicio de sesión:", error); | ||
} | ||
}; | ||
|
||
return ( | ||
<Drawer isOpen={isOpen} placement="left" onClose={onClose}> | ||
<DrawerOverlay> | ||
<DrawerContent> | ||
<DrawerCloseButton /> | ||
<Flex align="center"> | ||
<Image src="/kiwiq-icon.ico" alt="App icon" width="80px" height="80px"/> | ||
<DrawerHeader color={"forest_green.500"}>KIWIQ</DrawerHeader> | ||
</Flex> | ||
<DrawerBody> | ||
<Box flexDirection="column"> | ||
<Box margin={"10px"}> | ||
<Text color={"forest_green.500"}>{t("common.language")}</Text> | ||
<Select data-testid="language-select" onChange={handleChangeLanguage} value={selectedLanguage}> | ||
<option value="es">{t("common.spanish")}</option> | ||
<option value="en">{t("common.english")}</option> | ||
</Select> | ||
</Box> | ||
<Box margin={"10px"} flexDirection="row"> | ||
{isLoggedIn && ( | ||
<> | ||
{!isDashboard && ( | ||
<Box marginTop={"40px"}> | ||
<Button data-testid="dashboard" type="submit" variant="link" colorScheme={"forest_green"} onClick={() => {navigate("/dashboard")}}> | ||
<FaTachometerAlt /> | ||
<span style={{ marginLeft: '6px' }}>{t("common.dashboard")}</span> | ||
</Button> | ||
</Box> | ||
)} | ||
<Box marginTop={"40px"}> | ||
<Button data-testid="statistics" type="submit" variant="link" colorScheme={"forest_green"} onClick={() => {navigate("/dashboard/statistics")}}> | ||
<FaChartBar /> | ||
<span style={{ marginLeft: '6px' }}>{t("common.statistics.title")}</span> | ||
</Button> | ||
</Box> | ||
<Box marginTop={"40px"}> | ||
<Button data-testid="rules" type="submit" variant="link" colorScheme={"forest_green"} onClick={() => {navigate("/dashboard/rules")}}> | ||
<FaBook /> | ||
<span style={{ marginLeft: '6px' }}>{t("common.rules")}</span> | ||
</Button> | ||
</Box> | ||
<Box marginTop={"40px"}> | ||
<Button data-testid="API" type="submit" variant="link" colorScheme={"forest_green"} onClick={handleApiClick}> | ||
<SettingsIcon /> | ||
<span style={{ marginLeft: '6px' }}>API</span> | ||
</Button> | ||
</Box> | ||
</> | ||
)} | ||
</Box> | ||
</Box> | ||
</DrawerBody> | ||
<DrawerFooter> | ||
<Flex justify="flex-end" align="center" w="100%"> | ||
{isLoggedIn && ( | ||
<Button data-testid={"LogOut"} type="submit" colorScheme="raw_umber" margin={"10px"} className={"custom-button effect1"} onClick={handleLogout} width="70%">{t("common.logout")}</Button> | ||
)} | ||
<IconButton type="submit" aria-label='About' colorScheme={"forest_green"} icon={<InfoIcon />} className={"custom-button effect1"} onClick={() => {navigate("/about");}} margin={"10px"}></IconButton> | ||
</Flex> | ||
</DrawerFooter> | ||
</DrawerContent> | ||
</DrawerOverlay> | ||
</Drawer> | ||
); | ||
}; | ||
|
||
LateralMenu.propTypes = { | ||
isOpen: PropTypes.bool.isRequired, | ||
onClose: PropTypes.func.isRequired, | ||
changeLanguage: PropTypes.func.isRequired, | ||
currentLanguage: PropTypes.string.isRequired, | ||
isDashboard: PropTypes.bool.isRequired | ||
}; | ||
|
||
export default LateralMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import PropTypes from 'prop-types'; | ||
import { FaBars } from "react-icons/fa"; | ||
import { chakra, Box, IconButton } from "@chakra-ui/react"; | ||
|
||
const MenuButton = ({ onClick }) => { | ||
const [isFixed, setIsFixed] = useState(false); | ||
|
||
useEffect(() => { | ||
const handleScroll = () => { | ||
if (window.scrollY > 0) { | ||
setIsFixed(true); | ||
} else { | ||
setIsFixed(false); | ||
} | ||
}; | ||
|
||
window.addEventListener("scroll", handleScroll); | ||
return () => { | ||
window.removeEventListener("scroll", handleScroll); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<Box position={isFixed ? "fixed" : "absolute"} top="1rem" left="1rem"> | ||
<IconButton | ||
bg="pigment_green.600" | ||
color="whiteAlpha.900" | ||
size="lg" | ||
borderRadius="md" | ||
aria-label="Open Menu" | ||
_hover={{ bg: 'pigment_green.400' }} | ||
icon={<chakra.span as={FaBars} fontSize="1.5em" />} | ||
onClick={onClick} | ||
/> | ||
</Box> | ||
); | ||
} | ||
|
||
MenuButton.propTypes = { | ||
onClick: PropTypes.func.isRequired | ||
}; | ||
|
||
export default MenuButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { useState } from "react"; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Center, Heading, Stack, Box, Text, Table, Thead, Tr, Td, Th, Tbody, Container } from '@chakra-ui/react'; | ||
import { InfoIcon } from '@chakra-ui/icons'; | ||
|
||
import LateralMenu from '../components/LateralMenu'; | ||
import MenuButton from '../components/MenuButton'; | ||
import GoBack from "components/GoBack"; | ||
|
||
export default function About() { | ||
const { t, i18n } = useTranslation(); | ||
const currentLanguage = i18n.language; | ||
const [isMenuOpen, setIsMenuOpen] = useState(false); | ||
|
||
const changeLanguage = (selectedLanguage) => { | ||
i18n.changeLanguage(selectedLanguage); | ||
}; | ||
|
||
return ( | ||
<Center bgImage="/background.svg"> | ||
<MenuButton data-testid="menu-button" onClick={() => setIsMenuOpen(true)} /> | ||
<LateralMenu isOpen={isMenuOpen} onClose={() => setIsMenuOpen(false)} changeLanguage={changeLanguage} currentLanguage={currentLanguage} isDashboard={false}/> | ||
<Container maxW="lg"> | ||
<Box textAlign="center"> | ||
<InfoIcon boxSize={10} color="pigment_green.500" /> | ||
<Heading as="h2">{t('about.title')}</Heading> | ||
</Box> | ||
<Stack spacing={4} p="1rem" backgroundColor="whiteAlpha.900" boxShadow="md" rounded="1rem"> | ||
<Text>{t("about.description1")}</Text> | ||
<br></br> | ||
<Table variant="simple"> | ||
<Thead> | ||
<Tr> | ||
<Th><Text fontWeight='extrabold' color={"forest_green.400"} textAlign={"center"} fontSize={"md"}>{t("about.table1")}</Text></Th> | ||
<Th><Text fontWeight='extrabold' color={"forest_green.400"} textAlign={"center"} fontSize={"md"}>{t("about.table2")}</Text></Th> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
<Tr> | ||
<Td>Gonzalo Alonso Fernández</Td> | ||
<Td>UO282104</Td> | ||
</Tr> | ||
<Tr> | ||
<Td>Sergio Rodríguez García</Td> | ||
<Td>UO282598</Td> | ||
</Tr> | ||
<Tr> | ||
<Td>Jorge Joaquín Gancedo Fernández</Td> | ||
<Td>UO282161</Td> | ||
</Tr> | ||
<Tr> | ||
<Td>Darío Gutiérrez Mori</Td> | ||
<Td>UO282435</Td> | ||
</Tr> | ||
<Tr> | ||
<Td>Sergio Quintana Fernández</Td> | ||
<Td>UO288090</Td> | ||
</Tr> | ||
<Tr> | ||
<Td>Diego Villanueva Berros</Td> | ||
<Td>UO283615</Td> | ||
</Tr> | ||
<Tr> | ||
<Td>Gonzalo Suárez Losada</Td> | ||
<Td>UO283928</Td> | ||
</Tr> | ||
</Tbody> | ||
</Table> | ||
<GoBack/> | ||
</Stack> | ||
</Container> | ||
</Center> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.