Skip to content

Commit

Permalink
feat: make Trustpilot data available globally
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermespopolin committed Jul 7, 2023
1 parent 917f0bf commit 4f41042
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions apps/store/src/components/LayoutWithMenu/LayoutWithMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HeaderBlock } from '@/blocks/HeaderBlock'
import { ReusableBlockReference } from '@/blocks/ReusableBlockReference'
import { PageStory, StoryblokPageProps } from '@/services/storyblok/storyblok'
import { filterByBlockType, isProductStory } from '@/services/storyblok/Storyblok.helpers'
import { useHydrateTrustpilotData } from '@/services/trustpilot/trustpilot'
import { useChangeLocale } from '@/utils/l10n/useChangeLocale'
import { BreadcrumbList, BreadcrumbListItem } from './BreadcrumbList'
import { GlobalProductMetadata, GLOBAL_PRODUCT_METADATA_PROP_NAME } from './fetchProductMetadata'
Expand Down Expand Up @@ -33,6 +34,7 @@ export const LayoutWithMenu = (props: LayoutWithMenuProps) => {
const { story, globalStory, className, breadcrumbs } = props.children.props

useHydrateProductMetadata(props.children.props[GLOBAL_PRODUCT_METADATA_PROP_NAME])
useHydrateTrustpilotData(props.children.props.trustpilot)
const handleLocaleChange = useChangeLocale(story)

// Announcements are added as reusable blocks for Page and ProductPage content types
Expand Down
2 changes: 2 additions & 0 deletions apps/store/src/components/ProductPage/ProductPage.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ProductDataQuery } from '@/services/apollo/generated'
import { Template } from '@/services/PriceCalculator/PriceCalculator.types'
import { ProductStory, StoryblokPageProps } from '@/services/storyblok/storyblok'
import { type TrustpilotData } from '@/services/trustpilot/trustpilot.types'

export type ProductData = Exclude<ProductDataQuery['product'], null | undefined>

Expand All @@ -13,4 +14,5 @@ export type ProductPageProps = StoryblokPageProps & {
priceTemplate: Template
productData: ProductData
initialSelectedVariant?: ProductDataVariant
trustpilot: TrustpilotData
}
5 changes: 4 additions & 1 deletion apps/store/src/pages/[[...slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from '@/services/storyblok/storyblok'
import { GLOBAL_STORY_PROP_NAME, STORY_PROP_NAME } from '@/services/storyblok/Storyblok.constant'
import { isProductStory } from '@/services/storyblok/Storyblok.helpers'
import { fetchTrustpilotData } from '@/services/trustpilot/trustpilot'
import { isRoutingLocale } from '@/utils/l10n/localeUtils'

type NextContentPageProps = StoryblokPageProps & { type: 'content' }
Expand Down Expand Up @@ -75,11 +76,12 @@ export const getStaticProps: GetStaticProps<PageProps, StoryblokQueryParams> = a
const timerName = `Get static props for ${locale}/${slug} ${draftMode ? '(draft)' : ''}`
console.time(timerName)
const version = draftMode ? 'draft' : 'published'
const [globalStory, translations, productMetadata, breadcrumbs] = await Promise.all([
const [globalStory, translations, productMetadata, breadcrumbs, trustpilot] = await Promise.all([
getGlobalStory({ version, locale }),
serverSideTranslations(locale),
fetchGlobalProductMetadata({ apolloClient }),
fetchBreadcrumbs(slug, { version, locale }),
fetchTrustpilotData(),
]).catch((error) => {
throw new Error(`Failed to fetch data for ${slug}: ${error.message}`, { cause: error })
})
Expand All @@ -101,6 +103,7 @@ export const getStaticProps: GetStaticProps<PageProps, StoryblokQueryParams> = a
[GLOBAL_STORY_PROP_NAME]: globalStory,
[GLOBAL_PRODUCT_METADATA_PROP_NAME]: productMetadata,
breadcrumbs,
trustpilot,
}
const revalidate = process.env.VERCEL_ENV === 'preview' ? 1 : false

Expand Down
2 changes: 2 additions & 0 deletions apps/store/src/services/storyblok/storyblok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { blogBlocks } from '@/features/blog/blogBlocks'
// TODO: get rid of this import, services should avoid feature-imports
import { STORYBLOK_MANYPETS_FOLDER_SLUG } from '@/features/manyPets/manyPets.constants'
import { manyPetsBlocks } from '@/features/manyPets/manyPetsBlocks'
import { TrustpilotData } from '@/services/trustpilot/trustpilot.types'
import { isBrowser } from '@/utils/env'
import { Features } from '@/utils/Features'
import { getLocaleOrFallback, isRoutingLocale } from '@/utils/l10n/localeUtils'
Expand All @@ -98,6 +99,7 @@ export type StoryblokQueryParams = {
export type StoryblokPageProps = {
[STORY_PROP_NAME]: PageStory
[GLOBAL_STORY_PROP_NAME]: GlobalStory
trustpilot: TrustpilotData
}

export type StoryblokVersion = 'draft' | 'published'
Expand Down

0 comments on commit 4f41042

Please sign in to comment.