Skip to content

Commit

Permalink
Revert "refact: hide discount related changed under DISCOUNTS feature…
Browse files Browse the repository at this point in the history
… flag"

This reverts commit e2c978c.
  • Loading branch information
guilhermespopolin committed Jul 5, 2023
1 parent 156023a commit 7a8fe5e
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ import { motion } from 'framer-motion'
import { useTranslation } from 'next-i18next'
import React, { ReactNode, useState } from 'react'
import { ChevronIcon, Text, theme } from 'ui'
import type { Money, ProductOfferFragment } from '@/services/apollo/generated'
import { Features } from '@/utils/Features'
import { ProductOfferFragment } from '@/services/apollo/generated'
import { useFormatter } from '@/utils/useFormatter'

type Props = {
defaultOpen: boolean
price: Money
cost: ProductOfferFragment['cost']
children: ReactNode
}
type Props = { defaultOpen: boolean; cost: ProductOfferFragment['cost']; children: ReactNode }

export const CartEntryCollapsible = ({ defaultOpen, price, cost, children }: Props) => {
export const CartEntryCollapsible = ({ defaultOpen, cost, children }: Props) => {
const [open, setOpen] = useState(defaultOpen)
const { t } = useTranslation('cart')
const formatter = useFormatter()

const hasDiscountApplied = cost.discount.amount > 0

return (
<Collapsible.Root open={open} onOpenChange={setOpen}>
<DetailsHeader>
Expand All @@ -28,16 +24,12 @@ export const CartEntryCollapsible = ({ defaultOpen, price, cost, children }: Pro
<ChevronIcon color={theme.colors.textTertiary} size="1rem" />
</Trigger>
<PriceFlex>
{Features.enabled('DISCOUNTS') && cost.discount.amount > 0 && (
{hasDiscountApplied && (
<Text color="textSecondary" strikethrough={true}>
{formatter.monthlyPrice(cost.gross)}
</Text>
)}
<Text>
{Features.enabled('DISCOUNTS')
? formatter.monthlyPrice(cost.net)
: formatter.monthlyPrice(price)}
</Text>
<Text>{formatter.monthlyPrice(cost.net)}</Text>
</PriceFlex>
</DetailsHeader>
<CollapsibleContent forceMount>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Props = CartEntry & {

export const CartEntryItem = ({ defaultOpen = false, ...props }: Props) => {
const { shopSessionId, readOnly, onRemove, ...cartEntry } = props
const { title: titleLabel, price, cost, pillow } = cartEntry
const { title: titleLabel, cost, pillow } = cartEntry
const { t } = useTranslation('cart')

const [editProductOffer, editState] = useEditProductOffer()
Expand Down Expand Up @@ -49,7 +49,7 @@ export const CartEntryItem = ({ defaultOpen = false, ...props }: Props) => {

<Space y={1}>
<Layout.Details>
<CartEntryCollapsible defaultOpen={defaultOpen} price={price} cost={cost}>
<CartEntryCollapsible defaultOpen={defaultOpen} cost={cost}>
<DetailsSheet {...cartEntry} />
</CartEntryCollapsible>
</Layout.Details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
ProductRecommendationFragment,
} from '@/services/apollo/generated'
import { useTracking } from '@/services/Tracking/useTracking'
import { Features } from '@/utils/Features'
import { useFormatter } from '@/utils/useFormatter'

type CartOfferItemProps = {
Expand Down Expand Up @@ -54,6 +53,8 @@ export const CartEntryOfferItem = ({ shopSessionId, product, offer }: CartOfferI

if (!show) return null

const hasDiscountApplied = offer.cost.discount.amount > 0

return (
<Layout.Main>
<Layout.Pillow>
Expand Down Expand Up @@ -97,14 +98,12 @@ export const CartEntryOfferItem = ({ shopSessionId, product, offer }: CartOfferI
</Layout.Actions>

<Layout.Price>
{Features.enabled('DISCOUNTS') && offer.cost.discount.amount > 0 && (
{hasDiscountApplied && (
<Text color="textSecondary" strikethrough={true}>
{formatter.monthlyPrice(offer.cost.gross)}
</Text>
)}
{Features.enabled('DISCOUNTS')
? formatter.monthlyPrice(offer.cost.net)
: formatter.monthlyPrice(offer.price)}
{formatter.monthlyPrice(offer.cost.net)}
</Layout.Price>
</Layout.Main>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export const getCartEntry = (item: ShopSession['cart']['entries'][number]): Cart
return {
offerId: item.id,
title: item.variant.product.displayNameFull,
price: item.price,
cost: item.cost,
startDate: hasCancellation ? undefined : convertToDate(item.startDate),
pillow: {
Expand Down
1 change: 0 additions & 1 deletion apps/store/src/components/CartInventory/CartInventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const CartInventory = ({ shopSessionId, cart, readOnly = false }: Props)
key={item.id}
offerId={item.id}
title={item.variant.product.displayNameFull}
price={item.price}
cost={item.cost}
pillow={{
src: item.variant.product.pillowImage.src,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Money } from '@/utils/formatter'
export type CartEntry = {
offerId: string
title: string
price: Money
cost: ProductOfferFragment['cost']
startDate?: Date | null
pillow: { src: string; alt?: string }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { FormElement } from '@/components/ProductPage/PurchaseForm/PurchaseForm.
import * as TierLevelRadioGroup from '@/components/TierSelector/TierLevelRadioGroup'
import * as TierSelector from '@/components/TierSelector/TierSelector'
import { Money, ProductOfferFragment } from '@/services/apollo/generated'
import { Features } from '@/utils/Features'
import { useCurrentLocale } from '@/utils/l10n/useCurrentLocale'
import { PageLink } from '@/utils/PageLink'
import { useFormatter } from '@/utils/useFormatter'
Expand Down Expand Up @@ -36,10 +35,9 @@ export const DeductibleSelector = ({ offers, selectedOffer, onValueChange }: Pro

offers.forEach((offer) => {
if (offer.deductible) {
const price = Features.enabled('DISCOUNTS') ? offer.cost.net : offer.price
levels.push({
id: offer.id,
price,
price: offer.cost.net,
title: offer.deductible.displayName,
description: offer.deductible.tagline,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Text } from 'ui'
import * as TierLevelRadioGroup from '@/components/TierSelector/TierLevelRadioGroup'
import * as TierSelector from '@/components/TierSelector/TierSelector'
import { ProductOfferFragment } from '@/services/apollo/generated'
import { Features } from '@/utils/Features'
import { useFormatter } from '@/utils/useFormatter'

type Props = {
Expand All @@ -27,18 +26,15 @@ export const ProductTierSelector = ({ offers, selectedOffer, onValueChange }: Pr

<TierSelector.Content>
<TierLevelRadioGroup.Root value={selectedOffer.id} onValueChange={onValueChange}>
{offers.map((offer) => {
const price = Features.enabled('DISCOUNTS') ? offer.cost.net : offer.price
return (
<TierLevelRadioGroup.Item
key={offer.id}
value={offer.id}
title={offer.variant.displayName}
price={formatter.monthlyPrice(price)}
description={getVariantDescription(offer.variant.typeOfContract)}
/>
)
})}
{offers.map((offer) => (
<TierLevelRadioGroup.Item
key={offer.id}
value={offer.id}
title={offer.variant.displayName}
price={formatter.monthlyPrice(offer.cost.net)}
description={getVariantDescription(offer.variant.typeOfContract)}
/>
))}
</TierLevelRadioGroup.Root>
</TierSelector.Content>
</TierSelector.Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { useShopSession } from '@/services/shopSession/ShopSessionContext'
import { TrackingContextKey } from '@/services/Tracking/Tracking'
import { useTracking } from '@/services/Tracking/useTracking'
import { sendDialogEvent } from '@/utils/dialogEvent'
import { Features } from '@/utils/Features'
import { useBreakpoint } from '@/utils/useBreakpoint/useBreakpoint'
import { useFormatter } from '@/utils/useFormatter'
import { ScrollPast } from '../ScrollPast/ScrollPast'
Expand Down Expand Up @@ -198,10 +197,9 @@ export const PurchaseForm = () => {
return await router.push(nextUrl)
}

const price = Features.enabled('DISCOUNTS') ? item.cost.net : item.price
notifyProductAdded({
name: productData.displayNameFull,
price: formatter.monthlyPrice(price),
price: formatter.monthlyPrice(item.cost.net),
pillowSrc: productData.pillowImage.src,
description:
!item.cancellation.requested ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import { ProductOfferFragment } from '@/services/apollo/generated'
import { Features } from '@/utils/Features'

export const getOffersByPrice = (offers: Array<ProductOfferFragment>) => {
return [...offers].sort(Features.enabled('DISCOUNTS') ? sortByCost : sortByPrice)
}

const sortByCost = (a: ProductOfferFragment, b: ProductOfferFragment) => {
if (a.cost.net.amount < b.cost.net.amount) return -1
if (a.cost.net.amount > b.cost.net.amount) return 1
return 0
}

const sortByPrice = (a: ProductOfferFragment, b: ProductOfferFragment) => {
if (a.price.amount < b.price.amount) return -1
if (a.price.amount > b.price.amount) return 1
return 0
return [...offers].sort((a, b) => {
if (a.cost.net.amount < b.cost.net.amount) return -1
if (a.cost.net.amount > b.cost.net.amount) return 1
return 0
})
}
4 changes: 0 additions & 4 deletions apps/store/src/graphql/OfferRecommendationFragment.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ fragment OfferRecommendation on ProductOffer {
displayNameFull
}
}
price {
amount
currencyCode
}
cost {
gross {
amount
Expand Down
4 changes: 0 additions & 4 deletions apps/store/src/graphql/ProductOfferFragment.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ fragment ProductOffer on ProductOffer {
url
}
}
price {
amount
currencyCode
}
cost {
gross {
amount
Expand Down
30 changes: 11 additions & 19 deletions apps/store/src/services/Tracking/Tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from '@/services/gtm'
import { PriceIntent } from '@/services/priceIntent/priceIntent.types'
import { ShopSession } from '@/services/shopSession/ShopSession.types'
import { Features } from '@/utils/Features'
import { getAdtractionProductCategories } from './adtraction'

type TrackingContext = Partial<Record<TrackingContextKey, unknown>>
Expand All @@ -21,7 +20,6 @@ type TrackingProductData = {
}

type TrackingOffer = {
price: ProductOfferFragment['price']
cost: ProductOfferFragment['cost']
variant: {
typeOfContract: ProductOfferFragment['variant']['typeOfContract']
Expand Down Expand Up @@ -140,11 +138,10 @@ export class Tracking {
public async reportOfferCreated(offer: ProductOfferFragment) {
const event = TrackingEvent.OfferCreated
const userData = await getLegacyUserData(this.context)
const price = Features.enabled('DISCOUNTS') ? offer.cost.gross : offer.price
const eventData = {
offerData: {
insurance_price: price.amount,
currency: price.currencyCode as string,
insurance_price: offer.cost.gross.amount,
currency: offer.cost.gross.currencyCode as string,

insurance_type: offer.variant.typeOfContract,
flow_type: offer.variant.product.name,
Expand Down Expand Up @@ -304,17 +301,16 @@ const offerToEcommerceEvent = ({
context,
source,
}: OfferToEcommerseEventParams): EcommerceEvent => {
const price = Features.enabled('DISCOUNTS') ? offer.cost.gross : offer.price
return {
event,
ecommerce: {
value: price.amount,
currency: price.currencyCode,
value: offer.cost.gross.amount,
currency: offer.cost.gross.currencyCode,
items: [
{
item_id: offer.variant.product.id,
item_name: offer.variant.product.displayNameFull,
price: price.amount,
price: offer.cost.gross.amount,
item_variant: offer.variant.typeOfContract,
...(source && { item_list_id: source }),
},
Expand Down Expand Up @@ -342,16 +338,12 @@ const cartToEcommerceEvent = (
ecommerce: {
value: cart.cost.net.amount,
currency: cart.cost.net.currencyCode,
items: cart.entries.map((entry) => {
const price = Features.enabled('DISCOUNTS') ? entry.cost.gross : entry.price

return {
item_id: entry.variant.product.id,
item_name: entry.variant.product.displayNameFull,
price: price.amount,
variant: entry.variant.typeOfContract,
}
}),
items: cart.entries.map((entry) => ({
item_id: entry.variant.product.id,
item_name: entry.variant.product.displayNameFull,
price: entry.cost.gross.amount,
variant: entry.variant.typeOfContract,
})),
},
shopSession: {
id: context[TrackingContextKey.ShopSessionId] as string,
Expand Down

0 comments on commit 7a8fe5e

Please sign in to comment.