fix(ui): user invitation (#2945)

This commit is contained in:
Shekar Siri 2025-01-13 13:52:44 +01:00 committed by GitHub
parent f8a18006d3
commit 262392f32a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 13 deletions

View file

@ -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"

View file

@ -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');

View file

@ -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) {