From 662c9656431f81fbee462ef528f1652cc561c154 Mon Sep 17 00:00:00 2001 From: Jose Sampaio Date: Thu, 28 Apr 2022 14:59:48 +0000 Subject: [PATCH 1/2] Fix password modal not sending userId to lib-core --- src/Components/ProfileMenu/ResetPassword.js | 26 ++++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Components/ProfileMenu/ResetPassword.js b/src/Components/ProfileMenu/ResetPassword.js index a3ff5e68..a2800167 100644 --- a/src/Components/ProfileMenu/ResetPassword.js +++ b/src/Components/ProfileMenu/ResetPassword.js @@ -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 }); @@ -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] ); /** @@ -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); @@ -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: "" }; export default ResetPasswordModal; From 3390cca30aa3816318b105f38223ffe194500ce5 Mon Sep 17 00:00:00 2001 From: Jose Sampaio Date: Fri, 29 Apr 2022 10:25:01 +0000 Subject: [PATCH 2/2] Remove userId from default props --- src/Components/ProfileMenu/ResetPassword.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Components/ProfileMenu/ResetPassword.js b/src/Components/ProfileMenu/ResetPassword.js index a2800167..6fcfb157 100644 --- a/src/Components/ProfileMenu/ResetPassword.js +++ b/src/Components/ProfileMenu/ResetPassword.js @@ -66,7 +66,7 @@ const REQUIRED_INPUTS = { */ const ResetPasswordModal = forwardRef((props, ref) => { // Props - const { variant, userId } = props; + const { variant, userId = "" } = props; // State hooks const [form, setForm] = useState({ ...DEFAULT_VALUES }); const [errors, setErrors] = useState({ ...DEFAULT_ERRORS }); @@ -327,8 +327,7 @@ ResetPasswordModal.propTypes = { userId: PropTypes.string }; ResetPasswordModal.defaultProps = { - variant: VARIANT_OPTIONS.CHANGE, - userId: "" + variant: VARIANT_OPTIONS.CHANGE }; export default ResetPasswordModal;