Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/webapp/new-da…
Browse files Browse the repository at this point in the history
…shboard
  • Loading branch information
gony02 committed Mar 5, 2024
2 parents ee8c731 + 829ebc3 commit e8d8572
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 114 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
unit-tests:
unit-tests-webapp:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -15,8 +15,30 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/checkout@v4
- run: npm --prefix webapp ci
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
unit-tests-api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- run: mvn test
working-directory: api
env:
DATABASE_USER: ${{ secrets.DATABASE_USER }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
57 changes: 42 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,42 @@ on:
types: [published]

jobs:
unit-tests:
unit-tests-webapp:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix webapp ci
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/checkout@v4
- run: npm --prefix webapp ci
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
unit-tests-api:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- run: mvn test
working-directory: api
env:
DATABASE_USER: ${{ secrets.DATABASE_USER }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
e2e-tests:
Expand All @@ -29,7 +53,7 @@ jobs:
node-version: 20
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
#- run: npm --prefix webapp run test:e2e TODO: re-enable
docker-push-api:
runs-on: ubuntu-latest
needs: [ e2e-tests ]
Expand Down Expand Up @@ -65,7 +89,10 @@ jobs:
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/arquisoft/wiq_en2b/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_en2b/master/.env -O .env
docker compose down
docker compose --profile prod up -d
git clone https://github.com/Arquisoft/wiq_en2b.git
cd wiq_en2b
echo "DATABASE_USER=${{ secrets.DATABASE_USER }}" >> .env
echo "DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}" >> .env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
sudo docker compose down
sudo docker compose --profile prod up -d
5 changes: 5 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
<artifactId>jjwt-jackson</artifactId>
<version>0.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: '3'
services:
postgresql:
WIQ_DB:
container_name: postgresql-${teamname:-defaultASW}
environment:
POSTGRES_USER: ${DATABASE_USER}
Expand Down
3 changes: 2 additions & 1 deletion webapp/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"session": {
"username": "Username",
"password": "Password",
"email": "Email"
"email": "Email",
"confirm_password": "Confirm password"
},
"error": {
"login": "An ERROR occurred during login"
Expand Down
3 changes: 2 additions & 1 deletion webapp/public/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"session": {
"username": "Nombre de usuario",
"password": "Contraseña",
"email": "Correo electrónico"
"email": "Correo electrónico",
"confirm_password": "Confirmar contraseña"
},
"error": {
"login": "Ocurrió un ERROR en el login"
Expand Down
7 changes: 4 additions & 3 deletions webapp/src/components/Router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import Root from "../pages/Root";
import Login from "../pages/Login";
import Dashboard from "../pages/Dashboard";
import Rules from "../pages/Rules";

import { Route, createRoutesFromElements } from "react-router-dom";
import Signup from "../pages/Signup";
import { Route,createRoutesFromElements } from "react-router-dom";

export default createRoutesFromElements(
<Route path="/" >
<Route path="/">
<Route index element={<Root />} />
<Route path="/signup" element={<Signup />} />
<Route path="/login" element={<Login />}/>
<Route path="/dashboard" element={<Dashboard />}/>
<Route path="/dashboard/rules" element={<Rules />}/>
Expand Down
152 changes: 119 additions & 33 deletions webapp/src/pages/Signup.jsx
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>
);
}
}
Loading

0 comments on commit e8d8572

Please sign in to comment.