diff --git a/src/views/catalog/CatalogMessageHandler.tsx b/src/views/catalog/CatalogMessageHandler.tsx index 54b73d18..bcc13b40 100644 --- a/src/views/catalog/CatalogMessageHandler.tsx +++ b/src/views/catalog/CatalogMessageHandler.tsx @@ -1,4 +1,4 @@ -import { CatalogApproveNameResultEvent, CatalogClubEvent, CatalogGroupsEvent, CatalogPageEvent, CatalogPagesEvent, CatalogPurchaseEvent, CatalogPurchaseFailedEvent, CatalogPurchaseUnavailableEvent, CatalogSearchEvent, CatalogSoldOutEvent, CatalogUpdatedEvent, SellablePetPalettesEvent, UserSubscriptionEvent } from 'nitro-renderer'; +import { CatalogApproveNameResultEvent, CatalogClubEvent, CatalogGiftConfigurationEvent, CatalogGroupsEvent, CatalogPageEvent, CatalogPagesEvent, CatalogPurchaseEvent, CatalogPurchaseFailedEvent, CatalogPurchaseUnavailableEvent, CatalogSearchEvent, CatalogSoldOutEvent, CatalogUpdatedEvent, SellablePetPalettesEvent, UserSubscriptionEvent } from 'nitro-renderer'; import { FC, useCallback } from 'react'; import { CatalogNameResultEvent, CatalogPurchaseFailureEvent } from '../../events'; import { CatalogPurchasedEvent } from '../../events/catalog/CatalogPurchasedEvent'; @@ -145,6 +145,20 @@ export const CatalogMessageHandler: FC = props => }); }, [ dispatchCatalogState ]); + const onCatalogGiftConfigurationEvent = useCallback((event: CatalogGiftConfigurationEvent) => + { + const parser = event.getParser(); + + console.log(parser); + + dispatchCatalogState({ + type: CatalogActions.SET_GIFT_CONFIGURATION, + payload: { + giftConfiguration: parser + } + }); + }, [ dispatchCatalogState ]); + CreateMessageHook(CatalogPagesEvent, onCatalogPagesEvent); CreateMessageHook(CatalogPageEvent, onCatalogPageEvent); CreateMessageHook(CatalogPurchaseEvent, onCatalogPurchaseEvent); @@ -158,6 +172,7 @@ export const CatalogMessageHandler: FC = props => CreateMessageHook(CatalogClubEvent, onCatalogClubEvent); CreateMessageHook(UserSubscriptionEvent, onUserSubscriptionEvent); CreateMessageHook(CatalogUpdatedEvent, onCatalogUpdatedEvent); + CreateMessageHook(CatalogGiftConfigurationEvent, onCatalogGiftConfigurationEvent); return null; } diff --git a/src/views/catalog/CatalogView.tsx b/src/views/catalog/CatalogView.tsx index 4ee80c6a..8f6c6ff5 100644 --- a/src/views/catalog/CatalogView.tsx +++ b/src/views/catalog/CatalogView.tsx @@ -1,4 +1,4 @@ -import { CatalogModeComposer, ICatalogPageData, RoomPreviewer } from 'nitro-renderer'; +import { CatalogModeComposer, CatalogRequestGiftConfigurationComposer, ICatalogPageData, RoomPreviewer } from 'nitro-renderer'; import { FC, useCallback, useEffect, useReducer, useState } from 'react'; import { GetRoomEngine } from '../../api'; import { GetCatalogPageComposer } from '../../api/catalog/GetCatalogPageComposer'; @@ -49,6 +49,7 @@ export const CatalogView: FC = props => if(!catalogState.root) { SendMessageHook(new CatalogModeComposer(CatalogMode.MODE_NORMAL)); + SendMessageHook(new CatalogRequestGiftConfigurationComposer()); } }, [ isVisible, catalogState.root ]); diff --git a/src/views/catalog/common/GiftWrappingConfiguration.ts b/src/views/catalog/common/GiftWrappingConfiguration.ts new file mode 100644 index 00000000..f54d6850 --- /dev/null +++ b/src/views/catalog/common/GiftWrappingConfiguration.ts @@ -0,0 +1,51 @@ +import { CatalogGiftConfigurationParser } from 'nitro-renderer'; + +export class GiftWrappingConfiguration +{ + private _isEnabled: boolean = false; + private _price: number = null; + private _stuffTypes: number[] = null; + private _boxTypes: number[] = null; + private _ribbonTypes: number[] = null; + private _defaultStuffTypes: number[] = null; + + constructor(parser: CatalogGiftConfigurationParser) + { + this._isEnabled = parser.isEnabled; + this._price = parser.price; + this._boxTypes = parser.boxTypes; + this._ribbonTypes = parser.ribbonTypes; + this._stuffTypes = parser.giftWrappers; + this._defaultStuffTypes = parser.giftFurnis; + } + + public get isEnabled(): boolean + { + return this._isEnabled; + } + + public get price(): number + { + return this._price; + } + + public get stuffTypes(): number[] + { + return this._stuffTypes; + } + + public get boxTypes(): number[] + { + return this._boxTypes; + } + + public get ribbonTypes(): number[] + { + return this._ribbonTypes; + } + + public get defaultStuffTypes(): number[] + { + return this._defaultStuffTypes; + } +} diff --git a/src/views/catalog/reducers/CatalogReducer.tsx b/src/views/catalog/reducers/CatalogReducer.tsx index 6d68951a..0d70095e 100644 --- a/src/views/catalog/reducers/CatalogReducer.tsx +++ b/src/views/catalog/reducers/CatalogReducer.tsx @@ -1,7 +1,8 @@ -import { CatalogClubOfferData, CatalogGroupData, CatalogPageOfferData, ICatalogPageData, ICatalogPageParser } from 'nitro-renderer'; +import { CatalogClubOfferData, CatalogGiftConfigurationParser, CatalogGroupData, CatalogPageOfferData, ICatalogPageData, ICatalogPageParser } from 'nitro-renderer'; import { Reducer } from 'react'; import { CatalogPetPalette } from '../common/CatalogPetPalette'; import { ICatalogOffers, ICatalogSearchResult, SetOffersToNodes } from '../common/CatalogUtilities'; +import { GiftWrappingConfiguration } from '../common/GiftWrappingConfiguration'; import { SubscriptionInfo } from '../common/SubscriptionInfo'; export interface ICatalogState @@ -17,6 +18,7 @@ export interface ICatalogState petPalettes: CatalogPetPalette[]; clubOffers: CatalogClubOfferData[]; subscriptionInfo: SubscriptionInfo; + giftConfiguration: GiftWrappingConfiguration; } export interface ICatalogAction @@ -34,6 +36,7 @@ export interface ICatalogAction petPalette?: CatalogPetPalette; clubOffers?: CatalogClubOfferData[]; subscriptionInfo?: SubscriptionInfo; + giftConfiguration?: CatalogGiftConfigurationParser; } } @@ -50,6 +53,7 @@ export class CatalogActions public static SET_PET_PALETTE: string = 'CA_SET_PET_PALETTE'; public static SET_SEARCH_RESULT: string = 'CA_SET_SEARCH_RESULT'; public static SET_SUBSCRIPTION_INFO: string = 'CA_SET_SUBSCRIPTION_INFO'; + public static SET_GIFT_CONFIGURATION: string = 'CA_SET_GIFT_CONFIGURATION'; } export const initialCatalog: ICatalogState = { @@ -63,7 +67,8 @@ export const initialCatalog: ICatalogState = { groups: [], petPalettes: [], clubOffers: null, - subscriptionInfo: new SubscriptionInfo() + subscriptionInfo: new SubscriptionInfo(), + giftConfiguration: null } export const CatalogReducer: Reducer = (state, action) => @@ -158,6 +163,11 @@ export const CatalogReducer: Reducer = (state, ac case CatalogActions.RESET_STATE: { return { ...initialCatalog }; } + case CatalogActions.SET_GIFT_CONFIGURATION: { + const giftConfiguration = new GiftWrappingConfiguration((action.payload.giftConfiguration || null)); + + return { ...state, giftConfiguration }; + } default: return state; }