Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export interface RatingSummaryProps extends HTMLAttributes<HTMLDivElement> {
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
*/
testId?: string
/**
* Callback to be called when the create review button is clicked.
*/
onCreateReviewClick?: () => void
}

const RatingSummaryHeader = ({
Expand Down Expand Up @@ -89,6 +93,7 @@ export const RatingSummary = forwardRef<HTMLDivElement, RatingSummaryProps>(
} = {},
} = {},
testId = 'fs-rating-summary',
onCreateReviewClick,
...props
},
ref
Expand All @@ -107,10 +112,7 @@ export const RatingSummary = forwardRef<HTMLDivElement, RatingSummaryProps>(
singleReviewText={ratingCounterSingleReviewText}
multipleReviewsText={ratingCounterMultipleReviewsText}
/>
<Button
variant="secondary"
onClick={() => alert('Write a review button clicked!')}
>
<Button variant="secondary" onClick={onCreateReviewClick}>
{buttonText}
</Button>
{totalCount > 0 && <RatingDistribution distribution={distribution} />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import dynamic from 'next/dynamic'

const UIRatingSummary = dynamic(() =>
/* webpackChunkName: "UIRatingSummary" */
import('@faststore/ui').then((module) => module.RatingSummary)
)

export const ReviewsAndRatingsDefaultComponents = {
// TODO: Update this with the components that will be used in ReviewsAndRatings section
// Olhar o packages/core/src/components/sections/ProductGallery/DefaultComponents.ts
// ou o packages/core/src/components/sections/ProductShelf/DefaultComponents.ts
// para se basear
RatingSummary: UIRatingSummary,
} as const
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { useMemo } from 'react'

import ReviewsAndRatings from '../../ui/ReviewsAndRatings'
import ReviewsAndRatings, {
type ReviewsAndRatingsProps,
} 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
title: ReviewsAndRatingsProps['title']
ratingSummary: ReviewsAndRatingsProps['ratingSummary']
}
const ReviewsAndRatingsSection = ({ title }: Props) => {
const ReviewsAndRatingsSection = (props: Props) => {
return (
<Section
id="reviews-and-ratings"
className={`${styles.section} section-reviews-and-ratings layout__section`}
>
<ReviewsAndRatings title={title} />
<ReviewsAndRatings {...props} />
</Section>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { RatingSummary } from '@faststore/ui'
import { usePDP } from 'src/sdk/overrides/PageProvider'
import useScreenResize from 'src/sdk/ui/useScreenResize'
import type { RatingSummaryProps } from '@faststore/components'
import { useOverrideComponents } from 'src/sdk/overrides/OverrideContext'

export type ReviewsAndRatingsProps = {
title: string
ratingSummary: {
ratingCounter: RatingSummaryProps['textLabels']['ratingCounter']
createReviewButton: RatingSummaryProps['textLabels']['createReviewButton']
}
}

function ReviewsAndRatings({ title, ...otherProps }: ReviewsAndRatingsProps) {
function ReviewsAndRatings({ title, ratingSummary }: ReviewsAndRatingsProps) {
const context = usePDP()
const { RatingSummary } = useOverrideComponents<'ReviewsAndRatings'>()
const { isDesktop } = useScreenResize()

const rating = context?.data?.product?.rating
Expand All @@ -18,7 +24,14 @@ function ReviewsAndRatings({ title, ...otherProps }: ReviewsAndRatingsProps) {
<h2 className="text__title-section layout__content">{title}</h2>
<div data-fs-content>
{(isDesktop || rating?.totalCount > 0) && (
<RatingSummary {...rating} {...otherProps} />
<RatingSummary.Component
{...RatingSummary.props}
textLabels={{ ...ratingSummary }}
// Dynamic props shouldn't be overridable
// This decision can be reviewed later if needed
{...rating}
onCreateReviewClick={() => alert('Create review')}
/>
)}
</div>
</>
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/typings/overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import type {
SKUMatrixProps,
SKUMatrixTriggerProps,
SKUMatrixSidebarProps,
RatingSummaryProps,
} from '@faststore/ui'

import type {
Expand Down Expand Up @@ -360,7 +361,12 @@ export type SectionsOverrides = {
ReviewsAndRatings: {
Section: typeof ReviewsAndRatings
// TODO: Add components
Copy link
Contributor

Choose a reason for hiding this comment

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

this is because we also need to add ReviewModal right?

components: {}
components: {
RatingSummary: ComponentOverrideDefinition<
RatingSummaryProps,
RatingSummaryProps
>
}
}
RegionBar: {
Section: typeof RegionBar
Expand Down
Loading