Skip to content

Commit

Permalink
feat(RSS-ECOMM-2_13): add relocate new user to main page after regist…
Browse files Browse the repository at this point in the history
…ration (#123)
  • Loading branch information
Kleostro authored May 3, 2024
1 parent b60b3a0 commit cf9c4f0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/widgets/RegistrationForm/model/RegistrationFormModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { UserRegisterData } from '@/shared/types/interfaces.ts';
import getCustomerModel from '@/shared/API/customer/model/CustomerModel.ts';
import serverMessageModel from '@/shared/ServerMessage/model/ServerMessageModel.ts';
import getStore from '@/shared/Store/Store.ts';
import { setRegisterFormCountry } from '@/shared/Store/actions.ts';
import { setCurrentUser, setRegisterFormCountry } from '@/shared/Store/actions.ts';
import observeStore, { selectRegisterFormCountry } from '@/shared/Store/observer.ts';
import {
EVENT_NAMES,
Expand Down Expand Up @@ -139,13 +139,19 @@ class RegisterFormModel {
const customerModel = getCustomerModel();
customerModel
.registrationNewCustomer(formData)
.then(() => {
.then((data) => {
const userInfo = {
email: formData.email,
password: formData.password,
};
customerModel.authCustomer(userInfo).catch(() => {});
customerModel
.authCustomer(userInfo)
.then(() => getStore().dispatch(setCurrentUser(data)))
.catch(() => {});
serverMessageModel.showServerMessage(SERVER_MESSAGE.SUCCESSFUL_REGISTRATION, MESSAGE_STATUS.SUCCESS);
Object.entries(this.isValidInputFields).forEach(([key]) => {
this.isValidInputFields[key] = false;
});
})
.catch(() => serverMessageModel.showServerMessage(SERVER_MESSAGE.INCORRECT_REGISTRATION, MESSAGE_STATUS.ERROR));
});
Expand All @@ -155,6 +161,7 @@ class RegisterFormModel {
private switchSubmitFormButtonAccess(): boolean {
if (Object.values(this.isValidInputFields).every((value) => value)) {
this.view.getSubmitFormButton().setEnabled();
this.view.getSubmitFormButton().getHTML().focus();
} else {
this.view.getSubmitFormButton().setDisabled();
}
Expand Down

0 comments on commit cf9c4f0

Please sign in to comment.