Skip to content

Commit

Permalink
refact(OfferPresenter): hide changes under DISCOUNTS feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermespopolin committed Jul 5, 2023
1 parent b9b52b8 commit b109c63
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions apps/store/.env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ NEXT_PUBLIC_FEATURE_ENGLISH_LANGUAGE=true
NEXT_PUBLIC_FEATURE_COUNTRY_SELECTOR=true
NEXT_PUBLIC_FEATURE_SAS_PARTNERSHIP=true
NEXT_PUBLIC_FEATURE_HOMECOMING=true
NEXT_PUBLIC_FEATURE_DISCOUNTS=true

# Vercel Edge Config Connection String (https://github.com/vercel/edge-config)
EDGE_CONFIG=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { PriceIntent } from '@/services/priceIntent/priceIntent.types'
import { ShopSession } from '@/services/shopSession/ShopSession.types'
import { useTracking } from '@/services/Tracking/useTracking'
import { convertToDate } from '@/utils/date'
import { Features } from '@/utils/Features'
import { PageLink } from '@/utils/PageLink'
import { useGetDiscountExplanation } from '@/utils/useDiscountExplanation'
import { useFormatter } from '@/utils/useFormatter'
Expand Down Expand Up @@ -296,7 +297,7 @@ const useDiscountTooltipProps = (
if (selectedOffer.priceMatch) {
const company = selectedOffer.priceMatch.externalInsurer.displayName

if (selectedOffer.priceMatch.priceReduction.amount < 1) {
if (selectedOffer.priceMatch.priceReduction.amount <= 0) {
// No price reduction due to incomparable offers
const amount = formatter.monthlyPrice(selectedOffer.priceMatch.externalPrice)
return {
Expand All @@ -315,19 +316,21 @@ const useDiscountTooltipProps = (
} as const
}

const redeemedCampaign = redeemedCampaigns?.[0]
if (redeemedCampaign && selectedOffer.cost.discount.amount > 0) {
return {
children: getDiscountExplanation({
...redeemedCampaign.discount,
amount: selectedOffer.cost.discount,
}),
subtitle: t('DISCOUNT_PRICE_AFTER_EXPIRATION', {
amount: formatter.monthlyPrice(selectedOffer.cost.gross),
ns: 'cart',
}),
color: 'green',
} as const
if (Features.enabled('DISCOUNTS')) {
const redeemedCampaign = redeemedCampaigns?.[0]
if (redeemedCampaign && selectedOffer.cost.discount.amount > 0) {
return {
children: getDiscountExplanation({
...redeemedCampaign.discount,
amount: selectedOffer.cost.discount,
}),
subtitle: t('DISCOUNT_PRICE_AFTER_EXPIRATION', {
amount: formatter.monthlyPrice(selectedOffer.cost.gross),
ns: 'cart',
}),
color: 'green',
} as const
}
}
}, [t, formatter, getDiscountExplanation, selectedOffer, redeemedCampaigns])

Expand Down
1 change: 1 addition & 0 deletions apps/store/src/utils/Features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const config = {
SAS_PARTNERSHIP: process.env.NEXT_PUBLIC_FEATURE_SAS_PARTNERSHIP === 'true',
INSURELY_CAR: process.env.NEXT_PUBLIC_FEATURE_INSURELY_CAR === 'true',
HOMECOMING: process.env.NEXT_PUBLIC_FEATURE_HOMECOMING === 'true',
DISCOUNTS: process.env.NEXT_PUBLIC_FEATURE_DISCOUNTS === 'true',
} as const

export type FeatureFlag = keyof typeof config

0 comments on commit b109c63

Please sign in to comment.