diff --git a/src/components/catalog/CatalogMessageHandler.tsx b/src/components/catalog/CatalogMessageHandler.tsx index 61948e8f..960af30d 100644 --- a/src/components/catalog/CatalogMessageHandler.tsx +++ b/src/components/catalog/CatalogMessageHandler.tsx @@ -1,12 +1,15 @@ -import { ApproveNameMessageEvent, CatalogPageMessageEvent, CatalogPagesListEvent, CatalogPublishedMessageEvent, GiftReceiverNotFoundEvent, GiftWrappingConfigurationEvent, HabboClubOffersMessageEvent, LimitedEditionSoldOutEvent, ProductOfferEvent, PurchaseErrorMessageEvent, PurchaseNotAllowedMessageEvent, PurchaseOKMessageEvent, SellablePetPalettesMessageEvent, UserSubscriptionEvent } from '@nitrots/nitro-renderer'; +import { ApproveNameMessageEvent, CatalogPageMessageEvent, CatalogPagesListEvent, CatalogPublishedMessageEvent, GiftReceiverNotFoundEvent, GiftWrappingConfigurationEvent, HabboClubOffersMessageEvent, LimitedEditionSoldOutEvent, MarketplaceConfigurationEvent, MarketplaceMakeOfferResult, ProductOfferEvent, PurchaseErrorMessageEvent, PurchaseNotAllowedMessageEvent, PurchaseOKMessageEvent, SellablePetPalettesMessageEvent, UserSubscriptionEvent } from '@nitrots/nitro-renderer'; import { GuildMembershipsMessageEvent } from '@nitrots/nitro-renderer/src/nitro/communication/messages/incoming/user/GuildMembershipsMessageEvent'; import { FC, useCallback } from 'react'; +import { LocalizeText } from '../../api'; import { CatalogNameResultEvent, CatalogPurchaseFailureEvent } from '../../events'; import { CatalogGiftReceiverNotFoundEvent } from '../../events/catalog/CatalogGiftReceiverNotFoundEvent'; import { CatalogPurchasedEvent } from '../../events/catalog/CatalogPurchasedEvent'; import { CatalogPurchaseSoldOutEvent } from '../../events/catalog/CatalogPurchaseSoldOutEvent'; import { dispatchUiEvent } from '../../hooks/events/ui/ui-event'; import { CreateMessageHook } from '../../hooks/messages/message-event'; +import { NotificationAlertType } from '../../views/notification-center/common/NotificationAlertType'; +import { NotificationUtilities } from '../../views/notification-center/common/NotificationUtilities'; import { CatalogPetPalette } from './common/CatalogPetPalette'; import { SubscriptionInfo } from './common/SubscriptionInfo'; import { useCatalogContext } from './context/CatalogContext'; @@ -163,6 +166,43 @@ export const CatalogMessageHandler: FC<{}> = props => }); }, [ dispatchCatalogState ]); + const onMarketplaceMakeOfferResult = useCallback((event: MarketplaceMakeOfferResult) => + { + const parser = event.getParser(); + + if(!parser) return; + + let title = ''; + if(parser.result === 1) + { + title = LocalizeText('inventory.marketplace.result.title.success'); + } + else + { + title = LocalizeText('inventory.marketplace.result.title.failure'); + } + + const message = LocalizeText(`inventory.marketplace.result.${parser.result}`); + + NotificationUtilities.simpleAlert(message, NotificationAlertType.DEFAULT, null, null, title); + }, []); + + const onMarketplaceConfigurationEvent = useCallback((event: MarketplaceConfigurationEvent) => + { + const parser = event.getParser(); + + if(!parser) return; + + console.log(parser); + + dispatchCatalogState({ + type: CatalogActions.SET_MARKETPLACE_CONFIGURATION, + payload: { + marketplaceConfiguration: parser + } + }); + }, [dispatchCatalogState]); + CreateMessageHook(CatalogPagesListEvent, onCatalogPagesListEvent); CreateMessageHook(CatalogPageMessageEvent, onCatalogPageMessageEvent); CreateMessageHook(PurchaseOKMessageEvent, onPurchaseOKMessageEvent); @@ -178,6 +218,8 @@ export const CatalogMessageHandler: FC<{}> = props => CreateMessageHook(UserSubscriptionEvent, onUserSubscriptionEvent); CreateMessageHook(CatalogPublishedMessageEvent, onCatalogPublishedMessageEvent); CreateMessageHook(GiftWrappingConfigurationEvent, onGiftWrappingConfigurationEvent); + CreateMessageHook(MarketplaceMakeOfferResult, onMarketplaceMakeOfferResult); + CreateMessageHook(MarketplaceConfigurationEvent, onMarketplaceConfigurationEvent); return null; } diff --git a/src/components/catalog/CatalogView.tsx b/src/components/catalog/CatalogView.tsx index c97148d1..78e2d372 100644 --- a/src/components/catalog/CatalogView.tsx +++ b/src/components/catalog/CatalogView.tsx @@ -1,10 +1,11 @@ -import { GetCatalogIndexComposer, GetCatalogPageComposer, GetGiftWrappingConfigurationComposer, ILinkEventTracker, INodeData, RoomPreviewer } from '@nitrots/nitro-renderer'; +import { GetCatalogIndexComposer, GetCatalogPageComposer, GetGiftWrappingConfigurationComposer, GetMarketplaceConfigurationMessageComposer, ILinkEventTracker, INodeData, RoomPreviewer } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useReducer, useState } from 'react'; import { AddEventLinkTracker, GetRoomEngine, LocalizeText, RemoveLinkEventTracker } from '../../api'; import { CREDITS, PlaySound } from '../../api/utils/PlaySound'; import { Column } from '../../common/Column'; import { Grid } from '../../common/Grid'; import { CatalogEvent } from '../../events'; +import { UseMountEffect } from '../../hooks'; import { useUiEvent } from '../../hooks/events/ui/ui-event'; import { SendMessageHook } from '../../hooks/messages/message-event'; import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../layout'; @@ -117,7 +118,6 @@ export const CatalogView: FC<{}> = props => if(loadCatalog) { SendMessageHook(new GetCatalogIndexComposer(CatalogMode.MODE_NORMAL)); - SendMessageHook(new GetGiftWrappingConfigurationComposer()); return; } @@ -191,6 +191,12 @@ export const CatalogView: FC<{}> = props => } }, []); + UseMountEffect(() => + { + SendMessageHook(new GetMarketplaceConfigurationMessageComposer()); + SendMessageHook(new GetGiftWrappingConfigurationComposer()); + }); + const currentNavigationPage = ((searchResult && searchResult.page) || currentTab); const navigationHidden = !!(pageParser && pageParser.frontPageItems.length); diff --git a/src/components/catalog/reducers/CatalogReducer.tsx b/src/components/catalog/reducers/CatalogReducer.tsx index 35b1daf3..87eba150 100644 --- a/src/components/catalog/reducers/CatalogReducer.tsx +++ b/src/components/catalog/reducers/CatalogReducer.tsx @@ -1,4 +1,4 @@ -import { CatalogPageMessageOfferData, CatalogPageMessageParser, ClubOfferData, GiftWrappingConfigurationParser, INodeData } from '@nitrots/nitro-renderer'; +import { CatalogPageMessageOfferData, CatalogPageMessageParser, ClubOfferData, GiftWrappingConfigurationParser, INodeData, MarketplaceConfigurationMessageParser } from '@nitrots/nitro-renderer'; import { HabboGroupEntryData } from '@nitrots/nitro-renderer/src/nitro/communication/messages/parser/user/HabboGroupEntryData'; import { Reducer } from 'react'; import { CatalogPetPalette } from '../common/CatalogPetPalette'; @@ -19,6 +19,7 @@ export interface ICatalogState clubOffers: ClubOfferData[]; subscriptionInfo: SubscriptionInfo; giftConfiguration: GiftWrappingConfiguration; + marketplaceConfiguration: MarketplaceConfigurationMessageParser; } export interface ICatalogAction @@ -36,6 +37,7 @@ export interface ICatalogAction clubOffers?: ClubOfferData[]; subscriptionInfo?: SubscriptionInfo; giftConfiguration?: GiftWrappingConfigurationParser; + marketplaceConfiguration?: MarketplaceConfigurationMessageParser; } } @@ -52,6 +54,7 @@ export class CatalogActions 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'; + public static SET_MARKETPLACE_CONFIGURATION: string = 'CA_SET_MARKETPLACE_CONFIGURATION'; } export const initialCatalog: ICatalogState = { @@ -65,7 +68,8 @@ export const initialCatalog: ICatalogState = { petPalettes: [], clubOffers: null, subscriptionInfo: new SubscriptionInfo(), - giftConfiguration: null + giftConfiguration: null, + marketplaceConfiguration: null } export const CatalogReducer: Reducer = (state, action) => @@ -160,6 +164,11 @@ export const CatalogReducer: Reducer = (state, ac return { ...state, giftConfiguration }; } + case CatalogActions.SET_MARKETPLACE_CONFIGURATION: { + let marketplaceConfiguration = (action.payload.marketplaceConfiguration || state.marketplaceConfiguration || null); + + return { ...state, marketplaceConfiguration } + } default: return state; } diff --git a/src/components/catalog/views/page/layout/marketplace/post-offer/MarketplacePostOfferView.tsx b/src/components/catalog/views/page/layout/marketplace/post-offer/MarketplacePostOfferView.tsx index 27eec7b0..42e01bfb 100644 --- a/src/components/catalog/views/page/layout/marketplace/post-offer/MarketplacePostOfferView.tsx +++ b/src/components/catalog/views/page/layout/marketplace/post-offer/MarketplacePostOfferView.tsx @@ -6,11 +6,13 @@ import { SendMessageHook, useUiEvent } from '../../../../../../../hooks'; import { NitroCardContentView, NitroCardHeaderView, NitroCardView, NitroLayoutFlex } from '../../../../../../../layout'; import { NotificationUtilities } from '../../../../../../../views/notification-center/common/NotificationUtilities'; import { FurnitureItem } from '../../../../../../inventory/common/FurnitureItem'; +import { useCatalogContext } from '../../../../../context/CatalogContext'; export const MarketplacePostOfferView : FC<{}> = props => { const [ item, setItem ] = useState(null); const [ askingPrice, setAskingPrice ] = useState(0); + const { catalogState = null, dispatchCatalogState = null } = useCatalogContext(); const close = useCallback(() => { @@ -91,17 +93,21 @@ export const MarketplacePostOfferView : FC<{}> = props =>
- { LocalizeText('inventory.marketplace.make_offer.expiration_info') } + { LocalizeText('inventory.marketplace.make_offer.expiration_info', ['time'], [catalogState.marketplaceConfiguration.offerTime.toString()]) }
{ LocalizeText('inventory.marketplace.make_offer.price_request') }
setAskingPrice(event.target.valueAsNumber) } />
- { askingPrice <= 0 || isNaN(askingPrice) ? LocalizeText('inventory.marketplace.make_offer.min_price', ['minprice'], ['1']) : LocalizeText('inventory.marketplace.make_offer.final_price', ['commission', 'finalprice'], ['1', (askingPrice + 1).toString()])} + { (askingPrice < catalogState.marketplaceConfiguration.minimumPrice || isNaN(askingPrice)) && LocalizeText('inventory.marketplace.make_offer.min_price', ['minprice'], [catalogState.marketplaceConfiguration.minimumPrice.toString()]) } + { askingPrice > catalogState.marketplaceConfiguration.maximumPrice && !isNaN(askingPrice) && + LocalizeText('inventory.marketplace.make_offer.max_price', ['maxprice'], [catalogState.marketplaceConfiguration.maximumPrice.toString()]) + } + { !(askingPrice < catalogState.marketplaceConfiguration.minimumPrice || askingPrice > catalogState.marketplaceConfiguration.maximumPrice || isNaN(askingPrice)) && LocalizeText('inventory.marketplace.make_offer.final_price', ['commission', 'finalprice'], [catalogState.marketplaceConfiguration.commission.toString(), (askingPrice + catalogState.marketplaceConfiguration.commission).toString()])}
-