Fix gift place in inventory

This commit is contained in:
Bill 2021-09-12 03:22:08 -04:00
parent 5e7bd29e97
commit cfebf32679
4 changed files with 29 additions and 10 deletions

View File

@ -71,7 +71,7 @@ export const CatalogPurchaseView: FC<CatalogPurchaseViewProps> = props =>
</div> </div>
<div className="d-flex flex-column mt-1"> <div className="d-flex flex-column mt-1">
<CatalogPurchaseButtonView className="btn-sm w-100" offer={ offer } pageId={ pageId } extra={ extraData } quantity={ quantity } disabled={ disabled } /> <CatalogPurchaseButtonView className="btn-sm w-100" offer={ offer } pageId={ pageId } extra={ extraData } quantity={ quantity } disabled={ disabled } />
{ offer.giftable && <CatalogPurchaseGiftButtonView className="btn-sm w-100 mt-1" offer={ offer } pageId={ pageId } extra={ extraData } quantity={ quantity } /> } { offer.giftable && <CatalogPurchaseGiftButtonView className="btn-sm w-100 mt-1" offer={ offer } pageId={ pageId } extra={ extraData } disabled={ disabled } /> }
</div> </div>
</div> </div>
); );

View File

@ -6,7 +6,7 @@ import { CatalogPurchaseGiftButtonViewProps } from './CatalogPurchaseGiftButtonV
export const CatalogPurchaseGiftButtonView: FC<CatalogPurchaseGiftButtonViewProps> = props => export const CatalogPurchaseGiftButtonView: FC<CatalogPurchaseGiftButtonViewProps> = props =>
{ {
const { className = '', offer = null, pageId = -1, extra = null, quantity = 1, isPurchaseAllowed = true, beforePurchase = null } = props; const { className = '', offer = null, pageId = -1, extra = null, disabled = false } = props;
const initGift = useCallback(() => const initGift = useCallback(() =>
{ {
@ -14,6 +14,6 @@ export const CatalogPurchaseGiftButtonView: FC<CatalogPurchaseGiftButtonViewProp
}, [ extra, offer, pageId ]); }, [ extra, offer, pageId ]);
return ( return (
<button type="button" className={ 'btn btn-secondary ' + className } onClick={ initGift }>{ LocalizeText('catalog.purchase_confirmation.gift') }</button> <button type="button" className={ 'btn btn-secondary ' + className } onClick={ initGift } disabled={ disabled }>{ LocalizeText('catalog.purchase_confirmation.gift') }</button>
); );
} }

View File

@ -6,7 +6,5 @@ export interface CatalogPurchaseGiftButtonViewProps
offer: CatalogPageMessageOfferData; offer: CatalogPageMessageOfferData;
pageId: number; pageId: number;
extra?: string; extra?: string;
quantity?: number; disabled?: boolean;
isPurchaseAllowed?: boolean;
beforePurchase?: () => void;
} }

View File

@ -1,5 +1,6 @@
import { RoomObjectCategory, RoomObjectOperationType } from '@nitrots/nitro-renderer';
import { FC, useCallback, useMemo, useState } from 'react'; import { FC, useCallback, useMemo, useState } from 'react';
import { CreateLinkEvent, GetSessionDataManager, LocalizeText, RoomWidgetPresentOpenMessage, RoomWidgetRoomObjectUpdateEvent, RoomWidgetUpdatePresentDataEvent } from '../../../../../api'; import { CreateLinkEvent, GetRoomEngine, GetSessionDataManager, LocalizeText, RoomWidgetPresentOpenMessage, RoomWidgetRoomObjectUpdateEvent, RoomWidgetUpdatePresentDataEvent } from '../../../../../api';
import { CreateEventDispatcherHook } from '../../../../../hooks/events/event-dispatcher.base'; import { CreateEventDispatcherHook } from '../../../../../hooks/events/event-dispatcher.base';
import { NitroCardContentView, NitroCardHeaderView, NitroCardView, NitroLayoutGiftCardView } from '../../../../../layout'; import { NitroCardContentView, NitroCardHeaderView, NitroCardView, NitroLayoutGiftCardView } from '../../../../../layout';
import { ProductTypeEnum } from '../../../../catalog/common/ProductTypeEnum'; import { ProductTypeEnum } from '../../../../catalog/common/ProductTypeEnum';
@ -11,7 +12,6 @@ const LANDSCAPE: string = 'landscape';
export const FurnitureGiftOpeningView: FC<{}> = props => export const FurnitureGiftOpeningView: FC<{}> = props =>
{ {
const { eventDispatcher = null, widgetHandler = null } = useRoomContext();
const [ objectId, setObjectId ] = useState(-1); const [ objectId, setObjectId ] = useState(-1);
const [ classId, setClassId ] = useState(-1); const [ classId, setClassId ] = useState(-1);
const [ itemType, setItemType ] = useState<string>(null); const [ itemType, setItemType ] = useState<string>(null);
@ -24,6 +24,7 @@ export const FurnitureGiftOpeningView: FC<{}> = props =>
const [ placedInRoom, setPlacedInRoom ] = useState(false); const [ placedInRoom, setPlacedInRoom ] = useState(false);
const [ imageUrl, setImageUrl ] = useState<string>(null); const [ imageUrl, setImageUrl ] = useState<string>(null);
const [ openRequested, setOpenRequested ] = useState(false); const [ openRequested, setOpenRequested ] = useState(false);
const { roomSession = null, eventDispatcher = null, widgetHandler = null } = useRoomContext();
const clearGift = useCallback(() => const clearGift = useCallback(() =>
{ {
@ -127,7 +128,12 @@ export const FurnitureGiftOpeningView: FC<{}> = props =>
const close = useCallback(() => const close = useCallback(() =>
{ {
setObjectId(-1); setObjectId(-1);
}, []); setOpenRequested(false);
setPlacedItemId(-1);
setPlacedInRoom(false);
setText(null);
setIsOwnerOfFurniture(false);
}, [ clearGift ]);
const isSpaces = useMemo(() => const isSpaces = useMemo(() =>
{ {
@ -166,9 +172,24 @@ export const FurnitureGiftOpeningView: FC<{}> = props =>
case 'room': case 'room':
return; return;
case 'inventory': case 'inventory':
if((placedItemId > 0) && placedInRoom)
{
if(placedItemType === ProductTypeEnum.PET)
{
roomSession.pickupPet(placedItemId);
}
else
{
const roomObject = GetRoomEngine().getRoomObject(roomSession.roomId, placedItemId, RoomObjectCategory.FLOOR);
if(roomObject) GetRoomEngine().processRoomObjectOperation(roomObject.id, RoomObjectCategory.FLOOR, RoomObjectOperationType.OBJECT_PICKUP);
}
}
close();
return; return;
} }
}, [ widgetHandler, objectId ]); }, [ roomSession, widgetHandler, objectId, placedInRoom, placedItemId, placedItemType, close ]);
if(objectId === -1) return null; if(objectId === -1) return null;