Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(RSS-ECOMM-4_95): add confirm and link #333

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/pages/CartPage/view/CartPageView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import type { languageVariants } from '@/shared/types/common';
import type ProductOrderModel from '@/widgets/ProductOrder/model/ProductOrderModel';

import RouterModel from '@/app/Router/model/RouterModel.ts';
import ConfirmModel from '@/shared/Confirm/model/ConfirmModel.ts';
import InputModel from '@/shared/Input/model/InputModel.ts';
import LinkModel from '@/shared/Link/model/LinkModel.ts';
import modal from '@/shared/Modal/model/ModalModel.ts';
import getStore from '@/shared/Store/Store.ts';
import { USER_MESSAGE } from '@/shared/constants/confirmUserMessage.ts';
import { INPUT_TYPE } from '@/shared/constants/forms.ts';
import { PAGE_ID } from '@/shared/constants/pages.ts';
import createBaseElement from '@/shared/utils/createBaseElement.ts';
Expand Down Expand Up @@ -218,7 +221,12 @@ class CartPageView {
this.textElement.push({ element: this.clear.getHTML(), textItem: TITLE.CLEAR });
this.clear.getHTML().addEventListener('click', (event) => {
event.preventDefault();
this.clearCallback();
const confirmModel = new ConfirmModel(
() => this.clearCallback(),
USER_MESSAGE[getStore().getState().currentLanguage].CLEAR_CART,
);
modal.setContent(confirmModel.getHTML());
modal.show();
});
tdDelete.append(this.clear.getHTML());
return tdDelete;
Expand Down
14 changes: 11 additions & 3 deletions src/shared/API/cart/model/CartModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ export class CartModel {

private cart: Cart | null = null;

private isSetAnonymousId = false;

private root: CartApi;

constructor() {
this.root = getCartApi();
this.getCart().catch(showErrorMessage);
}

private adaptCart(data: CartResponse): Cart {
Expand Down Expand Up @@ -98,13 +101,15 @@ export class CartModel {
const data = await this.root.getAnonymCart(anonymousCartId);
if (!data.body.customerId) {
this.cart = this.getCartFromData(data);
if (data.body.anonymousId !== anonymousId) {
const cartAnonymId = data.body.anonymousId;
if (cartAnonymId !== anonymousId && !this.isSetAnonymousId) {
this.isSetAnonymousId = true;
const actions: CartSetAnonymousIdAction = {
action: ACTIONS.setAnonymousId,
anonymousId,
};
const data = await this.root.setAnonymousId(this.cart, actions);
this.cart = this.getCartFromData(data);
const dataSetId = await this.root.setAnonymousId(this.cart, actions);
this.cart = this.getCartFromData(dataSetId);
}
}

Expand Down Expand Up @@ -256,6 +261,9 @@ export class CartModel {
if (!this.cart) {
const { anonymousCartId, anonymousId } = getStore().getState();
if (anonymousCartId && anonymousId) {
// const data = await this.root.getAnonymCart(anonymousCartId);
// this.cart = this.getCartFromData(data);

this.cart = await this.getAnonymousCart(anonymousCartId, anonymousId);
}
if (!this.cart) {
Expand Down
2 changes: 2 additions & 0 deletions src/shared/constants/confirmUserMessage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const USER_MESSAGE = {
en: {
CLEAR_CART: 'Are you sure you want to clear the cart?',
CONFIRM: 'Are you sure you want to proceed?',
DELETE_ADDRESS: 'Are you sure you want to delete this address?',
},
ru: {
CLEAR_CART: 'Вы уверены, что хотите очистить корзину?',
CONFIRM: 'Вы уверены, что хотите продолжить?',
DELETE_ADDRESS: 'Вы уверены, что хотите удалить этот адрес?',
},
Expand Down
15 changes: 14 additions & 1 deletion src/widgets/ProductOrder/view/ProductOrderView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import type { LanguageChoiceType } from '@/shared/constants/common.ts';
import type { CartProduct } from '@/shared/types/cart';
import type { languageVariants } from '@/shared/types/common';

import LinkModel from '@/shared/Link/model/LinkModel.ts';
import getStore from '@/shared/Store/Store.ts';
import { LANGUAGE_CHOICE, TABLET_WIDTH } from '@/shared/constants/common.ts';
import { PAGE_ID } from '@/shared/constants/pages.ts';
import SVG_DETAILS from '@/shared/constants/svg.ts';
import { CartActive } from '@/shared/types/cart.ts';
import { buildPathName } from '@/shared/utils/buildPathname.ts';
import createBaseElement from '@/shared/utils/createBaseElement.ts';
import createSVGUse from '@/shared/utils/createSVGUse.ts';
import Hammer from 'hammerjs';
Expand Down Expand Up @@ -121,10 +124,20 @@ class ProductOrderView {

private createImgCell(): HTMLTableCellElement {
const tdImage = createBaseElement({ cssClasses: [styles.td, styles.imgCell], tag: 'td' });
const href = `${buildPathName(PAGE_ID.PRODUCT_PAGE, this.productItem.key, {
size: [this.productItem.size],
})}`;
const link = new LinkModel({
attrs: {
href,
},
classes: [styles.goDetailsPageLink],
});
const img = createBaseElement({ cssClasses: [styles.img], tag: 'img' });
img.src = this.productItem.images;
img.alt = this.productItem.name[Number(getStore().getState().currentLanguage === LANGUAGE_CHOICE.RU)].value;
tdImage.append(img);
link.getHTML().append(img);
tdImage.append(link.getHTML());
return tdImage;
}

Expand Down