Skip to content

Commit

Permalink
fix: rerouting to main
Browse files Browse the repository at this point in the history
  • Loading branch information
Kleostro committed May 10, 2024
1 parent 07c0020 commit a6d1aac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 45 deletions.
4 changes: 1 addition & 3 deletions src/app/App/model/AppModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ class AppModel {
};

const routes = new Map<string, () => Promise<Page>>();
Object.entries(routesMap).forEach(([key, value]) => {
routes.set(key, value);
});
Object.entries(routesMap).forEach(([key, value]) => routes.set(key, value));

return Promise.resolve(routes);
}
Expand Down
16 changes: 8 additions & 8 deletions src/shared/Loader/view/loaderView.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
}

.small {
border: 2px solid var(--noble-gray-200);
border-top: 2px solid var(--steam-green-800);
width: 10px;
height: 10px;
}

.medium {
border: 4px solid var(--noble-gray-200);
border-top: 4px solid var(--steam-green-800);
width: 20px;
height: 20px;
}

.large {
.medium {
border: 8px solid var(--noble-gray-200);
border-top: 8px solid var(--steam-green-800);
width: 30px;
height: 30px;
}

.large {
border: 10px solid var(--noble-gray-200);
border-top: 10px solid var(--steam-green-800);
width: 40px;
height: 40px;
}

@keyframes spin {
0% {
transform: rotate(0deg);
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/LoginForm/model/LoginFormModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LoginFormModel {

private loginUser(userLoginData: UserCredentials): void {
this.view.getSubmitFormButton().setDisabled();
const loader = new LoaderModel(SIZES.MEDIUM).getHTML();
const loader = new LoaderModel(SIZES.SMALL).getHTML();
this.view.getSubmitFormButton().getHTML().append(loader);
getCustomerModel()
.hasEmail(userLoginData.email)
Expand All @@ -62,7 +62,7 @@ class LoginFormModel {
}

private loginUserHandler(userLoginData: UserCredentials): void {
const loader = new LoaderModel(SIZES.MEDIUM).getHTML();
const loader = new LoaderModel(SIZES.SMALL).getHTML();
this.view.getSubmitFormButton().getHTML().append(loader);
getCustomerModel()
.authCustomer(userLoginData)
Expand Down
39 changes: 7 additions & 32 deletions src/widgets/RegistrationForm/model/RegistrationFormModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type InputFieldModel from '@/entities/InputField/model/InputFieldModel.ts';
import type { AddressType } from '@/shared/types/address.ts';
import type { Address, PersonalData, User, UserCredentials } from '@/shared/types/user.ts';
import type { Address, PersonalData, User } from '@/shared/types/user.ts';

import AddressModel from '@/entities/Address/model/AddressModel.ts';
import getCustomerModel, { CustomerModel } from '@/shared/API/customer/model/CustomerModel.ts';
Expand All @@ -13,7 +13,6 @@ import { MESSAGE_STATUS, SERVER_MESSAGE } from '@/shared/constants/messages.ts';
import { SIZES } from '@/shared/constants/sizes.ts';
import { ADDRESS_TYPE } from '@/shared/types/address.ts';
import formattedText from '@/shared/utils/formattedText.ts';
import { createGreetingMessage } from '@/shared/utils/messageTemplate.ts';

import RegistrationFormView from '../view/RegistrationFormView.ts';

Expand Down Expand Up @@ -69,13 +68,6 @@ class RegisterFormModel {
return currentUserData;
}

private getCredentialsData(): UserCredentials {
return {
email: this.view.getEmailField().getView().getValue(),
password: this.view.getPasswordField().getView().getValue(),
};
}

private getFormUserData(): User {
const userData: User = {
addresses: [],
Expand Down Expand Up @@ -125,28 +117,8 @@ class RegisterFormModel {
return true;
}

private loginUser(userLoginData: UserCredentials): void {
const loader = new LoaderModel(SIZES.MEDIUM).getHTML();
this.view.getSubmitFormButton().getHTML().append(loader);
getCustomerModel()
.authCustomer(userLoginData)
.then((data) => {
if (data) {
getStore().dispatch(switchIsUserLoggedIn(true));
serverMessageModel.showServerMessage(createGreetingMessage(), MESSAGE_STATUS.SUCCESS);
}
})
.catch(() => {
serverMessageModel.showServerMessage(
SERVER_MESSAGE[getStore().getState().currentLanguage].INCORRECT_PASSWORD,
MESSAGE_STATUS.ERROR,
);
})
.finally(() => loader.remove());
}

private registerUser(): void {
const loader = new LoaderModel(SIZES.MEDIUM).getHTML();
const loader = new LoaderModel(SIZES.SMALL).getHTML();
this.view.getSubmitFormButton().getHTML().append(loader);
getCustomerModel()
.registerNewCustomer(this.getFormUserData())
Expand Down Expand Up @@ -234,14 +206,17 @@ class RegisterFormModel {
}

private successfulUserRegistration(newUserData: User): void {
const loader = new LoaderModel(SIZES.SMALL).getHTML();
this.view.getSubmitFormButton().getHTML().append(loader);
this.updateUserData(newUserData)
.then(() => this.loginUser(this.getCredentialsData()))
.then(() => getStore().dispatch(switchIsUserLoggedIn(true)))
.catch(() => {
serverMessageModel.showServerMessage(
SERVER_MESSAGE[getStore().getState().currentLanguage].BAD_REQUEST,
MESSAGE_STATUS.ERROR,
);
});
})
.finally(() => loader.remove());
}

private switchSubmitFormButtonAccess(): boolean {
Expand Down

0 comments on commit a6d1aac

Please sign in to comment.