Final auth design

This commit is contained in:
Daniel Cojocea committed 2024-08-12 13:58:18 -04:00
1 parent 938226015d
commit 12992c8ae1
2 files changed
+60 -61

No files matched your search

+56 -61
View File
@@ -1,4 +1,4 @@
import { Stack, Typography } from "@mui/material"; import { Box, Stack, Typography } from "@mui/material";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { createToast } from "../../Utils/toastUtils"; import { createToast } from "../../Utils/toastUtils";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
@@ -8,10 +8,8 @@ import { credentials } from "../../Validation/validation";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import Field from "../../Components/Inputs/Field"; import Field from "../../Components/Inputs/Field";
import ButtonSpinner from "../../Components/ButtonSpinner"; import ButtonSpinner from "../../Components/ButtonSpinner";
import Button from "../../Components/Button";
import Logo from "../../assets/icons/bwu-icon.svg?react"; import Logo from "../../assets/icons/bwu-icon.svg?react";
import Key from "../../assets/icons/key.svg?react"; import Key from "../../assets/icons/key.svg?react";
import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";
import background from "../../assets/Images/background_pattern_decorative.png"; import background from "../../assets/Images/background_pattern_decorative.png";
import "./index.css"; import "./index.css";
@@ -26,10 +24,6 @@ const ForgotPassword = () => {
email: "", email: "",
}); });
const idMap = {
"forgot-password-email-input": "email",
};
const handleSubmit = async (event) => { const handleSubmit = async (event) => {
event.preventDefault(); event.preventDefault();
@@ -41,11 +35,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));
@@ -72,24 +64,16 @@ 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 (
@@ -128,45 +112,56 @@ const ForgotPassword = () => {
}, },
}, },
}} }}
></Stack> >
{/* <form className="forgot-password-form" onSubmit={handleSubmit}> <Stack gap={theme.gap.large} alignItems="center" textAlign="center">
<Stack direction="column" alignItems="center" gap={theme.gap.small}> <Box>
<Logomark alt="Logomark" style={{ fill: "white" }} /> <Key />
<Typography component="h1" sx={{ mt: theme.gap.ml }}> <Typography component="h1">Forgot password?</Typography>
Forgot password? <Typography>
</Typography> No worries, we'll send you reset instructions.
<Typography> </Typography>
No worries, we'll send you reset instructions. </Box>
</Typography> <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}
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> */}
</Stack> </Stack>
); );
}; };
+4
View File
@@ -136,3 +136,7 @@
width: 100%; width: 100%;
max-width: 800px; max-width: 800px;
} }
.forgot-password-page h1 {
font-size: var(--env-var-font-size-large-plus);
}