Skip to content

Commit

Permalink
feat: add confirm and link
Browse files Browse the repository at this point in the history
  • Loading branch information
YulikK committed Jun 3, 2024
1 parent 39d0992 commit c32d5e1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
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
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

0 comments on commit c32d5e1

Please sign in to comment.