feat: fixing PAssword Panel

This commit is contained in:
Caio Cabral committed 2024-10-31 14:43:09 -04:00
1 parent 40ef5c9be4
commit b36a5d028e
3 files changed
+68 -66

No files matched your search

-34
View File
@@ -1,34 +0,0 @@
- [x] Change schema to fix validations
- [x] Refactor to apply Single Responsibility Principle to validation (validation is done on joi only)
- [ ] Validation on change
- [ ] Validation on submit
- [ ] Take validation out from the component.
- [x] SetNewPassword
- [x] Register
- [ ] Refactor on change to deal with step three specificity
- [ ] Fix Input enter not working
- [ ] PasswordPanel
- [ ] Login
- [x] Update check component to accept not highlighted text
- [x] Split some of these user feedbacks? Like:
- [x] Must contain at least one special character,
- [x] Must contain at least one number,
- [x] Must contain at least one upper character,
- [x] Must contain at least one lower character
- [x] Pass mismatching password user feedback as the other messages, for consistency
- [ ] Get rid of toast message
- [x] Tests
- [x] Valid Password and Matching Confirmation
- [x] Valid Password, Incorrect Confirmation, then Corrects confirmation
- [x] Password Update to Match Confirm Password
- [x] Short Password with Matching Confirmation
- [x] Invalid Password Format, Correct Confirmation
- [x] Empty Password Field with Confirmation Filled
- [x] Confirm Password Left Blank
- [x] Password Change After Successful Match
- [x] Avoid submission in new password if password or confirm empty, and on error
- [ ] Update validation for password on backend
//TODO Apply custom hook to SetNewPassword
// Enter on input triggers back action on steps one and two
// When user registers, we see sign up page for half a second
@@ -29,13 +29,21 @@ const PasswordPanel = () => {
"edit-confirm-password": "confirm", "edit-confirm-password": "confirm",
}; };
const errorsMap = {
length: "Must be at least 8 characters long",
uppercase: "Must contain at least one upper character",
lowercase: "Must contain at least one lower character",
number: "Must contain at least one number",
special: "Must contain at least one special character",
different: "Confirm password and password must match",
};
const [localData, setLocalData] = useState({ const [localData, setLocalData] = useState({
password: "", password: "",
newPassword: "", newPassword: "",
confirm: "", confirm: "",
}); });
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
const handleChange = (event) => { const handleChange = (event) => {
const { value, id } = event.target; const { value, id } = event.target;
const name = idToName[id]; const name = idToName[id];
@@ -110,20 +118,32 @@ const PasswordPanel = () => {
onSubmit={handleSubmit} onSubmit={handleSubmit}
noValidate noValidate
spellCheck="false" spellCheck="false"
gap={theme.spacing(20)} gap={theme.spacing(26)}
maxWidth={"80ch"}
marginInline={"auto"}
> >
<Stack direction="row"> <Field
<Box flex={0.9}> type="text"
<Typography component="h1">Current password</Typography> id="hidden-username"
</Box> name="username"
<Field autoComplete="username"
type="text" hidden={true}
id="hidden-username" value=""
name="username" />
autoComplete="username"
hidden={true} <Stack
value="" direction="row"
/> justifyContent={"flex-start"}
alignItems={"center"}
gap={theme.spacing(8)}
flexWrap={"wrap"}
>
<Typography
component="h1"
width="20ch"
>
Current password
</Typography>
<Field <Field
type="password" type="password"
id="edit-current-password" id="edit-current-password"
@@ -131,13 +151,22 @@ const PasswordPanel = () => {
autoComplete="current-password" autoComplete="current-password"
value={localData.password} value={localData.password}
onChange={handleChange} onChange={handleChange}
error={errors[idToName["edit-current-password"]]} error={errorsMap[errors[idToName["edit-current-password"]]]}
/> />
</Stack> </Stack>
<Stack direction="row"> <Stack
<Box flex={0.9}> direction="row"
<Typography component="h1">New password</Typography> alignItems={"center"}
</Box> gap={theme.spacing(8)}
flexWrap={"wrap"}
>
<Typography
component="h1"
width="20ch"
>
New password
</Typography>
<Field <Field
type="password" type="password"
id="edit-new-password" id="edit-new-password"
@@ -145,13 +174,22 @@ const PasswordPanel = () => {
autoComplete="new-password" autoComplete="new-password"
value={localData.newPassword} value={localData.newPassword}
onChange={handleChange} onChange={handleChange}
error={errors[idToName["edit-new-password"]]} error={errorsMap[errors[idToName["edit-new-password"]]]}
/> />
</Stack> </Stack>
<Stack direction="row"> <Stack
<Box flex={0.9}> direction="row"
<Typography component="h1">Confirm new password</Typography> alignItems={"center"}
</Box> gap={theme.spacing(8)}
flexWrap={"wrap"}
>
<Typography
component="h1"
width="20ch"
>
Confirm new password
</Typography>
<Field <Field
type="password" type="password"
id="edit-confirm-password" id="edit-confirm-password"
@@ -159,18 +197,17 @@ const PasswordPanel = () => {
autoComplete="new-password" autoComplete="new-password"
value={localData.confirm} value={localData.confirm}
onChange={handleChange} onChange={handleChange}
error={errors[idToName["edit-confirm-password"]]} error={errorsMap[errors[idToName["edit-confirm-password"]]]}
/> />
</Stack> </Stack>
<Stack direction="row"> {Object.keys(errors).length > 0 && (
<Box flex={0.9}></Box> <Box sx={{ maxWidth: "70ch" }}>
<Box sx={{ flex: 1 }}>
<Alert <Alert
variant="warning" variant="warning"
body="New password must contain at least 8 characters and must have at least one uppercase letter, one number and one symbol." body="New password must contain at least 8 characters and must have at least one uppercase letter, one lowercase letter, one number and one special character."
/> />
</Box> </Box>
</Stack> )}
<Stack <Stack
direction="row" direction="row"
justifyContent="flex-end" justifyContent="flex-end"
@@ -178,7 +215,7 @@ const PasswordPanel = () => {
<LoadingButton <LoadingButton
variant="contained" variant="contained"
color="primary" color="primary"
onClick={handleSubmit} type="submit"
loading={isLoading} loading={isLoading}
loadingIndicator="Saving..." loadingIndicator="Saving..."
disabled={Object.keys(errors).length !== 0 && true} disabled={Object.keys(errors).length !== 0 && true}
@@ -149,7 +149,6 @@ function StepThree({ onSubmit, onBack }) {
type="submit" type="submit"
variant="contained" variant="contained"
color="primary" color="primary"
/* onClick={onSubmit} */
disabled={ disabled={
form.password.length === 0 || form.password.length === 0 ||
form.confirm.length === 0 || form.confirm.length === 0 ||