(event)
| 80 | } |
| 81 | |
| 82 | const validateAndSubmit = async (event) => { |
| 83 | event.preventDefault() |
| 84 | const validationErrors = [] |
| 85 | setAuthErrors([]) |
| 86 | setAuthRateLimitError(null) |
| 87 | if (!tokenVal) { |
| 88 | validationErrors.push('Token cannot be left blank!') |
| 89 | } |
| 90 | if (newPasswordVal !== confirmPasswordVal) { |
| 91 | validationErrors.push('New Password and Confirm Password do not match.') |
| 92 | } |
| 93 | const passwordErrors = validatePassword(newPasswordVal) |
| 94 | if (passwordErrors.length > 0) { |
| 95 | validationErrors.push(...passwordErrors) |
| 96 | } |
| 97 | if (validationErrors.length > 0) { |
| 98 | setAuthErrors(validationErrors) |
| 99 | return |
| 100 | } |
| 101 | const body = { |
| 102 | user: { |
| 103 | email: emailVal, |
| 104 | tempToken: tokenVal, |
| 105 | password: newPasswordVal |
| 106 | } |
| 107 | } |
| 108 | setLoading(true) |
| 109 | try { |
| 110 | const updateResponse = await accountApi.resetPassword(body) |
| 111 | setAuthErrors([]) |
| 112 | setLoading(false) |
| 113 | if (updateResponse.data) { |
| 114 | enqueueSnackbar({ |
| 115 | message: 'Password reset successful', |
| 116 | options: { |
| 117 | key: new Date().getTime() + Math.random(), |
| 118 | variant: 'success', |
| 119 | action: (key) => ( |
| 120 | <Button style={{ color: 'white' }} onClick={() => closeSnackbar(key)}> |
| 121 | <IconX /> |
| 122 | </Button> |
| 123 | ) |
| 124 | } |
| 125 | }) |
| 126 | setEmailVal('') |
| 127 | setTokenVal('') |
| 128 | setNewPasswordVal('') |
| 129 | setConfirmPasswordVal('') |
| 130 | goLogin() |
| 131 | } |
| 132 | } catch (error) { |
| 133 | setLoading(false) |
| 134 | setAuthErrors([typeof error.response.data === 'object' ? error.response.data.message : error.response.data]) |
| 135 | enqueueSnackbar({ |
| 136 | message: `Failed to reset password!`, |
| 137 | options: { |
| 138 | key: new Date().getTime() + Math.random(), |
| 139 | variant: 'error', |
nothing calls this directly
no test coverage detected