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 all commits
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
23 changes: 10 additions & 13 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,7 +323,8 @@ 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
Expand Down