From c7d3022ccb63fb1c1eec789f4fbbe5e1bd3c6c63 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 27 Feb 2022 20:58:28 -0500 Subject: [PATCH] Fix catalog offers --- src/components/catalog/common/FurnitureOffer.ts | 13 ++++++++++++- src/components/catalog/common/IPurchasableOffer.ts | 2 ++ src/components/catalog/common/Offer.ts | 10 ++++++++++ .../page/widgets/CatalogItemGridWidgetView.tsx | 9 +++++---- .../page/widgets/CatalogPurchaseWidgetView.tsx | 12 ++++++------ 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/components/catalog/common/FurnitureOffer.ts b/src/components/catalog/common/FurnitureOffer.ts index 85d3216a..9197ae9f 100644 --- a/src/components/catalog/common/FurnitureOffer.ts +++ b/src/components/catalog/common/FurnitureOffer.ts @@ -1,5 +1,6 @@ -import { IFurnitureData } from '@nitrots/nitro-renderer'; +import { GetProductOfferComposer, IFurnitureData } from '@nitrots/nitro-renderer'; import { GetProductDataForLocalization } from '../../../api'; +import { SendMessageHook } from '../../../hooks'; import { ICatalogPage } from './ICatalogPage'; import { IProduct } from './IProduct'; import { IPurchasableOffer } from './IPurchasableOffer'; @@ -18,6 +19,11 @@ export class FurnitureOffer implements IPurchasableOffer this._product = (new Product(this._furniData.type, this._furniData.id, this._furniData.customParams, 1, GetProductDataForLocalization(this._furniData.className), this._furniData) as IProduct); } + public activate(): void + { + SendMessageHook(new GetProductOfferComposer((this._furniData.rentOfferId > -1) ? this._furniData.rentOfferId : this._furniData.purchaseOfferId)); + } + public get offerId(): number { return (this.isRentOffer) ? this._furniData.rentOfferId : this._furniData.purchaseOfferId; @@ -107,4 +113,9 @@ export class FurnitureOffer implements IPurchasableOffer { return this._furniData.description; } + + public get isLazy(): boolean + { + return true; + } } diff --git a/src/components/catalog/common/IPurchasableOffer.ts b/src/components/catalog/common/IPurchasableOffer.ts index cc2693f7..b1828651 100644 --- a/src/components/catalog/common/IPurchasableOffer.ts +++ b/src/components/catalog/common/IPurchasableOffer.ts @@ -3,6 +3,7 @@ import { IProduct } from './IProduct'; export interface IPurchasableOffer { + activate(): void; clubLevel: number; page: ICatalogPage; offerId: number; @@ -19,5 +20,6 @@ export interface IPurchasableOffer badgeCode: string; localizationName: string; localizationDescription: string; + isLazy: boolean; products: IProduct[]; } diff --git a/src/components/catalog/common/Offer.ts b/src/components/catalog/common/Offer.ts index 16e30a0c..b39ed48f 100644 --- a/src/components/catalog/common/Offer.ts +++ b/src/components/catalog/common/Offer.ts @@ -59,6 +59,11 @@ export class Offer implements IPurchasableOffer } } + public activate(): void + { + + } + public get clubLevel(): number { return this._clubLevel; @@ -160,6 +165,11 @@ export class Offer implements IPurchasableOffer return LocalizeText(this._localizationId); } + public get isLazy(): boolean + { + return false; + } + public get products(): IProduct[] { return this._products; diff --git a/src/components/catalog/views/page/widgets/CatalogItemGridWidgetView.tsx b/src/components/catalog/views/page/widgets/CatalogItemGridWidgetView.tsx index e41ff311..dbb20b17 100644 --- a/src/components/catalog/views/page/widgets/CatalogItemGridWidgetView.tsx +++ b/src/components/catalog/views/page/widgets/CatalogItemGridWidgetView.tsx @@ -21,6 +21,10 @@ export const CatalogItemGridWidgetView: FC = pro const selectOffer = (offer: IPurchasableOffer) => { + offer.activate(); + + if(offer.isLazy) return; + setCurrentOffer(offer); if(offer.product && (offer.product.productType === ProductTypeEnum.WALL)) @@ -31,10 +35,7 @@ export const CatalogItemGridWidgetView: FC = pro return ( - { currentPage.offers && (currentPage.offers.length > 0) && currentPage.offers.map((offer, index) => - { - return selectOffer(offer) } />; - }) } + { currentPage.offers && (currentPage.offers.length > 0) && currentPage.offers.map((offer, index) => selectOffer(offer) } />) } { children } ); diff --git a/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx b/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx index 9b05d88f..d9df7e86 100644 --- a/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx +++ b/src/components/catalog/views/page/widgets/CatalogPurchaseWidgetView.tsx @@ -106,15 +106,15 @@ export const CatalogPurchaseWidgetView: FC = pro let pageId = currentOffer.page.pageId; - if(pageId === -1) - { - const nodes = getNodesByOfferId(currentOffer.offerId); + // if(pageId === -1) + // { + // const nodes = getNodesByOfferId(currentOffer.offerId); - if(nodes) pageId = nodes[0].pageId; - } + // if(nodes) pageId = nodes[0].pageId; + // } SendMessageHook(new PurchaseFromCatalogComposer(pageId, currentOffer.offerId, extraData, quantity)); - }, [ currentOffer, purchaseCallback, extraData, quantity, getNodesByOfferId ]); + }, [ currentOffer, purchaseCallback, extraData, quantity ]); useEffect(() => {