fix(ui): user invitation
This commit is contained in:
parent
f8a18006d3
commit
594c869906
3 changed files with 21 additions and 13 deletions
|
|
@ -32,13 +32,7 @@ function CreatePassword(props: Props) {
|
|||
if (!validatePassword(password)) {
|
||||
return;
|
||||
}
|
||||
resetPassword({ invitation, pass, password }).then((response: any) => {
|
||||
if (response && response.errors && response.errors.length > 0) {
|
||||
setError(response.errors[0]);
|
||||
} else {
|
||||
setUpdated(true);
|
||||
}
|
||||
});
|
||||
void resetPassword({ invitation, pass, password });
|
||||
};
|
||||
|
||||
const onSubmit = (e: any) => {
|
||||
|
|
@ -102,7 +96,7 @@ function CreatePassword(props: Props) {
|
|||
/>
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<label>{'Cofirm password'}</label>
|
||||
<label>{'Confirm password'}</label>
|
||||
<Input
|
||||
autoComplete="new-password"
|
||||
type="password"
|
||||
|
|
|
|||
|
|
@ -385,6 +385,8 @@ class UserStore {
|
|||
const data = await userService.resetPassword(params);
|
||||
runInAction(() => {
|
||||
this.account = new Account(data.user);
|
||||
this.jwt = data.jwt;
|
||||
this.spotJwt = data.spotJwt;
|
||||
});
|
||||
} catch (error) {
|
||||
toast.error('Error resetting your password; please try again');
|
||||
|
|
|
|||
|
|
@ -136,11 +136,23 @@ export default class UserService {
|
|||
.then((response: { data: any }) => response as Record<string, any> || {});
|
||||
}
|
||||
|
||||
resetPassword(data: any) {
|
||||
return this.client
|
||||
.post('/password/reset', data)
|
||||
.then((response: { json: () => any }) => response.json())
|
||||
.then((response: { data: any }) => response.data || {});
|
||||
async resetPassword(data: any) {
|
||||
try {
|
||||
const response = await this.client.post('/password/reset', data);
|
||||
const responseData = await response.json();
|
||||
if (responseData.errors) {
|
||||
throw new Error(responseData.errors[0] || 'An unexpected error occurred.');
|
||||
}
|
||||
|
||||
return responseData || {};
|
||||
} catch (error: any) {
|
||||
if (error.response) {
|
||||
const errorData = await error.response.json();
|
||||
const errorMessage = errorData.errors ? errorData.errors[0] : 'An unexpected error occurred.';
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
throw new Error('An unexpected error occurred.');
|
||||
}
|
||||
}
|
||||
|
||||
async requestResetPassword(data: any) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue