Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create review and ratings section structure #2663

Merged
merged 6 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/core/cms/faststore/sections.json
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,21 @@
}
}
},
{
"name": "ReviewsAndRatings",
"schema": {
"title": "Reviews And Ratings",
"description": "A section to display product reviews and ratings",
"type": "object",
"properties": {
"title": {
"title": "Title",
"type": "string",
"default": "Reviews"
}
}
}
},
{
"name": "CrossSellingShelf",
"requiredScopes": ["pdp", "custom"],
Expand Down
1 change: 1 addition & 0 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { default as AlertSection } from './src/components/sections/Alert'
export { default as BannerTextSection } from './src/components/sections/BannerText'
export { default as BreadcrumbSection } from './src/components/sections/Breadcrumb'
export { default as CrossSellingShelfSection } from './src/components/sections/CrossSellingShelf'
export { default as ReviewsAndRatingsSection } from './src/components/sections/ReviewsAndRatings'
export { default as EmptyState } from './src/components/sections/EmptyState'
export { default as HeroSection } from './src/components/sections/Hero'
export { default as NavbarSection } from './src/components/sections/Navbar'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const ReviewsAndRatingsDefaultComponents = {
// TODO: Update this with the components that will be used in ReviewsAndRatings section
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎗️

// Olhar o packages/core/src/components/sections/ProductGallery/DefaultComponents.ts
// ou o packages/core/src/components/sections/ProductShelf/DefaultComponents.ts
// para se basear
} as const
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { override } from 'src/customizations/src/components/overrides/ReviewsAndRatings'
import { override as overridePlugin } from 'src/plugins/overrides/ReviewsAndRatings'
import { getOverriddenSection } from 'src/sdk/overrides/getOverriddenSection'
import type { SectionOverrideDefinitionV1 } from 'src/typings/overridesDefinition'
import ReviewsAndRatings from '.'

/**
* This component exists to support overrides 1.0
*
* This allows users to override the default ReviewsAndRatings section present in the Headless CMS
*/
export const OverriddenDefaultReviewsAndRatings = getOverriddenSection({
...(overridePlugin as SectionOverrideDefinitionV1<'ReviewsAndRatings'>),
...(override as SectionOverrideDefinitionV1<'ReviewsAndRatings'>),
Section: ReviewsAndRatings,
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useMemo } from 'react'

import ReviewsAndRatings from '../../ui/ReviewsAndRatings'
import styles from '../ReviewsAndRatings/section.module.scss'
import Section from '../Section'
import { ReviewsAndRatingsDefaultComponents } from './DefaultComponents'
import { getOverridableSection } from '../../../sdk/overrides/getOverriddenSection'

interface Props {
title: string
}
const ReviewsAndRatingsSection = ({ title }: Props) => {
return (
<Section
id="reviews-and-ratings"
className={`${styles.section} section-reviews-and-ratings layout__section`}
>
<ReviewsAndRatings title={title} />
</Section>
)
}

const OverridableReviewsAndRatings = getOverridableSection<
typeof ReviewsAndRatingsSection
>(
'ReviewsAndRatings',
ReviewsAndRatingsSection,
ReviewsAndRatingsDefaultComponents
)

export default OverridableReviewsAndRatings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './ReviewsAndRatings'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: Rename this file to index.ts

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@layer components {
.section {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎗️
Revisit this after styles are added and components are imported correctly.

// TODO: Ajustar esses componentes para a nova section ReviewsAndRatings
// @import '@faststore/ui/src/components/atoms/Ratings/styles';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export type ReviewsAndRatingsProps = {
title: string
}

function ReviewsAndRatings({ title, ...otherProps }: ReviewsAndRatingsProps) {
return (
<>
<h2 className="text__title-section layout__content">{title}</h2>
</>
)
}

export default ReviewsAndRatings
2 changes: 2 additions & 0 deletions packages/core/src/components/ui/ReviewsAndRatings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './ReviewsAndRatings'
export type { ReviewsAndRatingsProps } from './ReviewsAndRatings'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This is an example of how it can be used on the starter.

import type { SectionOverride } from 'src/typings/overrides'

const SECTION = 'ReviewsAndRatings' as const

const override: SectionOverride = {
section: SECTION,
}

export { override }
4 changes: 3 additions & 1 deletion packages/core/src/pages/[slug]/p.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isNotFoundError } from '@faststore/api'
import type { Locator } from '@vtex/client-cms'
import type { Locator, Section } from '@vtex/client-cms'
import deepmerge from 'deepmerge'
import type { GetStaticPaths, GetStaticProps } from 'next'
import { BreadcrumbJsonLd, NextSeo, ProductJsonLd } from 'next-seo'
Expand All @@ -17,6 +17,7 @@ import BannerNewsletter from 'src/components/sections/BannerNewsletter/BannerNew
import { OverriddenDefaultBannerText as BannerText } from 'src/components/sections/BannerText/OverriddenDefaultBannerText'
import { OverriddenDefaultBreadcrumb as Breadcrumb } from 'src/components/sections/Breadcrumb/OverriddenDefaultBreadcrumb'
import { OverriddenDefaultCrossSellingShelf as CrossSellingShelf } from 'src/components/sections/CrossSellingShelf/OverriddenDefaultCrossSellingShelf'
import { OverriddenDefaultReviewsAndRatings as ReviewsAndRatings } from 'src/components/sections/ReviewsAndRatings/OverriddenDefaultReviewsAndRatings'
import { OverriddenDefaultHero as Hero } from 'src/components/sections/Hero/OverriddenDefaultHero'
import { OverriddenDefaultNewsletter as Newsletter } from 'src/components/sections/Newsletter/OverriddenDefaultNewsletter'
import { OverriddenDefaultProductDetails as ProductDetails } from 'src/components/sections/ProductDetails/OverriddenDefaultProductDetails'
Expand Down Expand Up @@ -59,6 +60,7 @@ const COMPONENTS: Record<string, ComponentType<any>> = {
ProductShelf,
ProductTiles,
CrossSellingShelf,
ReviewsAndRatings,
...PLUGINS_COMPONENTS,
...CUSTOM_COMPONENTS,
}
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/plugins/overrides/ReviewsAndRatings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is an example of how it can be used on the plugins.

export { override } from 'src/customizations/src/components/overrides/ReviewsAndRatings'
6 changes: 6 additions & 0 deletions packages/core/src/typings/overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import type Alert from '../components/sections/Alert'
import type Breadcrumb from '../components/sections/Breadcrumb'
import type BannerText from '../components/sections/BannerText'
import type CrossSellingShelf from '../components/sections/CrossSellingShelf'
import type ReviewsAndRatings from '../components/sections/ReviewsAndRatings'
import type EmptyState from '../components/sections/EmptyState'
import type Hero from '../components/sections/Hero'
import type ProductShelf from '../components/sections/ProductShelf'
Expand Down Expand Up @@ -356,6 +357,11 @@ export type SectionsOverrides = {
>
}
}
ReviewsAndRatings: {
Section: typeof ReviewsAndRatings
// TODO: Add components
components: {}
}
RegionBar: {
Section: typeof RegionBar
components: {
Expand Down
Loading