Merge branch 'bluewave-labs:master' into monitors

This commit is contained in:
Mohammad Khalilzadeh authored and GitHub committed 2024-06-13 10:47:15 +03:30
commit 67394991b2
15 files changed
+319 -144

No files matched your search

+57 -1
View File
@@ -5,8 +5,60 @@ import Logomark from "../../assets/Images/key-password.png";
import EmailTextField from "../../Components/TextFields/Email/EmailTextField";
import Button from "../../Components/Button";
import LeftArrow from "../../assets/Images/arrow-left.png";
import { useState, useEffect } from "react";
import { recoveryValidation } from "../../Validation/validation";
import axios from "axios";
import { useNavigate } from "react-router-dom";
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
const ForgotPassword = () => {
const navigate = useNavigate();
const [isLoading, setIsLoading] = useState(false); // Used to disable the button while loading so user doesn't submit multiple times
const [errors, setErrors] = useState({});
const [form, setForm] = useState({
email: "",
});
const idMap = {
"forgot-password-email-input": "email",
};
useEffect(() => {
const { error } = recoveryValidation.validate(form);
if (error === undefined) {
setErrors({});
} else {
const validationErrors = error.details.reduce((acc, err) => {
return { ...acc, [err.path[0]]: err.message };
}, {});
setErrors(validationErrors);
}
}, [form]);
const handleInput = (e) => {
const fieldName = idMap[e.target.id];
setForm({ ...form, [fieldName]: e.target.value });
};
const handleSubmit = async () => {
//TODO show loading spinner
setIsLoading(true);
try {
const { error } = recoveryValidation.validate(form);
if (error !== undefined) {
throw error;
}
await axios.post(`${BASE_URL}/auth/recovery/request`, form);
navigate("/check-email");
} catch (error) {
//TODO display error (Toast?)
alert(error);
} finally {
setIsLoading(false);
}
};
return (
<div className="forgot-password-page">
<BackgroundPattern></BackgroundPattern>
@@ -27,12 +79,16 @@ const ForgotPassword = () => {
<div className="forgot-password-v-gap-large"></div>
<div className="forgot-password-body">
<EmailTextField
error={false}
onChange={handleInput}
error={errors.email !== undefined ? true : false}
helperText={errors.email !== undefined ? errors.email : ""}
placeholder="Enter your email"
id="forgot-password-email-input"
/>
<div className="forgot-password-v-gap-medium"></div>
<Button
disabled={errors.email !== undefined || isLoading === true}
onClick={handleSubmit}
level="primary"
label="Reset password"
sx={{
+8 -14
View File
@@ -44,9 +44,10 @@ const Login = () => {
} else {
setErrors({});
}
}, []);
}, [form]);
const handleSubmit = async () => {
const handleSubmit = async (e) => {
e.preventDefault();
try {
await loginValidation.validateAsync(form, { abortEarly: false });
const action = await dispatch(login(form));
@@ -77,15 +78,6 @@ const Login = () => {
};
const handleInput = (e) => {
const fieldName = idMap[e.target.id];
// Extract and validate individual fields as input changes
const fieldSchema = loginValidation.extract(fieldName);
const { error } = fieldSchema.validate(e.target.value);
let errMsg = "";
if (error) {
errMsg = error.message;
}
setErrors({ ...errors, [fieldName]: errMsg });
const newForm = { ...form, [idMap[e.target.id]]: e.target.value };
setForm(newForm);
};
@@ -93,7 +85,7 @@ const Login = () => {
return (
<div className="login-page">
<BackgroundPattern></BackgroundPattern>
<div className="login-form">
<form className="login-form" onSubmit={handleSubmit}>
<div className="login-form-header">
<img
className="login-form-header-logo"
@@ -110,6 +102,7 @@ const Login = () => {
error={errors.email ? true : false}
helperText={errors.email ? errors.email : ""}
placeholder="Enter your email"
autoComplete="email"
id="login-email-input"
/>
<div className="login-form-v2-spacing" />
@@ -118,6 +111,7 @@ const Login = () => {
error={errors.password ? true : false}
helperText={errors.password ? errors.password : ""}
placeholder="Password"
autoComplete="current-password"
id="login-password-input"
/>
</div>
@@ -129,10 +123,10 @@ const Login = () => {
<div className="login-form-v3-spacing" />
<div className="login-form-actions">
<Button
type="submit"
level="primary"
label="Sign in"
sx={{ width: "100%" }}
onClick={handleSubmit}
/>
<div className="login-form-v-spacing" />
<Button
@@ -147,7 +141,7 @@ const Login = () => {
Don’t have an account?
<span className="new-account-option-span">Sign up</span>
</div>
</div>
</form>
</div>
);
};
+77 -86
View File
@@ -1,7 +1,6 @@
import { useState, useEffect } from "react";
import { useNavigate } from "react-router-dom";
import axios from "axios";
import "./index.css";
import BackgroundPattern from "../../Components/BackgroundPattern/BackgroundPattern";
import Logomark from "../../assets/Images/Logomark.png";
@@ -53,23 +52,15 @@ const Register = () => {
} else {
setErrors({});
}
}, []);
}, [form]);
const handleInput = (e) => {
const fieldName = idMap[e.target.id];
// Extract and validate individual fields as input changes
const fieldSchema = registerValidation.extract(fieldName);
const { error } = fieldSchema.validate(e.target.value);
let errMsg = "";
if (error) {
errMsg = error.message;
}
setErrors({ ...errors, [fieldName]: errMsg });
const newForm = { ...form, [idMap[e.target.id]]: e.target.value };
setForm(newForm);
};
const handleSubmit = async () => {
const handleSubmit = async (e) => {
e.preventDefault();
try {
await registerValidation.validateAsync(form, { abortEarly: false });
const action = await dispatch(register(form));
@@ -104,82 +95,82 @@ const Register = () => {
return (
<div className="register-page">
<BackgroundPattern></BackgroundPattern>
<form>
<div className="register-form">
<div className="register-form-header">
<img
className="register-form-header-logo"
src={Logomark}
alt="Logomark"
/>
<div className="register-form-v-spacing-large" />
<div className="register-form-heading">Create an account</div>
<div className="register-form-v-spacing-large"></div>
</div>
<div className="register-form-v-spacing-40px" />
<div className="register-form-inputs">
<StringTextField
onChange={handleInput}
error={errors.firstname ? true : false}
helperText={errors.firstname ? errors.firstname : ""}
label="First name*"
placeholder="Enter your first name"
id="register-firstname-input"
/>
<div className="login-form-v2-spacing" />
<StringTextField
onChange={handleInput}
error={errors.lastname ? true : false}
helperText={errors.lastname ? errors.lastname : ""}
label="Last name*"
placeholder="Enter your last name"
id="register-lastname-input"
/>
<div className="login-form-v2-spacing" />
<EmailTextField
onChange={handleInput}
label="Email*"
error={errors.email ? true : false}
helperText={errors.email ? errors.email : ""}
placeholder="Enter your email"
id="register-email-input"
/>
<div className="login-form-v2-spacing" />
<PasswordTextField
onChange={handleInput}
label="Password*"
error={errors.password ? true : false}
helperText={errors.password ? errors.password : ""}
placeholder="Create a password"
id="register-password-input"
/>
</div>
<div className="login-form-v2-spacing" />
<div className="register-form-checks">
<Check text="Must be at least 8 characters" />
<div className="register-form-v-spacing-small"></div>
<Check text="Must contain one special character" />
</div>
<div className="login-form-v2-spacing" />
<div className="register-form-actions">
<Button
onClick={handleSubmit}
level="primary"
label="Get started"
sx={{ width: "100%" }}
/>
<div className="login-form-v-spacing" />
<Button
disabled={true}
level="secondary"
label="Sign up with Google"
sx={{ width: "100%", color: "#344054", fontWeight: "700" }}
img={<img className="google-enter" src={Google} alt="Google" />}
/>
</div>
<form className="register-form" onSubmit={handleSubmit}>
<div className="register-form-header">
<img
className="register-form-header-logo"
src={Logomark}
alt="Logomark"
/>
<div className="register-form-v-spacing-large" />
<div className="register-form-heading">Create an account</div>
<div className="register-form-v-spacing-large"></div>
</div>
<div className="register-form-v-spacing-40px" />
<div className="register-form-inputs">
<StringTextField
onChange={handleInput}
error={errors.firstname ? true : false}
helperText={errors.firstname ? errors.firstname : ""}
label="First name*"
placeholder="Enter your first name"
id="register-firstname-input"
/>
<div className="login-form-v2-spacing" />
<StringTextField
onChange={handleInput}
error={errors.lastname ? true : false}
helperText={errors.lastname ? errors.lastname : ""}
label="Last name*"
placeholder="Enter your last name"
id="register-lastname-input"
/>
<div className="login-form-v2-spacing" />
<EmailTextField
onChange={handleInput}
label="Email*"
error={errors.email ? true : false}
helperText={errors.email ? errors.email : ""}
placeholder="Enter your email"
autoComplete="email"
id="register-email-input"
/>
<div className="login-form-v2-spacing" />
<PasswordTextField
onChange={handleInput}
label="Password*"
error={errors.password ? true : false}
helperText={errors.password ? errors.password : ""}
placeholder="Create a password"
autoComplete="current-password"
id="register-password-input"
/>
</div>
<div className="login-form-v2-spacing" />
<div className="register-form-checks">
<Check text="Must be at least 8 characters" />
<div className="register-form-v-spacing-small"></div>
<Check text="Must contain one special character" />
</div>
<div className="login-form-v2-spacing" />
<div className="register-form-actions">
<Button
type="submit"
level="primary"
label="Get started"
sx={{ width: "100%" }}
/>
<div className="login-form-v-spacing" />
<Button
disabled={true}
level="secondary"
label="Sign up with Google"
sx={{ width: "100%", color: "#344054", fontWeight: "700" }}
img={<img className="google-enter" src={Google} alt="Google" />}
/>
</div>
<div className="register-bottom-spacing"></div>
</form>
<div className="register-bottom-spacing"></div>
</div>
);
};
+66 -5
View File
@@ -1,14 +1,69 @@
import BackgroundPattern from "../../Components/BackgroundPattern/BackgroundPattern";
import "./index.css";
import React from "react";
import LockIcon from "../../assets/Images/lock-icon.png";
import PasswordTextField from "../../Components/TextFields/Password/PasswordTextField";
import Check from "../../Components/Check/Check";
import Button from "../../Components/Button";
import LeftArrow from "../../assets/Images/arrow-left.png";
import { useParams } from "react-router-dom";
import { useState, useEffect } from "react";
import { newPasswordValidation } from "../../Validation/validation";
import axios from "axios";
const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
import { useNavigate } from "react-router-dom";
const SetNewPassword = () => {
const navigate = useNavigate();
const [errors, setErrors] = useState({});
const [form, setForm] = useState({});
const [isLoading, setIsLoading] = useState(false);
const idMap = {
"register-password-input": "password",
"confirm-password-input": "confirm",
};
const handleInput = (e) => {
const fieldName = idMap[e.target.id];
setForm({ ...form, [fieldName]: e.target.value });
console.log(errors);
};
const handleSubmit = async () => {
// TODO show loading spinner
setIsLoading(true);
try {
await axios.post(`${BASE_URL}/auth/recovery/validate`, {
recoveryToken: token,
});
await axios.post(`${BASE_URL}/auth/recovery/reset`, {
...form,
recoveryToken: token,
});
navigate("/new-password-confirmed");
} catch (error) {
// TODO display error (Toast?)
alert(error.response.data.msg);
} finally {
setIsLoading(false);
}
};
useEffect(() => {
const { error } = newPasswordValidation.validate(form, {
abortEarly: false,
});
if (error) {
const validationErrors = error.details.reduce((acc, err) => {
return { ...acc, [err.path[0]]: err.message };
}, {});
setErrors(validationErrors);
} else {
setErrors({});
}
}, [form]);
const { token } = useParams();
return (
<div className="set-new-password-page">
@@ -31,16 +86,20 @@ const SetNewPassword = () => {
<div className="set-new-password-form-content">
<PasswordTextField
label="Password"
error={false}
onChange={handleInput}
error={errors.password !== undefined ? true : false}
helperText={errors.password !== undefined ? errors.password : ""}
placeholder="••••••••"
id="register-password-input"
/>
<div className="set-new-password-form-gap-medium"></div>
<PasswordTextField
label="Confirm password"
error={false}
onChange={handleInput}
error={errors.confirm !== undefined ? true : false}
helperText={errors.confirm !== undefined ? errors.confirm : ""}
placeholder="••••••••"
id="register-password-input"
id="confirm-password-input"
/>
<div className="set-new-password-form-gap-medium"></div>
<div className="set-new-password-form-checks">
@@ -50,8 +109,10 @@ const SetNewPassword = () => {
</div>
<div className="set-new-password-form-gap-medium"></div>
<Button
disabled={Object.keys(errors).length !== 0 || isLoading === true}
onClick={handleSubmit}
level="primary"
label="Reset passwprd"
label="Reset password"
sx={{
width: "100%",
fontSize: "13px",