Merge pull request #602 from bluewave-labs/feat/forgot-password-page
Forgot password page
This commit is contained in:
3 files changed
+112
-78
No files matched your search
@@ -1,18 +1,17 @@
|
|||||||
import "./index.css";
|
import { Box, Stack, Typography } from "@mui/material";
|
||||||
import background from "../../assets/Images/background_pattern_decorative.png";
|
import { useTheme } from "@emotion/react";
|
||||||
import Logomark from "../../assets/icons/key.svg?react";
|
|
||||||
import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { credentials } from "../../Validation/validation";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import Field from "../../Components/Inputs/Field";
|
|
||||||
import { createToast } from "../../Utils/toastUtils";
|
import { createToast } from "../../Utils/toastUtils";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { forgotPassword } from "../../Features/Auth/authSlice";
|
import { forgotPassword } from "../../Features/Auth/authSlice";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { credentials } from "../../Validation/validation";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import Field from "../../Components/Inputs/Field";
|
||||||
import ButtonSpinner from "../../Components/ButtonSpinner";
|
import ButtonSpinner from "../../Components/ButtonSpinner";
|
||||||
import { Stack, Typography } from "@mui/material";
|
import Logo from "../../assets/icons/bwu-icon.svg?react";
|
||||||
import { useTheme } from "@emotion/react";
|
import Key from "../../assets/icons/key.svg?react";
|
||||||
import Button from "../../Components/Button";
|
import background from "../../assets/Images/background_pattern_decorative.png";
|
||||||
|
import "./index.css";
|
||||||
|
|
||||||
const ForgotPassword = () => {
|
const ForgotPassword = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -25,9 +24,10 @@ const ForgotPassword = () => {
|
|||||||
email: "",
|
email: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const idMap = {
|
useEffect(() => {
|
||||||
"forgot-password-email-input": "email",
|
const email = sessionStorage.getItem("email");
|
||||||
};
|
email && setForm({ email: sessionStorage.getItem("email") });
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleSubmit = async (event) => {
|
const handleSubmit = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -40,11 +40,9 @@ const ForgotPassword = () => {
|
|||||||
error.details && error.details.length > 0
|
error.details && error.details.length > 0
|
||||||
? error.details[0].message
|
? error.details[0].message
|
||||||
: "Error validating data.";
|
: "Error validating data.";
|
||||||
setErrors(err);
|
setErrors({ email: err });
|
||||||
createToast({
|
createToast({
|
||||||
variant: "info",
|
|
||||||
body: err,
|
body: err,
|
||||||
hasIcon: false,
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const action = await dispatch(forgotPassword(form));
|
const action = await dispatch(forgotPassword(form));
|
||||||
@@ -71,72 +69,105 @@ const ForgotPassword = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
const { value, id } = event.target;
|
const { value } = event.target;
|
||||||
const name = idMap[id];
|
setForm({ email: value });
|
||||||
setForm((prev) => ({
|
|
||||||
...prev,
|
|
||||||
[name]: value,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const { error } = credentials.validate(
|
const { error } = credentials.validate(
|
||||||
{ [name]: value },
|
{ email: value },
|
||||||
{ abortEarly: false }
|
{ abortEarly: false }
|
||||||
);
|
);
|
||||||
|
|
||||||
setErrors((prev) => {
|
if (error) setErrors({ email: error.details[0].message });
|
||||||
const prevErrors = { ...prev };
|
else delete errors.email;
|
||||||
if (error) prevErrors[name] = error.details[0].message;
|
|
||||||
else delete prevErrors[name];
|
|
||||||
return prevErrors;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="forgot-password-page">
|
<Stack className="forgot-password-page auth" overflow="hidden">
|
||||||
<img
|
<img
|
||||||
className="background-pattern-svg"
|
className="background-pattern-svg"
|
||||||
src={background}
|
src={background}
|
||||||
alt="background pattern"
|
alt="background pattern"
|
||||||
/>
|
/>
|
||||||
<form className="forgot-password-form" onSubmit={handleSubmit}>
|
<Stack
|
||||||
<Stack direction="column" alignItems="center" gap={theme.gap.small}>
|
direction="row"
|
||||||
<Logomark alt="Logomark" style={{ fill: "white" }} />
|
alignItems="center"
|
||||||
<Typography component="h1" sx={{ mt: theme.gap.ml }}>
|
px={theme.gap.large}
|
||||||
Forgot password?
|
gap={theme.gap.small}
|
||||||
</Typography>
|
>
|
||||||
<Typography>
|
<Logo style={{ borderRadius: theme.shape.borderRadius }} />
|
||||||
No worries, we'll send you reset instructions.
|
<Typography sx={{ userSelect: "none" }}>BlueWave Uptime</Typography>
|
||||||
</Typography>
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
width="100%"
|
||||||
|
maxWidth={600}
|
||||||
|
flex={1}
|
||||||
|
justifyContent="center"
|
||||||
|
p={theme.gap.xl}
|
||||||
|
pb={theme.gap.triplexl}
|
||||||
|
mx="auto"
|
||||||
|
sx={{
|
||||||
|
"& > .MuiStack-root": {
|
||||||
|
border: 1,
|
||||||
|
borderRadius: theme.shape.borderRadius,
|
||||||
|
borderColor: theme.palette.otherColors.graishWhite,
|
||||||
|
backgroundColor: theme.palette.otherColors.white,
|
||||||
|
padding: {
|
||||||
|
xs: theme.gap.large,
|
||||||
|
sm: theme.gap.xl,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Stack gap={theme.gap.large} alignItems="center" textAlign="center">
|
||||||
|
<Box>
|
||||||
|
<Key />
|
||||||
|
<Typography component="h1">Forgot password?</Typography>
|
||||||
|
<Typography>
|
||||||
|
No worries, we'll send you reset instructions.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box width="100%" maxWidth={400} textAlign="left">
|
||||||
|
<form noValidate spellCheck={false} onSubmit={handleSubmit}>
|
||||||
|
<Field
|
||||||
|
type="email"
|
||||||
|
id="forgot-password-email-input"
|
||||||
|
label="Email"
|
||||||
|
isRequired={true}
|
||||||
|
placeholder="Enter your email"
|
||||||
|
value={form.email}
|
||||||
|
onChange={handleChange}
|
||||||
|
error={errors.email}
|
||||||
|
/>
|
||||||
|
<ButtonSpinner
|
||||||
|
disabled={errors.email !== undefined}
|
||||||
|
onClick={handleSubmit}
|
||||||
|
isLoading={isLoading}
|
||||||
|
level="primary"
|
||||||
|
label="Send instructions"
|
||||||
|
sx={{
|
||||||
|
width: "100%",
|
||||||
|
fontWeight: 400,
|
||||||
|
mt: theme.gap.mlplus,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack gap={theme.gap.ml} sx={{ mt: `calc(${theme.gap.ml}*2)` }}>
|
</Stack>
|
||||||
<Field
|
<Box textAlign="center" p={theme.gap.large}>
|
||||||
type="email"
|
<Typography display="inline-block">Go back to —</Typography>
|
||||||
id="forgot-password-email-input"
|
<Typography
|
||||||
label="Email"
|
component="span"
|
||||||
isRequired={true}
|
ml={theme.gap.xs}
|
||||||
placeholder="Enter your email"
|
onClick={() => {
|
||||||
value={form.email}
|
navigate("/login");
|
||||||
onChange={handleChange}
|
}}
|
||||||
error={errors.email}
|
sx={{ userSelect: "none" }}
|
||||||
/>
|
>
|
||||||
<ButtonSpinner
|
Log In
|
||||||
disabled={errors.email !== undefined}
|
</Typography>
|
||||||
onClick={handleSubmit}
|
</Box>
|
||||||
isLoading={isLoading}
|
</Stack>
|
||||||
level="primary"
|
|
||||||
label="Reset password"
|
|
||||||
sx={{ mb: theme.gap.medium }}
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
level="tertiary"
|
|
||||||
label="Back to log in"
|
|
||||||
img={<ArrowBackRoundedIcon />}
|
|
||||||
sx={{ alignSelf: "center", width: "fit-content" }}
|
|
||||||
onClick={() => navigate("/login")}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -154,6 +154,13 @@ const StepTwo = ({ form, errors, onSubmit, onChange, onBack }) => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleNavigate = () => {
|
||||||
|
if (form.email !== "" && !errors.email) {
|
||||||
|
sessionStorage.setItem("email", form.email);
|
||||||
|
}
|
||||||
|
navigate("/forgot-password");
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack gap={theme.gap.large} textAlign="center">
|
<Stack gap={theme.gap.large} textAlign="center">
|
||||||
@@ -209,7 +216,7 @@ const StepTwo = ({ form, errors, onSubmit, onChange, onBack }) => {
|
|||||||
component="span"
|
component="span"
|
||||||
ml={theme.gap.xs}
|
ml={theme.gap.xs}
|
||||||
sx={{ userSelect: "none" }}
|
sx={{ userSelect: "none" }}
|
||||||
onClick={() => navigate("/forgot-password")}
|
onClick={handleNavigate}
|
||||||
>
|
>
|
||||||
Reset password
|
Reset password
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
/* ////// */
|
/* ////// */
|
||||||
.set-new-password-page,
|
.set-new-password-page,
|
||||||
.password-confirmed-page,
|
.password-confirmed-page,
|
||||||
.forgot-password-page,
|
|
||||||
.check-email-page {
|
.check-email-page {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -11,7 +10,6 @@
|
|||||||
}
|
}
|
||||||
.set-new-password-page h1.MuiTypography-root,
|
.set-new-password-page h1.MuiTypography-root,
|
||||||
.password-confirmed-page h1.MuiTypography-root,
|
.password-confirmed-page h1.MuiTypography-root,
|
||||||
.forgot-password-page h1.MuiTypography-root,
|
|
||||||
.check-email-page h1.MuiTypography-root {
|
.check-email-page h1.MuiTypography-root {
|
||||||
font-size: var(--env-var-font-size-large);
|
font-size: var(--env-var-font-size-large);
|
||||||
color: var(--env-var-color-1);
|
color: var(--env-var-color-1);
|
||||||
@@ -21,8 +19,6 @@
|
|||||||
.set-new-password-page button,
|
.set-new-password-page button,
|
||||||
.password-confirmed-page p.MuiTypography-root,
|
.password-confirmed-page p.MuiTypography-root,
|
||||||
.password-confirmed-page button,
|
.password-confirmed-page button,
|
||||||
.forgot-password-page p.MuiTypography-root,
|
|
||||||
.forgot-password-page button,
|
|
||||||
.check-email-page p.MuiTypography-root,
|
.check-email-page p.MuiTypography-root,
|
||||||
.check-email-page button,
|
.check-email-page button,
|
||||||
.check-email-page span.MuiTypography-root {
|
.check-email-page span.MuiTypography-root {
|
||||||
@@ -30,7 +26,6 @@
|
|||||||
}
|
}
|
||||||
.set-new-password-page button:not(.MuiIconButton-root),
|
.set-new-password-page button:not(.MuiIconButton-root),
|
||||||
.password-confirmed-page button:not(.MuiIconButton-root),
|
.password-confirmed-page button:not(.MuiIconButton-root),
|
||||||
.forgot-password-page button:not(.MuiIconButton-root),
|
|
||||||
.check-email-page button:not(.MuiIconButton-root) {
|
.check-email-page button:not(.MuiIconButton-root) {
|
||||||
height: 34px;
|
height: 34px;
|
||||||
border-radius: var(--env-var-radius-2);
|
border-radius: var(--env-var-radius-2);
|
||||||
@@ -39,21 +34,18 @@
|
|||||||
|
|
||||||
.set-new-password-form,
|
.set-new-password-form,
|
||||||
.password-confirmed-form,
|
.password-confirmed-form,
|
||||||
.forgot-password-form,
|
|
||||||
.check-email-form {
|
.check-email-form {
|
||||||
margin-top: 65px;
|
margin-top: 65px;
|
||||||
width: var(--env-var-width-2);
|
width: var(--env-var-width-2);
|
||||||
}
|
}
|
||||||
.set-new-password-page p.MuiTypography-root,
|
.set-new-password-page p.MuiTypography-root,
|
||||||
.password-confirmed-page p.MuiTypography-root,
|
.password-confirmed-page p.MuiTypography-root,
|
||||||
.forgot-password-page p.MuiTypography-root,
|
|
||||||
.check-email-page p.MuiTypography-root {
|
.check-email-page p.MuiTypography-root {
|
||||||
color: var(--env-var-color-2);
|
color: var(--env-var-color-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.set-new-password-page button:not(.MuiIconButton-root) svg,
|
.set-new-password-page button:not(.MuiIconButton-root) svg,
|
||||||
.password-confirmed-page button:not(.MuiIconButton-root) svg,
|
.password-confirmed-page button:not(.MuiIconButton-root) svg,
|
||||||
.forgot-password-page button svg,
|
|
||||||
.check-email-page button svg {
|
.check-email-page button svg {
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
@@ -147,3 +139,7 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.forgot-password-page h1 {
|
||||||
|
font-size: var(--env-var-font-size-large-plus);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user