From f4dc7028f02ed120adfae86c008077fb4f0cbc8c Mon Sep 17 00:00:00 2001 From: Bill Date: Sat, 24 Jul 2021 04:04:27 -0400 Subject: [PATCH] Catalog vip purchase --- src/views/catalog/CatalogMessageHandler.tsx | 8 +- .../item/CatalogNavigationItemView.tsx | 2 + .../vip-buy/CatalogLayoutVipBuyView.scss | 9 +- .../vip-buy/CatalogLayoutVipBuyView.tsx | 165 +++++++++++++----- 4 files changed, 133 insertions(+), 51 deletions(-) diff --git a/src/views/catalog/CatalogMessageHandler.tsx b/src/views/catalog/CatalogMessageHandler.tsx index bcc13b40..70ddf952 100644 --- a/src/views/catalog/CatalogMessageHandler.tsx +++ b/src/views/catalog/CatalogMessageHandler.tsx @@ -127,11 +127,11 @@ export const CatalogMessageHandler: FC = props => type: CatalogActions.SET_SUBSCRIPTION_INFO, payload: { subscriptionInfo: new SubscriptionInfo( - Math.max(0, parser.days), - Math.max(0, parser.months), + Math.max(0, parser.daysToPeriodEnd), + Math.max(0, parser.periodsSubscribedAhead), parser.isVip, parser.pastClubDays, - parser.pastVIPDays + parser.pastVipDays ) } }); @@ -149,8 +149,6 @@ export const CatalogMessageHandler: FC = props => { const parser = event.getParser(); - console.log(parser); - dispatchCatalogState({ type: CatalogActions.SET_GIFT_CONFIGURATION, payload: { diff --git a/src/views/catalog/views/navigation/item/CatalogNavigationItemView.tsx b/src/views/catalog/views/navigation/item/CatalogNavigationItemView.tsx index baebd013..85878246 100644 --- a/src/views/catalog/views/navigation/item/CatalogNavigationItemView.tsx +++ b/src/views/catalog/views/navigation/item/CatalogNavigationItemView.tsx @@ -45,6 +45,8 @@ export const CatalogNavigationItemView: FC = pro SendMessageHook(new CatalogPageComposer(page.pageId, -1, CatalogMode.MODE_NORMAL)); }, [ isActive, page, select, dispatchCatalogState ]); + + if(!page.visible) return null; return (
diff --git a/src/views/catalog/views/page/layout/vip-buy/CatalogLayoutVipBuyView.scss b/src/views/catalog/views/page/layout/vip-buy/CatalogLayoutVipBuyView.scss index 00fac98f..fd44278a 100644 --- a/src/views/catalog/views/page/layout/vip-buy/CatalogLayoutVipBuyView.scss +++ b/src/views/catalog/views/page/layout/vip-buy/CatalogLayoutVipBuyView.scss @@ -1,7 +1,10 @@ .nitro-catalog-layout-vip-buy { - .catalog-offer-item-container { - height: 60px !important; - max-height: 60px !important; + .vip-buy-grid { + + .grid-item-container { + height: 70px !important; + max-height: 70px !important; + } } } diff --git a/src/views/catalog/views/page/layout/vip-buy/CatalogLayoutVipBuyView.tsx b/src/views/catalog/views/page/layout/vip-buy/CatalogLayoutVipBuyView.tsx index 554e1c58..2fdd4a9e 100644 --- a/src/views/catalog/views/page/layout/vip-buy/CatalogLayoutVipBuyView.tsx +++ b/src/views/catalog/views/page/layout/vip-buy/CatalogLayoutVipBuyView.tsx @@ -1,7 +1,11 @@ -import { CatalogClubOfferData, CatalogRequestVipOffersComposer } from 'nitro-renderer'; -import { FC, useCallback, useEffect, useMemo } from 'react'; +import { CatalogClubOfferData, CatalogPurchaseComposer, CatalogRequestVipOffersComposer } from 'nitro-renderer'; +import { FC, useCallback, useEffect, useMemo, useState } from 'react'; +import { Button } from 'react-bootstrap'; import { SendMessageHook } from '../../../../../../hooks/messages/message-event'; +import { NitroCardGridItemView } from '../../../../../../layout/card/grid/item/NitroCardGridItemView'; +import { NitroCardGridView } from '../../../../../../layout/card/grid/NitroCardGridView'; import { LocalizeText } from '../../../../../../utils/LocalizeText'; +import { GLOBAL_PURSE } from '../../../../../purse/PurseView'; import { CurrencyIcon } from '../../../../../shared/currency-icon/CurrencyIcon'; import { GetCatalogPageImage } from '../../../../common/CatalogUtilities'; import { useCatalogContext } from '../../../../context/CatalogContext'; @@ -11,16 +15,7 @@ export const CatalogLayoutVipBuyView: FC = props = { const { catalogState = null } = useCatalogContext(); const { pageParser = null, clubOffers = null, subscriptionInfo = null } = catalogState; - - useEffect(() => - { - if(clubOffers === null) - { - SendMessageHook(new CatalogRequestVipOffersComposer(1)); - - return; - } - }, [ clubOffers ]); + const [ pendingOffer, setPendingOffer ] = useState(null); const getOfferText = useCallback((offer: CatalogClubOfferData) => { @@ -41,6 +36,31 @@ export const CatalogLayoutVipBuyView: FC = props = return offerText; }, []); + const getPurchaseHeader = useCallback(() => + { + const purse = GLOBAL_PURSE; + + if(!purse) return ''; + + const extensionOrSubscription = (purse.clubDays > 0 || purse.clubPeriods > 0) ? 'extension.' : 'subscription.'; + const daysOrMonths = ((pendingOffer.months === 0) ? 'days' : 'months'); + const daysOrMonthsText = ((pendingOffer.months === 0) ? pendingOffer.extraDays : pendingOffer.months); + const locale = LocalizeText('catalog.vip.buy.confirm.' + extensionOrSubscription + daysOrMonths); + + return locale.replace('%NUM_' + daysOrMonths.toUpperCase() + '%', daysOrMonthsText.toString()); + }, [ pendingOffer ]); + + const getPurchaseValidUntil = useCallback(() => + { + let locale = LocalizeText('catalog.vip.buy.confirm.end_date'); + + locale = locale.replace('%month%', pendingOffer.month.toString()); + locale = locale.replace('%day%', pendingOffer.day.toString()); + locale = locale.replace('%year%', pendingOffer.year.toString()); + + return locale; + }, [ pendingOffer ]); + const getSubscriptionDetails = useMemo(() => { if(!subscriptionInfo) return ''; @@ -52,41 +72,100 @@ export const CatalogLayoutVipBuyView: FC = props = return LocalizeText('catalog.vip.extend.info', [ 'days' ], [ totalDays.toString() ]); }, [ subscriptionInfo ]); + const purchaseSubscription = useCallback(() => + { + if(!pendingOffer) return; + + SendMessageHook(new CatalogPurchaseComposer(pageParser.pageId, pendingOffer.offerId, null, 1)); + }, [ pendingOffer, pageParser ]) + + useEffect(() => + { + if(clubOffers === null) + { + SendMessageHook(new CatalogRequestVipOffersComposer(1)); + + return; + } + }, [ clubOffers ]); + return ( -
-
-
- { clubOffers && (clubOffers.length > 0) && clubOffers.map((offer, index) => - { - return
-
-
- - { getOfferText(offer) } -
-
- { (offer.priceCredits > 0) && -
- { offer.priceCredits } - -
} - { (offer.priceActivityPoints > 0) && -
- { offer.priceActivityPoints } - + <> +
+
+ + { clubOffers && (clubOffers.length > 0) && clubOffers.map((offer, index) => + { + return ( + + { (pendingOffer === offer) && +
+
{ getPurchaseHeader() }
+
{ getPurchaseValidUntil() }
+
} + { (pendingOffer !== offer) && + <> +
+
+ + { getOfferText(offer) } +
+
+ { (offer.priceCredits > 0) && +
+ { offer.priceCredits } + +
} + { (offer.priceActivityPoints > 0) && +
+ { offer.priceActivityPoints } + +
} +
+
+ + } +
+ ); + }) } +
+ {/*
+ { clubOffers && (clubOffers.length > 0) && clubOffers.map((offer, index) => + { + return ( +
+
+
+ + { getOfferText(offer) } +
+
+ { (offer.priceCredits > 0) && +
+ { offer.priceCredits } + +
} + { (offer.priceActivityPoints > 0) && +
+ { offer.priceActivityPoints } + +
} +
+
-
-
; - })} + ); + }) } +
*/} +
+
+
+ +
+
-
-
- -
-
-
-
+ ); }