Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Add the ability to change password from edit profile form #968

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

coderatomy
Copy link
Collaborator

@coderatomy coderatomy commented Oct 26, 2023

Summary

fixes #904
Adds ability to change password from /edit-profile

Changes

  • Improves validation and error handling in the Edit Profile form
  • Improves how form submission is handled. Utilizing the handleSubmit function from formik such that form submission is immediately cancelled if any validation errors exist. Sometimes our custom validation can have some loop holes.

Screencasts

Screencast.from.2023-10-26.15-27-09.webm

"changePassword": {
"newPassword": "Change Password",
"confirmNewPassword": "Retype new password",
"error": "<1/> {{errorMessage}}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a custom Component and an error message

@@ -117,7 +122,7 @@ function EditProfile(props) {
className="auth-form"
name="signup"
noValidate="noValidate"
onSubmit={e => editProfile(e, props, toast)}
onSubmit={props.handleSubmit}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utilizing the formik handleSubmit for better security in terms of validation

user_location: '',
bio: '',
}),
validationSchema,
handleSubmit: (values, { props }) => {
return editProfile(values, props, toast)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assigning the editProfile with the validated data

is: (newPassword) => newPassword && newPassword.length > 0,
then: Yup.string().oneOf([Yup.ref('newPassword')], 'Passwords must match').required('Retype new password'),
otherwise: Yup.string().notRequired(),
}),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improving the schema for better error handling

(props.errors['password'] &&
<Trans t={t} i18nextKey="editProfile.inputs.changePassword.error">
<ErrorIcon fontSize="small" /> {{errorMessage: props.errors['password']}}
</Trans>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the Trans component from react-i18next to improve the field error message with Icons

@NdibeRaymond
Copy link
Collaborator

hello @coderatomy , you did a great job here! Thanks for that! few things that I'd like us to deliberate on:

  • have something against having the option to change the password alongside other things here (I didn't follow the conversation on the issue or I would have said the same thing there. I am also going to mention @srish and @tuxology here so they can give their opinion). It's been the standard practice to separate these two flows as one deals with a general change of data while the other deals with a kind of change that can affect a user's ability to log in. We can have a link from the edit-profile page that takes us to the change-password page, but both should not be on the same page. additionally, there should be some form of re-authentication before a user can be redirected to the change-password page (I think we missed implementing this before but it is important).

What I propose is something like this [some link on the edit-profile page] ------------> [page where the user re-authenticates with their old password] -------------------------------> [change-password page]

@tuxology
Copy link
Member

@NdibeRaymond I agree about this as well. I see that @srish approved this more simple design here (#904 (comment)). I think the rationale why we have mixed both "Edit Profile" and "Account Settings" workflow is because the Edit Profile page allows you to change username, location, personal details etc. Which is very similar to "account" related info. Hence, we can, for now also allow changing password via that workflow as well. We can have a dedicated change password/account settings button some where which can do a similar workflow as yours and then we can phase out this change. We would need UX input for that and I think it would look similar to your approach

@@ -113,6 +113,11 @@ const styles = theme => ({
color: 'var(--primary-color2)',
},
fieldHelperTextStyle: {
'&.MuiFormHelperText-root.Mui-error': {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try sending the classnames to mui component rather than using their generated class names. it would hassle when upgrading libraries as they change how the classnames (or styles) (they usually support it) are created or update dom structure

<ErrorComponent classNames={{
errorComponent: classNames.myErrorClassName
}} />

<InputLabel
className={classes.customLabelStyle}
htmlFor="password"
<Grid container style={{ display: 'block'}}>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you changing the grid system to block? its just gonno affect responsiveness

FYI If you aare changing to block system just use div instead

endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

labels need translations

@@ -221,7 +216,15 @@ export const handleTooltipClose = () => {
export const validationSchema = Yup.object().shape({
username: Yup.string().required('required'),
user_location: Yup.string().min(1, 'min').required('required'),
password: Yup.string().required('required'),
password: Yup.string().required('Your password is required'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the errors needs translation

@aqsaaqeel
Copy link
Contributor

hey @coderatomy please link this PR to #984 so that redundant work can be avoided. Once this PR is merged I can work on moving the edit profile to the sidenav. Thanks!

@coderatomy
Copy link
Collaborator Author

coderatomy commented Nov 15, 2023

hey @aqsaaqeel , i think you can go on with this, just go through the comments here to get the context, then get out what might be useful from this PR and use it. My main priority now is on the Migrations. Kindly help me with that.

@aqsaaqeel
Copy link
Contributor

hey @aqsaaqeel , i think you can go on with this, just go through the comments here to get the context, then get out what might be useful from this PR and use it. My main priority now is on the Migrations. Kindly help me with that.

Alright!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the ability to change password from edit profile form
5 participants