diff --git a/src/events/catalog/CatalogEvent.ts b/src/events/catalog/CatalogEvent.ts index 818289f0..f4f0f1d1 100644 --- a/src/events/catalog/CatalogEvent.ts +++ b/src/events/catalog/CatalogEvent.ts @@ -9,6 +9,7 @@ export class CatalogEvent extends NitroEvent public static PURCHASE_FAILED: string = 'CE_PURCHASE_FAILED'; public static SOLD_OUT: string = 'CE_SOLD_OUT'; public static APPROVE_NAME_RESULT: string = 'CE_APPROVE_NAME_RESULT'; + public static GIFT_RECEIVER_NOT_FOUND: string = 'CE_GIFT_RECEIVER_NOT_FOUND'; public static PURCHASE_APPROVED: string = 'CE_PURCHASE_APPROVED'; public static INIT_GIFT: string = 'CE_INIT_GIFT'; public static CATALOG_RESET: string = 'CE_RESET'; diff --git a/src/events/catalog/CatalogGiftReceiverNotFoundEvent.ts b/src/events/catalog/CatalogGiftReceiverNotFoundEvent.ts new file mode 100644 index 00000000..611eaff7 --- /dev/null +++ b/src/events/catalog/CatalogGiftReceiverNotFoundEvent.ts @@ -0,0 +1,9 @@ +import { CatalogEvent } from './CatalogEvent'; + +export class CatalogGiftReceiverNotFoundEvent extends CatalogEvent +{ + constructor() + { + super(CatalogEvent.GIFT_RECEIVER_NOT_FOUND); + } +} diff --git a/src/views/catalog/CatalogMessageHandler.tsx b/src/views/catalog/CatalogMessageHandler.tsx index e875ddfe..89c1e6fc 100644 --- a/src/views/catalog/CatalogMessageHandler.tsx +++ b/src/views/catalog/CatalogMessageHandler.tsx @@ -1,7 +1,8 @@ -import { ApproveNameMessageEvent, CatalogPageMessageEvent, CatalogPagesListEvent, CatalogPublishedMessageEvent, GiftWrappingConfigurationEvent, HabboClubOffersMessageEvent, LimitedEditionSoldOutEvent, ProductOfferEvent, PurchaseErrorMessageEvent, PurchaseNotAllowedMessageEvent, PurchaseOKMessageEvent, SellablePetPalettesMessageEvent, UserSubscriptionEvent } from '@nitrots/nitro-renderer'; +import { ApproveNameMessageEvent, CatalogPageMessageEvent, CatalogPagesListEvent, CatalogPublishedMessageEvent, GiftReceiverNotFoundEvent, GiftWrappingConfigurationEvent, HabboClubOffersMessageEvent, LimitedEditionSoldOutEvent, 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 { 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'; @@ -96,6 +97,11 @@ export const CatalogMessageHandler: FC = props => dispatchUiEvent(new CatalogNameResultEvent(parser.result, parser.validationInfo)); }, []); + const onGiftReceiverNotFoundEvent = useCallback(() => + { + dispatchUiEvent(new CatalogGiftReceiverNotFoundEvent()); + }, []); + const onHabboClubOffersMessageEvent = useCallback((event: HabboClubOffersMessageEvent) => { const parser = event.getParser(); @@ -168,6 +174,7 @@ export const CatalogMessageHandler: FC = props => CreateMessageHook(GuildMembershipsMessageEvent, onGuildMembershipsMessageEvent); CreateMessageHook(SellablePetPalettesMessageEvent, onSellablePetPalettesMessageEvent); CreateMessageHook(ApproveNameMessageEvent, onApproveNameMessageEvent); + CreateMessageHook(GiftReceiverNotFoundEvent, onGiftReceiverNotFoundEvent); CreateMessageHook(HabboClubOffersMessageEvent, onHabboClubOffersMessageEvent); CreateMessageHook(UserSubscriptionEvent, onUserSubscriptionEvent); CreateMessageHook(CatalogPublishedMessageEvent, onCatalogPublishedMessageEvent); diff --git a/src/views/catalog/views/gift/CatalogPageGiftView.tsx b/src/views/catalog/views/gift/CatalogPageGiftView.tsx index 3cf7f616..1d7a1bf1 100644 --- a/src/views/catalog/views/gift/CatalogPageGiftView.tsx +++ b/src/views/catalog/views/gift/CatalogPageGiftView.tsx @@ -29,6 +29,13 @@ export const CatalogPageGiftView: FC<{}> = props => const [ maxBoxIndex, setMaxBoxIndex ] = useState(0); const [ maxRibbonIndex, setMaxRibbonIndex ] = useState(0); + const [ receiverNotFound, setReceiverNotFound ] = useState(false); + + useEffect(() => + { + setReceiverNotFound(false); + }, [ receiverName ]); + useEffect(() => { if(!giftConfiguration) return; @@ -79,11 +86,15 @@ export const CatalogPageGiftView: FC<{}> = props => setOfferId(castedEvent.offerId); setIsVisible(true); return; + case CatalogEvent.GIFT_RECEIVER_NOT_FOUND: + setReceiverNotFound(true); + return; } }, [ close ]); useUiEvent(CatalogEvent.PURCHASE_SUCCESS, onCatalogEvent); useUiEvent(CatalogEvent.INIT_GIFT, onCatalogEvent); + useUiEvent(CatalogEvent.GIFT_RECEIVER_NOT_FOUND, onCatalogEvent); const isBoxDefault = useMemo(() => { @@ -150,6 +161,12 @@ export const CatalogPageGiftView: FC<{}> = props => }); return; case 'buy': + if(!receiverName || receiverName.length === 0) + { + setReceiverNotFound(true); + return; + } + SendMessageHook(new PurchaseFromCatalogAsGiftComposer(pageId, offerId, extraData, receiverName, message, selectedColorId, selectedBoxIndex, selectedRibbonIndex, showMyFace)); return; } @@ -163,7 +180,8 @@ export const CatalogPageGiftView: FC<{}> = props =>
- setReceiverName(e.target.value) } /> + setReceiverName(e.target.value) } /> + { receiverNotFound &&
{ LocalizeText('catalog.gift_wrapping.receiver_not_found.title') }
}
setMessage(value) } />