From e4c5a18fab81000de03d21ef644475f511883728 Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 11 May 2021 19:22:45 -0400 Subject: [PATCH] Add image/text to catalog pages --- src/views/catalog/reducers/CatalogReducer.tsx | 3 ++- src/views/catalog/utils/CatalogUtilities.ts | 25 ++++++++++++++++++- .../default/CatalogLayoutDefaultView.tsx | 9 ++++++- .../page/offers/CatalogPageOffersView.tsx | 13 +++++----- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/views/catalog/reducers/CatalogReducer.tsx b/src/views/catalog/reducers/CatalogReducer.tsx index e4a4a1f0..39fe23d8 100644 --- a/src/views/catalog/reducers/CatalogReducer.tsx +++ b/src/views/catalog/reducers/CatalogReducer.tsx @@ -65,6 +65,7 @@ export const CatalogReducer: Reducer = (state, ac } case CatalogActions.SET_CATALOG_PAGE_PARSER: { const pageParser = action.payload.pageParser; + const activeOffer = null; const searchResult = state.searchResult; @@ -73,7 +74,7 @@ export const CatalogReducer: Reducer = (state, ac searchResult.furniture = null; } - return { ...state, pageParser, searchResult }; + return { ...state, pageParser, activeOffer, searchResult }; } case CatalogActions.SET_CATALOG_ACTIVE_OFFER: { const activeOffer = (action.payload.activeOffer || state.activeOffer || null); diff --git a/src/views/catalog/utils/CatalogUtilities.ts b/src/views/catalog/utils/CatalogUtilities.ts index caaf4e99..7af9ab25 100644 --- a/src/views/catalog/utils/CatalogUtilities.ts +++ b/src/views/catalog/utils/CatalogUtilities.ts @@ -1,5 +1,6 @@ -import { CatalogPageOfferData, ICatalogPageData, IFurnitureData } from 'nitro-renderer'; +import { CatalogPageOfferData, ICatalogPageData, ICatalogPageParser, IFurnitureData } from 'nitro-renderer'; import { GetProductDataForLocalization } from '../../../api/nitro/session/GetProductDataForLocalization'; +import { GetConfiguration } from '../../../utils/GetConfiguration'; export interface ICatalogOffers { @@ -65,3 +66,25 @@ export function SetOffersToNodes(offers: ICatalogOffers, pageData: ICatalogPageD for(const child of pageData.children) SetOffersToNodes(offers, child); } } + +export function GetCatalogPageImage(page: ICatalogPageParser, index: number = 0): string +{ + const imageName = page.localization.images && page.localization.images[index]; + + if(!imageName || !imageName.length) return null; + + let assetUrl = GetConfiguration('catalog.asset.image.url'); + + assetUrl = assetUrl.replace('%name%', imageName); + + return assetUrl; +} + +export function GetCatalogPageText(page: ICatalogPageParser, index: number = 0): string +{ + let message = (page.localization.texts[index] || ''); + + if(message && message.length) message = message.replace(/\r\n|\r|\n/g, '
'); + + return (message || ''); +} diff --git a/src/views/catalog/views/page/layout/default/CatalogLayoutDefaultView.tsx b/src/views/catalog/views/page/layout/default/CatalogLayoutDefaultView.tsx index 176d7cb3..ea3ef7bd 100644 --- a/src/views/catalog/views/page/layout/default/CatalogLayoutDefaultView.tsx +++ b/src/views/catalog/views/page/layout/default/CatalogLayoutDefaultView.tsx @@ -2,7 +2,7 @@ import { FC } from 'react'; import { LimitedEditionCompletePlateView } from '../../../../../limited-edition/complete-plate/LimitedEditionCompletePlateView'; import { RoomPreviewerView } from '../../../../../room-previewer/RoomPreviewerView'; import { useCatalogContext } from '../../../../context/CatalogContext'; -import { GetOfferName } from '../../../../utils/CatalogUtilities'; +import { GetCatalogPageImage, GetCatalogPageText, GetOfferName } from '../../../../utils/CatalogUtilities'; import { CatalogPageOffersView } from '../../offers/CatalogPageOffersView'; import { CatalogPurchaseView } from '../../purchase/CatalogPurchaseView'; import { CatalogLayoutDefaultViewProps } from './CatalogLayoutDefaultView.types'; @@ -20,6 +20,13 @@ export const CatalogLayoutDefaultView: FC = props
+ { !product && +
+
+ +
+ { GetCatalogPageText(pageParser, 0) } +
} { product &&
diff --git a/src/views/catalog/views/page/offers/CatalogPageOffersView.tsx b/src/views/catalog/views/page/offers/CatalogPageOffersView.tsx index e367bd95..c44ebbda 100644 --- a/src/views/catalog/views/page/offers/CatalogPageOffersView.tsx +++ b/src/views/catalog/views/page/offers/CatalogPageOffersView.tsx @@ -1,6 +1,5 @@ import { FC, useEffect } from 'react'; import { useCatalogContext } from '../../../context/CatalogContext'; -import { CatalogActions } from '../../../reducers/CatalogReducer'; import { CatalogPageOfferView } from '../offer/CatalogPageOfferView'; import { CatalogPageOffersViewProps } from './CatalogPageOffersView.types'; @@ -14,12 +13,12 @@ export const CatalogPageOffersView: FC = props => { if(!offers || !offers.length) return; - dispatchCatalogState({ - type: CatalogActions.SET_CATALOG_ACTIVE_OFFER, - payload: { - activeOffer: offers[0] - } - }) + // dispatchCatalogState({ + // type: CatalogActions.SET_CATALOG_ACTIVE_OFFER, + // payload: { + // activeOffer: offers[0] + // } + // }); }, [ offers, dispatchCatalogState ]); return (