mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-26 15:40: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 { SelectClubGiftComposer } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useCallback } from 'react';
|
import { FC, useCallback, useMemo } from 'react';
|
||||||
import { LocalizeText, SendMessageComposer } from '../../../../../../api';
|
import { LocalizeText, SendMessageComposer } from '../../../../../../api';
|
||||||
import { AutoGrid, Text } from '../../../../../../common';
|
import { AutoGrid, Text } from '../../../../../../common';
|
||||||
import { useCatalog, useNotification, usePurse } from '../../../../../../hooks';
|
import { useCatalog, useNotification, usePurse } from '../../../../../../hooks';
|
||||||
@ -41,11 +41,21 @@ export const CatalogLayoutVipGiftsView: FC<CatalogLayoutProps> = props =>
|
|||||||
}, null);
|
}, null);
|
||||||
}, [ setCatalogOptions, showConfirm ]);
|
}, [ 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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Text truncate shrink fontWeight="bold">{ giftsAvailable() }</Text>
|
<Text truncate shrink fontWeight="bold">{ giftsAvailable() }</Text>
|
||||||
<AutoGrid columnCount={ 1 } className="nitro-catalog-layout-vip-gifts-grid">
|
<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>
|
</AutoGrid>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
@ -7,12 +7,13 @@ export interface VipGiftItemViewProps
|
|||||||
{
|
{
|
||||||
offer: CatalogPageMessageOfferData;
|
offer: CatalogPageMessageOfferData;
|
||||||
isAvailable: boolean;
|
isAvailable: boolean;
|
||||||
|
daysRequired: number;
|
||||||
onSelect(localizationId: string): void;
|
onSelect(localizationId: string): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const VipGiftItem : FC<VipGiftItemViewProps> = props =>
|
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( () =>
|
const getImageUrlForOffer = useCallback( () =>
|
||||||
{
|
{
|
||||||
@ -45,6 +46,11 @@ export const VipGiftItem : FC<VipGiftItemViewProps> = props =>
|
|||||||
return LocalizeText(localizationKey);
|
return LocalizeText(localizationKey);
|
||||||
}, [ offer ]);
|
}, [ offer ]);
|
||||||
|
|
||||||
|
const getMonthsRequired = useCallback(() =>
|
||||||
|
{
|
||||||
|
return Math.floor(daysRequired / 31);
|
||||||
|
},[ daysRequired ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LayoutGridItem center={ false } column={ false } alignItems="center" className="p-1">
|
<LayoutGridItem center={ false } column={ false } alignItems="center" className="p-1">
|
||||||
<LayoutImage imageUrl={ getImageUrlForOffer() } />
|
<LayoutImage imageUrl={ getImageUrlForOffer() } />
|
||||||
|
Loading…
Reference in New Issue
Block a user