Skip to content

Commit

Permalink
feat(purchase-summary-add-new-insurance): loads price intent from cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermespopolin committed Oct 18, 2024
1 parent 3a52885 commit 184535c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/store/public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* - Please do NOT serve this file on production.
*/

const PACKAGE_VERSION = '2.4.7'
const PACKAGE_VERSION = '2.4.11'
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
const activeClientIds = new Set()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function OfferSummary() {
// the flow while still can load price calculator for that product again by refreshing the
// page or navigating back.
const priceIntentService = priceIntentServiceInitClientSide(apolloClient)
priceIntentService.create({
await priceIntentService.create({
shopSessionId,
productName: selectedOffer.product.name,
priceTemplate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useApolloClient } from '@apollo/client'
import clsx from 'clsx'
import { useSetAtom } from 'jotai'
import { useTranslation } from 'next-i18next'
import { useCallback, useEffect } from 'react'
import { useEffect } from 'react'
import { Text, Card, Divider, Button, yStack } from 'ui'
import type { Banner } from '@/components/Banner/Banner.types'
import { ButtonNextLink } from '@/components/ButtonNextLink'
import { useSetGlobalBanner, useDismissBanner } from '@/components/GlobalBanner/globalBannerState'
import { Pillow } from '@/components/Pillow/Pillow'
import { useResetPriceIntent } from '@/components/ProductPage/PurchaseForm/priceIntentAtoms'
import { currentPriceIntentIdAtom } from '@/components/ProductPage/PurchaseForm/priceIntentAtoms'
import { usePriceTemplate } from '@/components/ProductPage/PurchaseForm/priceTemplateAtom'
import { useSelectedOfferValueOrThrow } from '@/components/ProductPage/PurchaseForm/useSelectedOffer'
import { TextWithLink } from '@/components/TextWithLink'
Expand All @@ -20,7 +22,11 @@ import {
hasCartItemsEligibleForBundleDiscount,
} from '@/features/bundleDiscount/bundleDiscount.utils'
import type { TemplateV2 } from '@/services/PriceCalculator/PriceCalculator.types'
import { useShopSessionValueOrThrow } from '@/services/shopSession/ShopSessionContext'
import { priceIntentServiceInitClientSide } from '@/services/priceIntent/PriceIntentService'
import {
useShopSessionIdOrThrow,
useShopSessionValueOrThrow,
} from '@/services/shopSession/ShopSessionContext'
import { getOfferPrice } from '@/utils/getOfferPrice'
import { useRoutingLocale } from '@/utils/l10n/useRoutingLocale'
import { PageLink } from '@/utils/PageLink'
Expand All @@ -29,15 +35,22 @@ import { actions } from './PurchaseSummary.css'
export function PurchaseSummary({ className }: { className?: string }) {
const { t } = useTranslation('purchase-form')
const locale = useRoutingLocale()
const apolloClient = useApolloClient()
const shopSessionId = useShopSessionIdOrThrow()
const offer = useSelectedOfferValueOrThrow()
const priceTemplate = usePriceTemplate() as TemplateV2
const resetPriceIntent = useResetPriceIntent()
const setCurrentPriceIntentId = useSetAtom(currentPriceIntentIdAtom)

useNotifyAboutBundleDiscounts()

const handleAddMore = useCallback(() => {
resetPriceIntent()
}, [resetPriceIntent])
const handleAddMore = () => {
const priceIntentService = priceIntentServiceInitClientSide(apolloClient)
const priceIntentId = priceIntentService.getStoredId(priceTemplate.name, shopSessionId)
if (!priceIntentId) {
throw new Error('Price intent id should be stored in a cookie at this point')
}
setCurrentPriceIntentId(priceIntentId)
}

const showAddMoreButton = offer.product.multiple && priceTemplate.addMultiple

Expand Down Expand Up @@ -67,10 +80,10 @@ export function PurchaseSummary({ className }: { className?: string }) {
})}
</Button>
)}
<ButtonNextLink href={PageLink.checkout({ locale })} variant="primary">
<ButtonNextLink href={PageLink.checkout({ locale }).toRelative()} variant="primary">
{t('GO_TO_CART_LABEL')}
</ButtonNextLink>
<ButtonNextLink href={PageLink.store({ locale })} variant="ghost">
<ButtonNextLink href={PageLink.store({ locale }).toRelative()} variant="ghost">
{t('SEE_MORE_INSURANCES_LABEL')}
</ButtonNextLink>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/store/src/utils/PageLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const PageLink = {
if (locale === 'se') {
slug = 'forsakringar'
}
return new URL(`${locale}/${slug}`, ORIGIN_URL)
return new ExtendedURL(`${locale}/${slug}`, ORIGIN_URL)
},
checkout: ({ locale, expandCart = false }: CheckoutPage) => {
const url = new ExtendedURL(`${locale}/checkout`, ORIGIN_URL)
Expand Down

0 comments on commit 184535c

Please sign in to comment.