Skip to content

Commit

Permalink
feat: passing product to add review modal
Browse files Browse the repository at this point in the history
  • Loading branch information
artursantiago committed Feb 27, 2025
1 parent e76f63c commit e3f9382
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { useUI } from '@faststore/components'
import type { AddReviewModalProps } from 'src/components/reviews/AddReviewModal/AddReviewModal'
import { useOverrideComponents } from 'src/sdk/overrides/OverrideContext'
import { usePDP } from 'src/sdk/overrides/PageProvider'

export type ReviewsAndRatingsProps = {
title: string
addReviewModal: {
title: string
closeButtonAriaLabel: string
cancelButtonLabel: string
submitButtonLabel: string
}
addReviewModal: Omit<AddReviewModalProps, 'product'>
}

function ReviewsAndRatings({ title, addReviewModal }: ReviewsAndRatingsProps) {
const { AddReviewModalButton, __experimentalAddReviewModal: AddReviewModal } =
useOverrideComponents<'ReviewsAndRatings'>()
const { openAddReviewModal, addReviewModal: displayAddReviewModal } = useUI()
const context = usePDP()
const { product, isValidating } = context.data

return (
<>
Expand All @@ -30,8 +29,15 @@ function ReviewsAndRatings({ title, addReviewModal }: ReviewsAndRatingsProps) {
Add a review
</AddReviewModalButton.Component>

{displayAddReviewModal && (
<AddReviewModal.Component {...addReviewModal} />
{displayAddReviewModal && !isValidating && (
<AddReviewModal.Component
{...addReviewModal}
product={{
id: product.id,
name: product.name,
image: product.image[0],
}}
/>
)}
</>
)
Expand Down

0 comments on commit e3f9382

Please sign in to comment.