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 remote-tracking branch 'origin/develop' into feat/webapp/new-da…
…shboard
- Loading branch information
Showing
10 changed files
with
262 additions
and
114 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
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
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 |
---|---|---|
@@ -1,53 +1,139 @@ | ||
import { Center } from "@chakra-ui/layout"; | ||
import { Button, FormControl, FormLabel, Heading, Input, Text, Stack } from "@chakra-ui/react"; | ||
import { Heading, Input, Button, InputGroup, Stack, InputLeftElement, chakra, Box, Avatar, FormControl, InputRightElement, Text, FormHelperText } from "@chakra-ui/react"; | ||
import { ViewIcon, ViewOffIcon } from '@chakra-ui/icons' | ||
import axios, { HttpStatusCode } from "axios"; | ||
import React, { useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { FaUserAlt, FaLock, FaAddressCard } from "react-icons/fa"; | ||
import ButtonEf from '../components/ButtonEf'; | ||
|
||
export default function Signup() { | ||
|
||
const [email, setEmail] = useState(""); | ||
const [username, setUsername] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const [confirmPassword, setConfirmPassword] = useState(""); | ||
const [showPassword, setShowPassword] = useState(false); | ||
const [showConfirmPassword, setShowConfirmPassword] = useState(false); | ||
const [hasError, setHasError] = useState(false); | ||
|
||
const navigate = useNavigate(); | ||
const { t } = useTranslation(); | ||
|
||
const ChakraFaCardAlt = chakra(FaAddressCard); | ||
const ChakraFaUserAlt = chakra(FaUserAlt); | ||
const ChakraFaLock = chakra(FaLock); | ||
|
||
const sendLogin = async () => { | ||
let data = {}; | ||
let response = await axios.post(process.env.API_URL, data); | ||
if (response.status === HttpStatusCode.Accepted) { | ||
navigate("/home"); | ||
} else { | ||
try { | ||
const response = await axios.post(process.env.API_URL, { email, username, password }); | ||
if (response.status === HttpStatusCode.Accepted) { | ||
navigate("/home"); | ||
} | ||
} catch (error) { | ||
setHasError(true); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<Center display={"flex"} flexDirection={"column"} maxW={"100%"} minW={"30%"} mt={"2vh"}> | ||
<Heading as="h2">{ t("common.register")}</Heading> | ||
{ | ||
!hasError ? | ||
<></> : | ||
<Center bgColor={"#FFA98A"} margin={"1vh 0vw"} padding={"1vh 0vw"} | ||
color={"#FF0500"} border={"0.1875em solid #FF0500"} | ||
borderRadius={"0.75em"} maxW={"100%"} minW={"30%"}> | ||
<Center | ||
display={"flex"} | ||
flexDirection={"column"} | ||
w={"100wh"} | ||
h={"100vh"} | ||
bg={"blue.50"} | ||
justifyContent={"center"} | ||
alignItems={"center"} | ||
> | ||
{hasError && ( | ||
<div className="error-container"> | ||
<Text>Error</Text> | ||
</div> | ||
)} | ||
<Stack flexDir={"column"} mb="2" justifyContent="center" alignItems={"center"}> | ||
<Avatar bg="blue.500" /> | ||
<Heading as="h2" color="blue.400"> | ||
{t("common.register")} | ||
</Heading> | ||
{!hasError ? ( | ||
<></> | ||
) : ( | ||
<Center | ||
bgColor={"#FFA98A"} | ||
margin={"1vh 0vw"} | ||
padding={"1vh 0vw"} | ||
color={"#FF0500"} | ||
border={"0.1875em solid #FF0500"} | ||
borderRadius={"0.75em"} | ||
maxW={"100%"} | ||
minW={"30%"} | ||
> | ||
<Text>Error</Text> | ||
</Center> | ||
} | ||
<Stack spacing={4} mt={4} width="100%" mx={"auto"} maxWidth={"400px"}> | ||
<FormControl as="fieldset" padding={"1vh 0vw"} isRequired> | ||
<FormLabel>{ t("session.username") }</FormLabel> | ||
<Input type="text" /> | ||
</FormControl> | ||
<FormControl as="fieldset" padding={"1vh 0vw"} isRequired> | ||
<FormLabel>{ t("Correo electrónico") }</FormLabel> {/* To be changed */} | ||
<Input type="text" /> | ||
</FormControl> | ||
<FormControl as="fieldset" padding={"1vh 0vw"} isRequired> | ||
<FormLabel> {t("session.password")}</FormLabel> | ||
<Input type="password" /> | ||
</FormControl> | ||
<Button type="submit" onClick={sendLogin}>Enviar</Button> | ||
</Center> | ||
)} | ||
<Box minW={{ md: "400px" }}> | ||
<Stack spacing={4} p="1rem" backgroundColor="whiteAlpha.900" boxShadow="md"> | ||
<FormControl> | ||
<InputGroup> | ||
<InputLeftElement children={<ChakraFaCardAlt color="gray.300" />} /> | ||
<Input | ||
type="text" | ||
placeholder={t("session.email")} | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
/> | ||
</InputGroup> | ||
</FormControl> | ||
<FormControl> | ||
<InputGroup> | ||
<InputLeftElement children={<ChakraFaUserAlt color="gray.300" />} /> | ||
<Input | ||
type="text" | ||
placeholder={t("session.username")} | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
/> | ||
</InputGroup> | ||
</FormControl> | ||
<FormControl> | ||
<InputGroup> | ||
<InputLeftElement children={<ChakraFaLock color="gray.300" />} /> | ||
<Input | ||
type={showPassword ? "text" : "password"} | ||
placeholder={t("session.password")} | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
/> | ||
<InputRightElement width="4.5rem"> | ||
<Button data-testid="show-confirm-password-button" h="1.75rem" size="sm" onClick={() => setShowPassword(!showPassword)}> | ||
{showPassword ? <ViewOffIcon/> : <ViewIcon/>} | ||
</Button> | ||
</InputRightElement> | ||
</InputGroup> | ||
</FormControl> | ||
<FormControl> | ||
<InputGroup> | ||
<InputLeftElement children={<ChakraFaLock color="gray.300" />} /> | ||
<Input | ||
type={showConfirmPassword ? "text" : "password"} | ||
placeholder={t("session.confirm_password")} | ||
value={confirmPassword} | ||
onChange={(e) => setConfirmPassword(e.target.value)} | ||
/> | ||
<InputRightElement width="4.5rem"> | ||
<Button data-testid="show-confirm-password-button" h="1.75rem" size="sm" onClick={() => setShowConfirmPassword(!showConfirmPassword)}> | ||
{showConfirmPassword ? <ViewOffIcon/> : <ViewIcon/>} | ||
</Button> | ||
</InputRightElement> | ||
</InputGroup> | ||
{confirmPassword && password && confirmPassword !== password && ( | ||
<FormHelperText color="red">Las contraseñas no coinciden</FormHelperText> | ||
)} | ||
</FormControl> | ||
<ButtonEf dataTestId={"Sign up"} variant={"solid"} colorScheme={"blue"} text={t("common.register")} onClick={sendLogin}/> | ||
</Stack> | ||
</Box> | ||
</Stack> | ||
</Center> | ||
); | ||
} | ||
} |
Oops, something went wrong.