mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-30 00:50:50 +01:00
Gift ReceiverNotFound handler
This commit is contained in:
parent
d70afa28eb
commit
bee5513c13
@ -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';
|
||||
|
9
src/events/catalog/CatalogGiftReceiverNotFoundEvent.ts
Normal file
9
src/events/catalog/CatalogGiftReceiverNotFoundEvent.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { CatalogEvent } from './CatalogEvent';
|
||||
|
||||
export class CatalogGiftReceiverNotFoundEvent extends CatalogEvent
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
super(CatalogEvent.GIFT_RECEIVER_NOT_FOUND);
|
||||
}
|
||||
}
|
@ -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<CatalogMessageHandlerProps> = 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<CatalogMessageHandlerProps> = props =>
|
||||
CreateMessageHook(GuildMembershipsMessageEvent, onGuildMembershipsMessageEvent);
|
||||
CreateMessageHook(SellablePetPalettesMessageEvent, onSellablePetPalettesMessageEvent);
|
||||
CreateMessageHook(ApproveNameMessageEvent, onApproveNameMessageEvent);
|
||||
CreateMessageHook(GiftReceiverNotFoundEvent, onGiftReceiverNotFoundEvent);
|
||||
CreateMessageHook(HabboClubOffersMessageEvent, onHabboClubOffersMessageEvent);
|
||||
CreateMessageHook(UserSubscriptionEvent, onUserSubscriptionEvent);
|
||||
CreateMessageHook(CatalogPublishedMessageEvent, onCatalogPublishedMessageEvent);
|
||||
|
@ -29,6 +29,13 @@ export const CatalogPageGiftView: FC<{}> = props =>
|
||||
const [ maxBoxIndex, setMaxBoxIndex ] = useState<number>(0);
|
||||
const [ maxRibbonIndex, setMaxRibbonIndex ] = useState<number>(0);
|
||||
|
||||
const [ receiverNotFound, setReceiverNotFound ] = useState<boolean>(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 =>
|
||||
<NitroCardContentView className="text-black">
|
||||
<div className="form-group">
|
||||
<label>{ LocalizeText('catalog.gift_wrapping.receiver') }</label>
|
||||
<input type="text" className="form-control form-control-sm" value={ receiverName } onChange={ (e) => setReceiverName(e.target.value) } />
|
||||
<input type="text" className={ 'form-control form-control-sm' + classNames({ ' is-invalid': receiverNotFound }) } value={ receiverName } onChange={ (e) => setReceiverName(e.target.value) } />
|
||||
{ receiverNotFound && <div className="invalid-feedback">{ LocalizeText('catalog.gift_wrapping.receiver_not_found.title') }</div> }
|
||||
</div>
|
||||
<div className="mt-2">
|
||||
<NitroLayoutGiftCardView figure={ GetSessionDataManager().figure } userName={ GetSessionDataManager().userName } message={ message } editable={ true } onChange={ (value) => setMessage(value) } />
|
||||
|
Loading…
Reference in New Issue
Block a user