mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-26 23:50:52 +01:00
Merge pull request #88 from billsonnn/@bug-fix/default-gift
@bug fix/default gift
This commit is contained in:
commit
9f46f75a1e
@ -27,6 +27,9 @@
|
|||||||
width: 80px;
|
width: 80px;
|
||||||
height: 80px;
|
height: 80px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gift-color {
|
.gift-color {
|
||||||
@ -89,7 +92,8 @@
|
|||||||
.icon-hc-banner {
|
.icon-hc-banner {
|
||||||
width: 68px;
|
width: 68px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
background: url("../../assets/images/catalog/hc_big.png") center no-repeat;
|
background: url("../../assets/images/catalog/hc_big.png") center
|
||||||
|
no-repeat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
import { GiftReceiverNotFoundEvent, PurchaseFromCatalogAsGiftComposer } from '@nitrots/nitro-renderer';
|
import { GiftReceiverNotFoundEvent, PurchaseFromCatalogAsGiftComposer } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useCallback, useEffect, useMemo, useState } from 'react';
|
import { FC, useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { GetSessionDataManager, LocalizeText, ProductTypeEnum, SendMessageComposer } from '../../../../api';
|
import { ColorUtils, GetSessionDataManager, LocalizeText, ProductTypeEnum, SendMessageComposer } from '../../../../api';
|
||||||
import { Base, Button, ButtonGroup, classNames, Column, Flex, FormGroup, LayoutCurrencyIcon, LayoutFurniImageView, LayoutGiftTagView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common';
|
import { Base, Button, ButtonGroup, classNames, Column, Flex, FormGroup, LayoutCurrencyIcon, LayoutFurniImageView, LayoutGiftTagView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common';
|
||||||
import { CatalogEvent, CatalogInitGiftEvent, CatalogPurchasedEvent } from '../../../../events';
|
import { CatalogEvent, CatalogInitGiftEvent, CatalogPurchasedEvent } from '../../../../events';
|
||||||
import { useCatalog, useMessageEvent, useUiEvent } from '../../../../hooks';
|
import { useCatalog, useMessageEvent, useUiEvent } from '../../../../hooks';
|
||||||
@ -24,6 +24,7 @@ export const CatalogGiftView: FC<{}> = props =>
|
|||||||
const [ receiverNotFound, setReceiverNotFound ] = useState<boolean>(false);
|
const [ receiverNotFound, setReceiverNotFound ] = useState<boolean>(false);
|
||||||
const { catalogOptions = null } = useCatalog();
|
const { catalogOptions = null } = useCatalog();
|
||||||
const { giftConfiguration = null } = catalogOptions;
|
const { giftConfiguration = null } = catalogOptions;
|
||||||
|
const [ boxTypes, setBoxTypes ] = useState<number[]>([]);
|
||||||
|
|
||||||
const onClose = useCallback(() =>
|
const onClose = useCallback(() =>
|
||||||
{
|
{
|
||||||
@ -42,24 +43,32 @@ export const CatalogGiftView: FC<{}> = props =>
|
|||||||
|
|
||||||
const isBoxDefault = useMemo(() =>
|
const isBoxDefault = useMemo(() =>
|
||||||
{
|
{
|
||||||
return giftConfiguration ? (giftConfiguration.defaultStuffTypes.findIndex(s => (s === giftConfiguration.boxTypes[selectedBoxIndex])) > -1) : true;
|
return giftConfiguration ? (giftConfiguration.defaultStuffTypes.findIndex(s => (s === boxTypes[selectedBoxIndex])) > -1) : false;
|
||||||
}, [ giftConfiguration, selectedBoxIndex ]);
|
}, [ boxTypes, giftConfiguration, selectedBoxIndex ]);
|
||||||
|
|
||||||
const boxExtraData = useMemo(() =>
|
const boxExtraData = useMemo(() =>
|
||||||
{
|
{
|
||||||
if (!giftConfiguration) return '';
|
if (!giftConfiguration) return '';
|
||||||
|
|
||||||
return ((giftConfiguration.boxTypes[selectedBoxIndex] * 1000) + giftConfiguration.ribbonTypes[selectedRibbonIndex]).toString();
|
return ((boxTypes[selectedBoxIndex] * 1000) + giftConfiguration.ribbonTypes[selectedRibbonIndex]).toString();
|
||||||
}, [ giftConfiguration, selectedBoxIndex, selectedRibbonIndex ]);
|
}, [ giftConfiguration, selectedBoxIndex, selectedRibbonIndex, boxTypes ]);
|
||||||
|
|
||||||
const isColorable = useMemo(() =>
|
const isColorable = useMemo(() =>
|
||||||
{
|
{
|
||||||
if (!giftConfiguration) return false;
|
if (!giftConfiguration) return false;
|
||||||
|
|
||||||
const boxType = giftConfiguration.boxTypes[selectedBoxIndex];
|
if (isBoxDefault) return false;
|
||||||
|
|
||||||
|
const boxType = boxTypes[selectedBoxIndex];
|
||||||
|
|
||||||
return (boxType === 8 || (boxType >= 3 && boxType <= 6)) ? false : true;
|
return (boxType === 8 || (boxType >= 3 && boxType <= 6)) ? false : true;
|
||||||
}, [ giftConfiguration, selectedBoxIndex ]);
|
}, [ giftConfiguration, selectedBoxIndex, isBoxDefault, boxTypes ]);
|
||||||
|
|
||||||
|
const colourId = useMemo(() =>
|
||||||
|
{
|
||||||
|
return isBoxDefault ? boxTypes[selectedBoxIndex] : selectedColorId;
|
||||||
|
},[ isBoxDefault, boxTypes, selectedBoxIndex, selectedColorId ])
|
||||||
|
|
||||||
|
|
||||||
const handleAction = useCallback((action: string) =>
|
const handleAction = useCallback((action: string) =>
|
||||||
{
|
{
|
||||||
@ -84,10 +93,10 @@ export const CatalogGiftView: FC<{}> = props =>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SendMessageComposer(new PurchaseFromCatalogAsGiftComposer(pageId, offerId, extraData, receiverName, message, selectedColorId, selectedBoxIndex, selectedRibbonIndex, showMyFace));
|
SendMessageComposer(new PurchaseFromCatalogAsGiftComposer(pageId, offerId, extraData, receiverName, message, colourId , selectedBoxIndex, selectedRibbonIndex, showMyFace));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, [ extraData, maxBoxIndex, maxRibbonIndex, message, offerId, pageId, receiverName, selectedBoxIndex, selectedColorId, selectedRibbonIndex, showMyFace ]);
|
}, [ colourId, extraData, maxBoxIndex, maxRibbonIndex, message, offerId, pageId, receiverName, selectedBoxIndex, selectedRibbonIndex, showMyFace ]);
|
||||||
|
|
||||||
useMessageEvent<GiftReceiverNotFoundEvent>(GiftReceiverNotFoundEvent, event => setReceiverNotFound(true));
|
useMessageEvent<GiftReceiverNotFoundEvent>(GiftReceiverNotFoundEvent, event => setReceiverNotFound(true));
|
||||||
|
|
||||||
@ -118,6 +127,23 @@ export const CatalogGiftView: FC<{}> = props =>
|
|||||||
setReceiverNotFound(false);
|
setReceiverNotFound(false);
|
||||||
}, [ receiverName ]);
|
}, [ receiverName ]);
|
||||||
|
|
||||||
|
const createBoxTypes = useCallback(() =>
|
||||||
|
{
|
||||||
|
if (!giftConfiguration) return;
|
||||||
|
|
||||||
|
setBoxTypes(prev =>
|
||||||
|
{
|
||||||
|
let newPrev = [ ...giftConfiguration.boxTypes ];
|
||||||
|
|
||||||
|
newPrev.push(giftConfiguration.defaultStuffTypes[ Math.floor((Math.random() * (giftConfiguration.defaultStuffTypes.length - 1))) ]);
|
||||||
|
|
||||||
|
setMaxBoxIndex(newPrev.length- 1);
|
||||||
|
setMaxRibbonIndex(newPrev.length - 1);
|
||||||
|
|
||||||
|
return newPrev;
|
||||||
|
})
|
||||||
|
},[ giftConfiguration ])
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
if(!giftConfiguration) return;
|
if(!giftConfiguration) return;
|
||||||
@ -130,22 +156,28 @@ export const CatalogGiftView: FC<{}> = props =>
|
|||||||
|
|
||||||
if(!giftData) continue;
|
if(!giftData) continue;
|
||||||
|
|
||||||
if(giftData.colors && giftData.colors.length > 0) newColors.push({ id: colorId, color: `#${ giftData.colors[0].toString(16) }` });
|
if(giftData.colors && giftData.colors.length > 0) newColors.push({ id: colorId, color: ColorUtils.makeColorNumberHex(giftData.colors[0]) });
|
||||||
}
|
}
|
||||||
|
|
||||||
setMaxBoxIndex(giftConfiguration.boxTypes.length - 1);
|
createBoxTypes();
|
||||||
setMaxRibbonIndex(giftConfiguration.ribbonTypes.length - 1);
|
|
||||||
|
|
||||||
if(newColors.length)
|
if(newColors.length)
|
||||||
{
|
{
|
||||||
setSelectedColorId(newColors[0].id);
|
setSelectedColorId(newColors[0].id);
|
||||||
setColors(newColors);
|
setColors(newColors);
|
||||||
}
|
}
|
||||||
}, [ giftConfiguration ]);
|
}, [ giftConfiguration, createBoxTypes ]);
|
||||||
|
|
||||||
|
useEffect(() =>
|
||||||
|
{
|
||||||
|
if (!isVisible) return;
|
||||||
|
|
||||||
|
createBoxTypes();
|
||||||
|
},[ createBoxTypes, isVisible ])
|
||||||
|
|
||||||
if(!giftConfiguration || !giftConfiguration.isEnabled || !isVisible) return null;
|
if(!giftConfiguration || !giftConfiguration.isEnabled || !isVisible) return null;
|
||||||
|
|
||||||
const boxName = 'catalog.gift_wrapping_new.box.' + (isBoxDefault ? 'default' : selectedBoxIndex);
|
const boxName = 'catalog.gift_wrapping_new.box.' + (isBoxDefault ? 'default' : boxTypes[selectedBoxIndex]);
|
||||||
const ribbonName = `catalog.gift_wrapping_new.ribbon.${ selectedRibbonIndex }`;
|
const ribbonName = `catalog.gift_wrapping_new.ribbon.${ selectedRibbonIndex }`;
|
||||||
const priceText = 'catalog.gift_wrapping_new.' + (isBoxDefault ? 'freeprice' : 'price');
|
const priceText = 'catalog.gift_wrapping_new.' + (isBoxDefault ? 'freeprice' : 'price');
|
||||||
|
|
||||||
@ -167,7 +199,7 @@ export const CatalogGiftView: FC<{}> = props =>
|
|||||||
<Flex alignItems="center" gap={ 2 }>
|
<Flex alignItems="center" gap={ 2 }>
|
||||||
{ selectedColorId &&
|
{ selectedColorId &&
|
||||||
<Base className="gift-preview">
|
<Base className="gift-preview">
|
||||||
<LayoutFurniImageView productType={ ProductTypeEnum.FLOOR } productClassId={ selectedColorId } extraData={ boxExtraData } />
|
<LayoutFurniImageView productType={ ProductTypeEnum.FLOOR } productClassId={ colourId } extraData={ boxExtraData } />
|
||||||
</Base> }
|
</Base> }
|
||||||
<Column gap={ 1 }>
|
<Column gap={ 1 }>
|
||||||
<Flex gap={ 2 }>
|
<Flex gap={ 2 }>
|
||||||
@ -187,7 +219,7 @@ export const CatalogGiftView: FC<{}> = props =>
|
|||||||
</Flex>
|
</Flex>
|
||||||
</Column>
|
</Column>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex alignItems="center" gap={ 2 }>
|
<Flex alignItems="center" gap={ 2 } className={ isColorable ? '' : 'opacity-50 pointer-events-none' }>
|
||||||
<ButtonGroup>
|
<ButtonGroup>
|
||||||
<Button variant="primary" onClick={ () => handleAction('prev_ribbon') }>
|
<Button variant="primary" onClick={ () => handleAction('prev_ribbon') }>
|
||||||
<FontAwesomeIcon icon="chevron-left" />
|
<FontAwesomeIcon icon="chevron-left" />
|
||||||
@ -200,7 +232,7 @@ export const CatalogGiftView: FC<{}> = props =>
|
|||||||
</Flex>
|
</Flex>
|
||||||
</Column>
|
</Column>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Column gap={ 1 }>
|
<Column gap={ 1 } className={ isColorable ? '' : 'opacity-50 pointer-events-none' }>
|
||||||
<Text fontWeight="bold">
|
<Text fontWeight="bold">
|
||||||
{ LocalizeText('catalog.gift_wrapping.pick_color') }
|
{ LocalizeText('catalog.gift_wrapping.pick_color') }
|
||||||
</Text>
|
</Text>
|
||||||
|
Loading…
Reference in New Issue
Block a user