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

Feature/FP-1720 - Fix reset password not working #100

Merged
merged 2 commits into from
Apr 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions src/Components/ProfileMenu/ResetPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const REQUIRED_INPUTS = {
*/
const ResetPasswordModal = forwardRef((props, ref) => {
// Props
const { variant } = props;
const { variant, userId } = props;
// State hooks
const [form, setForm] = useState({ ...DEFAULT_VALUES });
const [errors, setErrors] = useState({ ...DEFAULT_ERRORS });
Expand Down Expand Up @@ -105,15 +105,11 @@ const ResetPasswordModal = forwardRef((props, ref) => {
*/
const updatePassword = useCallback(
body => {
const METHOD = {
[VARIANT_OPTIONS.CHANGE]: user.changePassword,
[VARIANT_OPTIONS.RESET]: user.resetPassword
};
return variant in METHOD
? METHOD[variant](body)
: user.changePassword(body);
if (variant === VARIANT_OPTIONS.RESET)
return User.resetPassword(userId, body);
return user.changePassword(body);
},
[variant]
[variant, userId]
);

/**
Expand All @@ -122,9 +118,9 @@ const ResetPasswordModal = forwardRef((props, ref) => {
*/
const changePassword = async () => {
const body = {
current_password: form[FORM_FIELDS.CURRENT_PASSWORD],
new_password: form[FORM_FIELDS.NEW_PASSWORD],
confirm_password: form[FORM_FIELDS.CONFIRM_PASSWORD]
CurrentPassword: form[FORM_FIELDS.CURRENT_PASSWORD],
NewPassword: form[FORM_FIELDS.NEW_PASSWORD],
ConfirmPassword: form[FORM_FIELDS.CONFIRM_PASSWORD]
};
// Request password update
setLoading(true);
Expand Down Expand Up @@ -327,10 +323,12 @@ const ResetPasswordModal = forwardRef((props, ref) => {
});

ResetPasswordModal.propTypes = {
variant: PropTypes.oneOf(Object.values(VARIANT_OPTIONS)) // change password or reset password
variant: PropTypes.oneOf(Object.values(VARIANT_OPTIONS)), // change password or reset password
userId: PropTypes.string
};
ResetPasswordModal.defaultProps = {
variant: VARIANT_OPTIONS.CHANGE
variant: VARIANT_OPTIONS.CHANGE,
userId: ""
};
Copy link
Contributor

Choose a reason for hiding this comment

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

We should consider stop using defaultProps on functional components as it will become deprecated (you can add the default value for props on the props parameter)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the update. Done


export default ResetPasswordModal;