-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement separate page for addresses
- Loading branch information
1 parent
899be3b
commit 9cdd9a7
Showing
26 changed files
with
268 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/pages/UserAddressesPage/model/UserAddressesPageModel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { Page } from '@/shared/types/page.ts'; | ||
|
||
import RouterModel from '@/app/Router/model/RouterModel.ts'; | ||
import getCustomerModel from '@/shared/API/customer/model/CustomerModel.ts'; | ||
import getStore from '@/shared/Store/Store.ts'; | ||
import { setCurrentPage } from '@/shared/Store/actions.ts'; | ||
import { SERVER_MESSAGE_KEYS } from '@/shared/constants/messages.ts'; | ||
import { PAGE_ID } from '@/shared/constants/pages.ts'; | ||
import createBaseElement from '@/shared/utils/createBaseElement.ts'; | ||
import { showErrorMessage } from '@/shared/utils/userMessage.ts'; | ||
import UserAddressesModel from '@/widgets/UserAddresses/model/UserAddressesModel.ts'; | ||
|
||
import UserAddressesPageView from '../view/UserAddressesPageView.ts'; | ||
|
||
class UserAddressesPageModel implements Page { | ||
private addresses: UserAddressesModel | null = null; | ||
|
||
private view: UserAddressesPageView | null = null; | ||
|
||
constructor(parent: HTMLDivElement) { | ||
const { isUserLoggedIn } = getStore().getState(); | ||
if (!isUserLoggedIn) { | ||
RouterModel.getInstance().navigateTo(PAGE_ID.LOGIN_PAGE); | ||
showErrorMessage(SERVER_MESSAGE_KEYS.NEED_LOGIN); | ||
} else { | ||
this.view = new UserAddressesPageView(parent); | ||
this.init().catch(showErrorMessage); | ||
} | ||
} | ||
|
||
private async init(): Promise<void> { | ||
try { | ||
const user = await getCustomerModel().getCurrentUser(); | ||
if (user) { | ||
this.addresses = new UserAddressesModel(user); | ||
this.view?.getHTML().append(this.addresses.getHTML()); | ||
getStore().dispatch(setCurrentPage(PAGE_ID.USER_ADDRESSES_PAGE)); | ||
} | ||
} catch (error) { | ||
showErrorMessage(SERVER_MESSAGE_KEYS.NEED_LOGIN); | ||
} | ||
} | ||
|
||
public getHTML(): HTMLDivElement { | ||
if (this.view) { | ||
return this.view.getHTML(); | ||
} | ||
return createBaseElement({ | ||
tag: 'div', | ||
}); | ||
} | ||
} | ||
|
||
export default UserAddressesPageModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import clearOutElement from '@/shared/utils/clearOutElement.ts'; | ||
import createBaseElement from '@/shared/utils/createBaseElement.ts'; | ||
|
||
import styles from './userAddressesPageView.module.scss'; | ||
|
||
class UserAddressesPageView { | ||
private page: HTMLDivElement; | ||
|
||
private parent: HTMLDivElement; | ||
|
||
constructor(parent: HTMLDivElement) { | ||
this.parent = parent; | ||
clearOutElement(this.parent); | ||
this.page = this.createHTML(); | ||
window.scrollTo(0, 0); | ||
} | ||
|
||
private createHTML(): HTMLDivElement { | ||
this.page = createBaseElement({ | ||
cssClasses: [styles.userAddressesPage], | ||
tag: 'div', | ||
}); | ||
|
||
this.parent.append(this.page); | ||
|
||
return this.page; | ||
} | ||
|
||
public getHTML(): HTMLDivElement { | ||
return this.page; | ||
} | ||
} | ||
export default UserAddressesPageView; |
19 changes: 19 additions & 0 deletions
19
src/pages/UserAddressesPage/view/userAddressesPageView.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@import 'src/app/styles/mixins'; | ||
|
||
.userAddressesPage { | ||
position: relative; | ||
display: block; | ||
padding: 0 var(--small-offset); | ||
animation: show 0.2s ease-out forwards; | ||
} | ||
|
||
@keyframes show { | ||
0% { | ||
opacity: 0; | ||
} | ||
|
||
100% { | ||
display: block; | ||
opacity: 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.