mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-26 07:30:51 +01:00
Add clubgifts requirements & correct sorting (#119)
This commit is contained in:
parent
340aeff64d
commit
9381b37e8a
@ -1,5 +1,5 @@
|
||||
import { SelectClubGiftComposer } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback } from 'react';
|
||||
import { FC, useCallback, useMemo } from 'react';
|
||||
import { LocalizeText, SendMessageComposer } from '../../../../../../api';
|
||||
import { AutoGrid, Text } from '../../../../../../common';
|
||||
import { useCatalog, useNotification, usePurse } from '../../../../../../hooks';
|
||||
@ -41,11 +41,21 @@ export const CatalogLayoutVipGiftsView: FC<CatalogLayoutProps> = props =>
|
||||
}, null);
|
||||
}, [ setCatalogOptions, showConfirm ]);
|
||||
|
||||
const sortGifts = useMemo(() =>
|
||||
{
|
||||
let gifts = clubGifts.offers.sort((a,b) =>
|
||||
{
|
||||
return clubGifts.getOfferExtraData(a.offerId).daysRequired - clubGifts.getOfferExtraData(b.offerId).daysRequired;
|
||||
})
|
||||
return gifts;
|
||||
},[ clubGifts ]);
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Text truncate shrink fontWeight="bold">{ giftsAvailable() }</Text>
|
||||
<AutoGrid columnCount={ 1 } className="nitro-catalog-layout-vip-gifts-grid">
|
||||
{ (clubGifts.offers.length > 0) && clubGifts.offers.map(offer => <VipGiftItem key={ offer.offerId } offer={ offer } isAvailable={ (clubGifts.getOfferExtraData(offer.offerId).isSelectable && (clubGifts.giftsAvailable > 0)) } onSelect={ selectGift }/>) }
|
||||
{ (clubGifts.offers.length > 0) && sortGifts.map(offer => <VipGiftItem key={ offer.offerId } offer={ offer } isAvailable={ (clubGifts.getOfferExtraData(offer.offerId).isSelectable && (clubGifts.giftsAvailable > 0)) } onSelect={ selectGift } daysRequired={ clubGifts.getOfferExtraData(offer.offerId).daysRequired }/>) }
|
||||
</AutoGrid>
|
||||
</>
|
||||
)
|
||||
|
@ -7,12 +7,13 @@ export interface VipGiftItemViewProps
|
||||
{
|
||||
offer: CatalogPageMessageOfferData;
|
||||
isAvailable: boolean;
|
||||
daysRequired: number;
|
||||
onSelect(localizationId: string): void;
|
||||
}
|
||||
|
||||
export const VipGiftItem : FC<VipGiftItemViewProps> = props =>
|
||||
{
|
||||
const { offer = null, isAvailable = false, onSelect = null } = props;
|
||||
const { offer = null, isAvailable = false, daysRequired = 0, onSelect = null } = props;
|
||||
|
||||
const getImageUrlForOffer = useCallback( () =>
|
||||
{
|
||||
@ -45,6 +46,11 @@ export const VipGiftItem : FC<VipGiftItemViewProps> = props =>
|
||||
return LocalizeText(localizationKey);
|
||||
}, [ offer ]);
|
||||
|
||||
const getMonthsRequired = useCallback(() =>
|
||||
{
|
||||
return Math.floor(daysRequired / 31);
|
||||
},[ daysRequired ]);
|
||||
|
||||
return (
|
||||
<LayoutGridItem center={ false } column={ false } alignItems="center" className="p-1">
|
||||
<LayoutImage imageUrl={ getImageUrlForOffer() } />
|
||||
|
Loading…
Reference in New Issue
Block a user