Skip to content

feat: reviews and ratings - #2676

Open
Guilera wants to merge 24 commits into
devfrom
feat/reviews-and-ratings
Open

Guilera wants to merge 24 commits into
devfrom
feat/reviews-and-ratings

Conversation

@Guilera

@Guilera Guilera commented Feb 6, 2025 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

This is a feature branch for Reviews & Ratings

References

JIRA EPIC
API Doc
FIGMA

🔗 Related Package PRs

API

FRONT

Preview

🧪 How to Test

To try out the new reviews and ratings feature, go to the preview above.
You can now view and test the reviews components without being logged in to Starter. However, if you want to test creating a review, you will need to be logged in to complete it successfully.
You will need to log in using the Preview link. However, the authentication service does not return you to the original page once you have logged in.
We need to manually retrieve the authentication cookie and add it to the preview.
To retrieve the authentication cookie:

  • Open DevTools (F12 or right click > Inspect Item).
  • Go to the Application tab.
  • Go to Storage > Cookies.
  • Locate the VtexIdclientAutCookie_storeframework cookie and copy its name and value.
  • Add the cookie to the preview:
  • Go to the Branch Preview.
  • Open DevTools again and go to Application > Cookies.
  • Create a new cookie using the name and value you copied earlier.
  • Refresh the page.

@Guilera Guilera added the enhancement New feature or request label Feb 6, 2025
@codesandbox-ci

codesandbox-ci Bot commented Feb 6, 2025 •

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

This was referenced Feb 13, 2025
@Guilera
Guilera force-pushed the feat/reviews-and-ratings branch 2 times, most recently from 9c2cebb to 736e0f8 Compare February 18, 2025 19:49
Guilera and others added 7 commits February 19, 2025 14:34
## What's the purpose of this pull request?

To add the Reviews & Ratings API integration through commerce client

## How it works?

Adds 3 new calls to the client:
- client.commerce.rating (retrieves rating information for a specific
product)
- client.commerce.reviews.list (retrieves all reviews for a specific
product)
- client.commerce.reviews.create (creates a new review for a specific
product)

## How to test it?

Creates a `.ts` file on the root folder of the project and adds the
following code:
```typescript
import { getContextFactory, Options } from "./packages/api/src/platforms/vtex";

const apiOptions = {
  platform: 'vtex',
  account: 'storeframework',
  locale: 'en-US',
  environment: 'vtexcommercestable',
  channel: '{"salesChannel":"1"}',
  showSponsored: false,
} as Options

const apiCtx = getContextFactory(apiOptions)

const commerceApiClient = apiCtx({}).clients.commerce
```

After that you can use the `commerceApiClient` to call the new methods.

To run the file locally use the following command:
```bash
npx tsx 
```

## References

[JIRA Task: SFS-2092](https://vtex-dev.atlassian.net/browse/SFS-2092)
[Reviews & Ratings API
Doc](https://developers.vtex.com/docs/api-reference/reviews-and-ratings-api#overview)

## Checklist

**PR Description**

- [ ] Added Rating types
- [ ] Added Reviews types
- [ ] Incremented ProductSearchReviewResult
- [ ] Created adapatObject function on `utils`
- [ ] Created camelToSnakeCase function on `utils`
## What's the purpose of this pull request?

To add reviews query resolver on graphQL

## How it works?

It defines a few new types and adds a new query resolver called:
`reviews` wich retrieves an array of reviews for a specific product.

For input we have:
- productId (`required`)
- after and first for pagination, (both are `optional`)
- sort (`optional`)
- rating (`optional`)(for filtering)

## How to test it?

run the api graphql server locally with the following command:
```bash
yarn dev:server
```
and make a query call

## References

[JIRA TASK: SFS-2094](https://vtex-dev.atlassian.net/browse/SFS-2094)


![image](https://github.com/user-attachments/assets/d07547af-329e-4dbe-8b83-75694ec18fbc)

![image](https://github.com/user-attachments/assets/f9bcef6d-359e-464e-893a-74f1ffc06464)

## Checklist

<em>You may erase this after checking them all 😉</em>

**PR Description**

- [ ] Adds graphQL `Reviews` types
- [ ] Creates a new query resolver for `Reviews`
>⚠️ THIS PR DEPENDS ON
[PR#2647](#2647) ⚠️

## What's the purpose of this pull request?

To add a reviews mutation resolver on graphQL for allowing a new review
to be created

## How it works?

It defines a few new types and adds a new mutation resolver called:
`createProductReview`

## How to test it?

run the api graphql server locally with the following command:
```bash
yarn dev:server
```
and make a query call

## References

[JIRA TASK: SFS-2095](https://vtex-dev.atlassian.net/browse/SFS-2095)
[API Reviews
Docs](https://developers.vtex.com/docs/api-reference/reviews-and-ratings-api#post-/reviews-and-ratings/api/review)

## Checklist

<em>You may erase this after checking them all 😉</em>

**PR Description**

- [ ] Adds graphQL types
- [ ] Creates a new mutation resolver for `Reviews`
## What's the purpose of this pull request?

To add product rating resolvers on graphQL

## How it works?

It defines a new type called: `StoreProductRating` and increments the
query resolver for `product` and for `searchResult`

It was necessary to adapt the `EnhancedSku` type and also to adds a
rating callback to the searchResult's promise resolution

## How to test it?

run the api graphql server locally with the following command:
```bash
yarn dev:server
```
and make a query call

## References

[JIRA Task: SFS-2093](https://vtex-dev.atlassian.net/browse/SFS-2093)

## Checklist

<em>You may erase this after checking them all 😉</em>

**PR Description**

- [ ] Adds graphQL Rating type
- [ ] Increments `product` resolver
- [ ] Increments `searchResult` resolver
## What's the purpose of this pull request?

Establish the initial structure for the Review & Ratings section,
enabling new components to branch from this foundation, thereby
facilitating their testing and preview.

## How it works?

- **Directory Creation**: A new directory has been created at
`packages/core/src/components/sections/ReviewAndRatings`, following the
Overridable section structure.

- **Support Files**: Files have been added to
`packages/core/src/components/plugins/overrides` and
`packages/core/src/components/customizations/src/components` to support
overrides.

- **Product Page Integration**: The section has been integrated into the
product page rendering component located at
`packages/core/src/pages/[slug]/p.tsx`.

- **CMS Configuration**: An entry for the Review and Ratings section has
been added to the CMS JSON file at
`packages/core/cms/faststore/sections.json`. Currently, only a `title`
property is included; additional properties will be incorporated as new
components are developed.

<!--- Tell us the role of the new feature, or component, in its context.
Provide details about what you have implemented and screenshots if
applicable. --->

## How to test it

You can access the preview link and open any pdp. It already should be
able to show the reviews sections with the title `Reviews`.
If the title doesn't appear you can run `yarn cms-sync` in the
`start.store`
[branch](https://github.com/vtex-sites/starter.store/pull/686)

<!--- Describe the steps with bullet points. Is there any external link
that can be used to better test it or an example? --->

### Starters Deploy Preview


[Preview](https://starter-git-feat-preview-review-ratings-section-vtex.vercel.app/)

<!--- Add a link to a deploy preview from `starter.store` with this
branch being used. --->

<!--- Tip: You can get an installable version of this branch from the
CodeSandbox generated when this PR is created. --->


## References

[Jira Task: SFS-2084](https://vtex-dev.atlassian.net/browse/SFS-2084)
## What's the purpose of this pull request?

To add rating stars to existing components:
- `<ProductCardContent/>`
- `<ProductTitle/>`

## How it works?

If the feature flag for reviews and ratings, defined at
`discovery.config`, it's turned on, then everywhere a `<ProductCard/>`
is used then it will display the product star rating

## How to test it?


[preview](https://starter-git-feat-basic-rating-display-vtex.vercel.app/)

## References

[JIRA TASK: SFS-2063](https://vtex-dev.atlassian.net/browse/SFS-2063)
[JIRA TASK: SFS-2065](https://vtex-dev.atlassian.net/browse/SFS-2065)


![image](https://github.com/user-attachments/assets/379da3f2-22cb-4e86-a3ac-3cf049fb0c0e)

![image](https://github.com/user-attachments/assets/05df5d00-6a78-44b1-bf59-6b8f46ef4c4d)

![image](https://github.com/user-attachments/assets/721c3121-8382-427f-bb2a-bfb5adb091ba)

![image](https://github.com/user-attachments/assets/85875b3a-53d6-4a0a-bbd2-9e28826fb227)

## Checklist

<em>You may erase this after checking them all 😉</em>

**PR Description**

- [ ] Displays rating at `Just Arrived`
- [ ] Displays rating at `Most Wanted`
- [ ] Displays rating at `Deals & Promotions`
- [ ] Displays rating at `Product Details`
- [ ] Displays rating at `Product Gallery`
@Guilera
Guilera force-pushed the feat/reviews-and-ratings branch from cc15cdd to 33db057 Compare February 19, 2025 17:34
Guilera and others added 2 commits February 20, 2025 10:12
## What's the purpose of this pull request?

To retrieves the rating distribution

## How it works?

- increments the api client to retrieves the rating distribution
- improves graphQL resolvers with rating distribution

>[!IMPORTANT]
> The percentage distribution must be in integers.
> Here’s the issue: The original percentages might not add up exactly to
100% because, when rounding, small errors can accumulate.
>For example, if you have 27.5% and round it to 28%, you’ve added 0.5%
more than the actual value. If you repeat this rounding with multiple
percentages, you may end up with a total that’s slightly over or under
100%.
>If the sum of the percentages is not exactly 100%, the best approach is
to adjust the value of the largest percentage
>
>If the sum is 99%: Distribute the remaining 1% to the most frequent
score or to the higher scores
>
>If the sum is 101%: Reduce the largest percentage by 1%
>
>This process ensures that the sum of the percentages is always 100%,
keeping the distribution as realistic as possible."

## References

[FEATURE BRANCH](#2676)
[JIRA SFS-2148](https://vtex-dev.atlassian.net/browse/SFS-2148)
## What's the purpose of this pull request?

- This pull request adds the new molecule ReviewCard component. 

## How does it work?

- The ReviewCard will display the following information:

  - User's name
  - Verified user (boolean)
  - Review date
  - Review title and text
  - "Read more" and "Read less" options
- Tooltip (displayed only for verified users when hovering over the
verified icon next to the name)
 
- The card must be **responsive** and rearrange itself for both desktop
and mobile/tablet views.
- Compose components were utilized to create the **ReviewAuthor** and
**ReviewDate** components.
- This component will be used in the listing of reviews for a product in
the new **Reviews and Ratings** section.

## How to test it?

<!--- Describe the steps with bullet points. Is there any external link
that can be used to better test it or an example? --->

### Starters Deploy Preview


[Preview](https://starter-git-feat-add-review-card-custom-section-vtex.vercel.app/review-and-ratings-playground)

<!--- Add a link to a deploy preview from `starter.store` with this
branch being used. --->

<!--- Tip: You can get an installable version of this branch from the
CodeSandbox generated when this PR is created. --->

## References

[JIRA TASK: SFS-2071](https://vtex-dev.atlassian.net/browse/SFS-2071)


[Figma](https://www.figma.com/design/YXU6IX2htN2yg7udpCumZv/Reviews-%26-Ratings?node-id=131-64429&t=0rv1XYm6XsgBeDwA-4)


![image](https://github.com/user-attachments/assets/3cbab6a6-7d9a-424b-96e5-91605bd26a17)


![image](https://github.com/user-attachments/assets/3c0b4c03-c19f-415e-a277-ad35c148f1eb)

---------

Co-authored-by: Fanny Chien <[email protected]>
Co-authored-by: Pedro Soares <[email protected]>
@@ -0,0 +1,143 @@
import React, { forwardRef, useEffect, useRef, useState } from 'react'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎗️ ask for doc request when merging the review and rating feature.

## What's the purpose of this pull request?

**Adds the number of reviews** next to the **Rating** component in the
**ProductTitle**. The review count, as well as the rating, should only
be visible if the corresponding flag in the **discovery.config** is
enabled in the code.

## How it works?

The following props have been added to **ProductTitle**:

- **reviewsCount?**: The amount of reviews for the product.
- **reviewsSectionId?**: The ID of the reviews section to link to.
- **noReviewsText?**: Default text for "No reviews yet."
- **reviewsCountText?**: Default text for "X reviews."

The review count text should be a link to the reviews section, which
will be located further down on the product page. This link will receive
the section ID through the **reviewsSectionId** prop. The labels for the
text can also be customized via props, but by default, they will be "No
reviews yet" and "X reviews."

## How to test it?

You can access the preview link and open any pdp. It already should be
able to show the reviews count for the product.
If the count label don't appear you can run `yarn cms-sync` in the
`start.store`
[branch](https://github.com/vtex-sites/starter.store/pull/685)

<!--- Describe the steps with bullet points. Is there any external link
that can be used to better test it or an example? --->

### Starters Deploy Preview


[Preview](https://starter-git-feat-preview-product-title-count-vtex.vercel.app/)

<!--- Add a link to a deploy preview from `starter.store` with this
branch being used. --->

<!--- Tip: You can get an installable version of this branch from the
CodeSandbox generated when this PR is created. --->

## References

[JIRA TASK: SFS-2064](https://vtex-dev.atlassian.net/browse/SFS-2064)


[Figma](https://www.figma.com/design/YXU6IX2htN2yg7udpCumZv/Reviews-%26-Ratings?node-id=130-32961&t=sKkz60J8JEjxL8m4-4)


![image](https://github.com/user-attachments/assets/b3828116-34ee-49fe-abf4-d7478c18b725)

![image](https://github.com/user-attachments/assets/3d6b3c4a-11db-4b40-911e-171f076b676a)

---------

Co-authored-by: gutchenzo <[email protected]>
Co-authored-by: Larícia Mota <[email protected]>
Co-authored-by: Fanny Chien <[email protected]>
## What's the purpose of this pull request?

To add the Rating Summary component

## How it works?

The component is responsible for:
- display the current average rating of the product
- display the number of reviews of the product
- display the rating distribution of the product
- to have a button to open the modal to write a review (current not
integrated, it's just emit an alert. It's depends on another task)

>[!IMPORTANT]
> If the product has no reviews, the component should display a message
saying that there are no reviews yet.
Both the text from the button and the text from number of reviews
changes when there isn't any review yet.

>[!IMPORTANT]
> Plural and singular cases for the text label of the rating counter
must be handled

> [!IMPORTANT]
> The component shouldn't be displayed if the product has no reviews and
the user is not on desktop

### Starters Deploy Preview

[PREVIEW](https://starter-git-feat-rating-summary-vtex.vercel.app/)

## References

[FEATURE BRANCH](#2676)
[JIRA SFS-2166](https://vtex-dev.atlassian.net/browse/SFS-2166)
[JIRA SFS-2167](https://vtex-dev.atlassian.net/browse/SFS-2167)
[JIRA SFS-2069](https://vtex-dev.atlassian.net/browse/SFS-2069)
artursantiago pushed a commit that referenced this pull request Mar 11, 2025
## What's the purpose of this pull request?

To add the Rating Summary component

## How it works?

The component is responsible for:
- display the current average rating of the product
- display the number of reviews of the product
- display the rating distribution of the product
- to have a button to open the modal to write a review (current not
integrated, it's just emit an alert. It's depends on another task)

>[!IMPORTANT]
> If the product has no reviews, the component should display a message
saying that there are no reviews yet.
Both the text from the button and the text from number of reviews
changes when there isn't any review yet.

>[!IMPORTANT]
> Plural and singular cases for the text label of the rating counter
must be handled

> [!IMPORTANT]
> The component shouldn't be displayed if the product has no reviews and
the user is not on desktop

### Starters Deploy Preview

[PREVIEW](https://starter-git-feat-rating-summary-vtex.vercel.app/)

## References

[FEATURE BRANCH](#2676)
[JIRA SFS-2166](https://vtex-dev.atlassian.net/browse/SFS-2166)
[JIRA SFS-2167](https://vtex-dev.atlassian.net/browse/SFS-2167)
[JIRA SFS-2069](https://vtex-dev.atlassian.net/browse/SFS-2069)
pedromtec pushed a commit that referenced this pull request Mar 11, 2025
## What's the purpose of this pull request?

To retrieves the rating distribution

## How it works?

- increments the api client to retrieves the rating distribution
- improves graphQL resolvers with rating distribution

>[!IMPORTANT]
> The percentage distribution must be in integers.
> Here’s the issue: The original percentages might not add up exactly to
100% because, when rounding, small errors can accumulate.
>For example, if you have 27.5% and round it to 28%, you’ve added 0.5%
more than the actual value. If you repeat this rounding with multiple
percentages, you may end up with a total that’s slightly over or under
100%.
>If the sum of the percentages is not exactly 100%, the best approach is
to adjust the value of the largest percentage
>
>If the sum is 99%: Distribute the remaining 1% to the most frequent
score or to the higher scores
>
>If the sum is 101%: Reduce the largest percentage by 1%
>
>This process ensures that the sum of the percentages is always 100%,
keeping the distribution as realistic as possible."

## References

[FEATURE BRANCH](#2676)
[JIRA SFS-2148](https://vtex-dev.atlassian.net/browse/SFS-2148)
artursantiago and others added 3 commits March 11, 2025 19:57
## What's the purpose of this pull request?

This pull request includes some changes to the `RatingSummary` component
and its integration within the `ReviewsAndRatings` section, like adding
a callback for the create review button, dynamically importing the
`RatingSummary` component, and updating the `ReviewsAndRatings` section
to use the new properties and overrides.

## How it works?

Enhancements to `RatingSummary` component:

* Added `onCreateReviewClick` callback property to `RatingSummaryProps`
to handle create review button clicks.
[[1]](diffhunk://#diff-3842b6542c4617b9089bcfe95aae46869139ddb93e8dcd66334f2e63bea0f669R43-R46)
[[2]](diffhunk://#diff-3842b6542c4617b9089bcfe95aae46869139ddb93e8dcd66334f2e63bea0f669R96)
[[3]](diffhunk://#diff-3842b6542c4617b9089bcfe95aae46869139ddb93e8dcd66334f2e63bea0f669L110-R115)

Integration of `RatingSummary` in `ReviewsAndRatings` section:

* Dynamically imported `RatingSummary` component in
`ReviewsAndRatingsDefaultComponents`.
* Updated `ReviewsAndRatingsSection` to pass new properties
(`ratingSummary`, `addReviewModal`) to `ReviewsAndRatings` component.
* Modified `ReviewsAndRatings` component to accept and use new
properties (`ratingSummary`, `addReviewModal`) and to use the overridden
`RatingSummary` component.
[[1]](diffhunk://#diff-3240d26fcff836d6cf071f404185609676c1bd28d2adaad248e94c88efae1e86R4-R27)
[[2]](diffhunk://#diff-3240d26fcff836d6cf071f404185609676c1bd28d2adaad248e94c88efae1e86L21-R45)

Type definitions update:

* Added `RatingSummaryProps` to overrides type definitions and updated
`SectionsOverrides` to include `RatingSummary` component.
[[1]](diffhunk://#diff-493fb3077e5ff0ebee6d765533eda8dd478cbb7ef439d8fbc526fd9bed7daa7cR45)
[[2]](diffhunk://#diff-493fb3077e5ff0ebee6d765533eda8dd478cbb7ef439d8fbc526fd9bed7daa7cL363-R369)

## How to test it?

- You can check the starter build on the starter preview of the branch
bellow that is already using this changes:
> - #2695

---------

Co-authored-by: Fanny Chien <[email protected]>
>⚠️ THIS PR DEPENDS ON:  ⚠️
> - <del>https://github.com/vtex/faststore/pull/2693</del> (PR was
closed because this one will suffice)
> - #2707
## What's the purpose of this pull request?

This PR integrates the `ReviewModal` component in the core package for
the Review and Ratings section.
The actual review form implementation will be handled in a separate PR
to be easy to review.

## How it works?

- Adding schema configuration in sections.json for `ReviewModal`
properties in the Headless CMS
- Creating a new `ReviewModal` component in
packages/core/src/components/reviews that will handle form logic
- Integrating the modal within the ReviewsAndRatings UI with a temporary
trigger button

## How to test it?

- Check `ReviewModal` structure in core package and its types
declarations
- Confirm that CMS-configured content is properly displayed

<!--- Describe the steps with bullet points. Is there any external link
that can be used to better test it or an example? --->

### Starters Deploy Preview


[Preview](https://starter-git-feat-add-review-modal-core-structure-vtex.vercel.app/)

<!--- Add a link to a deploy preview from `starter.store` with this
branch being used. --->

<!--- Tip: You can get an installable version of this branch from the
CodeSandbox generated when this PR is created. --->

## References

[FEATURE BRANCH](#2676)

[Figma](https://www.figma.com/design/YXU6IX2htN2yg7udpCumZv/Reviews-%26-Ratings?node-id=128-22351&t=zALRZSwDWuF6UrjH-4)
[SFS-2082](https://vtex-dev.atlassian.net/browse/SFS-2082)

[SFS-2082]:
https://vtex-dev.atlassian.net/browse/SFS-2082?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Fanny Chien <[email protected]>
Co-authored-by: Bruno Guilera Gutchenzo <[email protected]>
Co-authored-by: Fanny Chien <[email protected]>
artursantiago added a commit that referenced this pull request Mar 17, 2025
>⚠️ THIS PR DEPENDS ON:  ⚠️
> - <del>https://github.com/vtex/faststore/pull/2693</del> (PR was
closed because this one will suffice)
> - #2707

This PR integrates the `ReviewModal` component in the core package for
the Review and Ratings section.
The actual review form implementation will be handled in a separate PR
to be easy to review.

- Adding schema configuration in sections.json for `ReviewModal`
properties in the Headless CMS
- Creating a new `ReviewModal` component in
packages/core/src/components/reviews that will handle form logic
- Integrating the modal within the ReviewsAndRatings UI with a temporary
trigger button

- Check `ReviewModal` structure in core package and its types
declarations
- Confirm that CMS-configured content is properly displayed

<!--- Describe the steps with bullet points. Is there any external link
that can be used to better test it or an example? --->

[Preview](https://starter-git-feat-add-review-modal-core-structure-vtex.vercel.app/)

<!--- Add a link to a deploy preview from `starter.store` with this
branch being used. --->

<!--- Tip: You can get an installable version of this branch from the
CodeSandbox generated when this PR is created. --->

[FEATURE BRANCH](#2676)

[Figma](https://www.figma.com/design/YXU6IX2htN2yg7udpCumZv/Reviews-%26-Ratings?node-id=128-22351&t=zALRZSwDWuF6UrjH-4)
[SFS-2082](https://vtex-dev.atlassian.net/browse/SFS-2082)

[SFS-2082]:
https://vtex-dev.atlassian.net/browse/SFS-2082?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Fanny Chien <[email protected]>
Co-authored-by: Bruno Guilera Gutchenzo <[email protected]>
Co-authored-by: Fanny Chien <[email protected]>
artursantiago and others added 9 commits March 24, 2025 16:06
>⚠️ THIS PR DEPENDS ON:  ⚠️
> - #2707
> - #2695
> - #2700

## What's the purpose of this pull request?

This PR implements the "Add Review" form functionality within the core
package.

> [!NOTE]
> I also made some adjustments to global components (Rating, Textarea,
CheckboxField, InputField). I've included them in this PR for
efficiency, but can move them to separate PRs targeting main if
preferred.

## How it works?

- Review Modal Form:

- Adjust AddReviewModal.tsx in the core package with form handling,
validation, success states, and error management
Integrated 
    - Couldn't focus on checkbox field so I add a scrollIntoView for it
-
![image](https://github.com/user-attachments/assets/2d711653-40c0-4668-92b3-ffae2192b6bb)

  - Add new cms configuration in `sections.json`

- GraphQL Integration:

- Added CreateProductReview mutation to handle the submission of review
data
- Defined appropriate types and integrated mutation documents in GraphQL
schema
- Developed a useAddReview hook that leverages useLazyQuery for handling
review submission

- Global Component Enhancements:

- Rating: Added type="button" attribute so that it doesn't trigger
submit inside form
- CheckboxField: Implemented checkboxRef prop for better form control
and adjusted label sizing
  - Textarea: Adjust label sizing
- InputField: Fixed label positioning when error messages are present by
updating positioning calculation
-
![image](https://github.com/user-attachments/assets/fc20b766-14c0-430e-9e22-ebd63a42a892)


## How to test it?

- Navigate to any product page and click on "Write a Review"
- Test form validation by submitting without required fields
- Verify rating selection works properly
- Submit a complete review and confirm success state appears
- Check error handling:
  - Not logged in
  - Duplicate review

### Starters Deploy Preview


[Preview](https://starter-git-feat-add-review-modal-form-vtex.vercel.app/)

<!--- Add a link to a deploy preview from `starter.store` with this
branch being used. --->

<!--- Tip: You can get an installable version of this branch from the
CodeSandbox generated when this PR is created. --->

## References

[FEATURE BRANCH](#2676)

[Figma](https://www.figma.com/design/YXU6IX2htN2yg7udpCumZv/Reviews-%26-Ratings?node-id=128-22351&t=zALRZSwDWuF6UrjH-4)
[SFS-2082](https://vtex-dev.atlassian.net/browse/SFS-2082)
[SFS-2169](https://vtex-dev.atlassian.net/browse/SFS-2169)


![image](https://github.com/user-attachments/assets/bf0d9a2b-1f87-4c4f-857c-6cc897c8a989)


[SFS-2082]:
https://vtex-dev.atlassian.net/browse/SFS-2082?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
## What's the purpose of this pull request?  
This PR adds the `RatingSummarySkeleton` component.  

## How does it work?  
When `isValidating` from `usePDP` is `true`, the skeleton will be
displayed until the data is ready.

## How to test it?  
Load a product page and check if the skeleton is shown before being
replaced by the `RatingSummary` with the updated product rating data.

### Starters Deploy Preview


[Preview](https://starter-git-feat-rating-summary-skeleton-vtex.vercel.app/)

## References

[JIRA SFS-2321](https://vtex-dev.atlassian.net/browse/SFS-2321)
[FEATURE BRANCH](#2676)


![image](https://github.com/user-attachments/assets/7e6e3ddb-6e25-4b79-b8f6-7da525c1bac3)
>⚠️ THIS PR DEPENDS ON:  ⚠️
> - #2707

## What's the purpose of this pull request?

This pull request introduces the reviews filtering and sorting feature
to the `ReviewsAndRatings` section.

## How it works?

New components for filtering and sorting reviews:

*
[`packages/core/src/components/reviews/FilterProductReviews/FilterProductReviews.tsx`](diffhunk://#diff-a2b0bd1e2cdbfbcf09123edfce232730783b1b1137ade37ee1e695fb03455afbR1-R55):
Introduced `FilterProductReviews` component to filter reviews by rating.
*
[`packages/core/src/components/reviews/SortProductReviews/SortProductReviews.tsx`](diffhunk://#diff-c75acab76a9610dd3829f0261b68aff5951f22de317c4a8915c6794fe43d1fddR1-R52):
Introduced `SortProductReviews` component to sort reviews by different
criteria.

Updates to `ReviewList` and `ReviewsAndRatings` sections:

*
[`packages/core/src/components/reviews/ReviewList/ReviewList.tsx`](diffhunk://#diff-28fec2fd4196ed19b480f08cff6c7b8bdd0f40429f986ced88b7b42616366385R1-R54):
Added `ReviewList` component to display reviews with sorting and
filtering options.
*
[`packages/core/src/components/sections/ReviewsAndRatings/ReviewsAndRatings.tsx`](diffhunk://#diff-053f669e6d7dbf149a46ce88aa4b6e46b857eb4791642ae6e1ffd5f110357ee4L3-R22):
Updated `ReviewsAndRatings` section to include the new `ReviewList`
component and handle its props.
[[1]](diffhunk://#diff-053f669e6d7dbf149a46ce88aa4b6e46b857eb4791642ae6e1ffd5f110357ee4L3-R22)
[[2]](diffhunk://#diff-3240d26fcff836d6cf071f404185609676c1bd28d2adaad248e94c88efae1e86L1-R25)
[[3]](diffhunk://#diff-3240d26fcff836d6cf071f404185609676c1bd28d2adaad248e94c88efae1e86R35-R48)

Styling updates:

*
[`packages/core/src/components/sections/ReviewsAndRatings/section.module.scss`](diffhunk://#diff-2a282117ceeb7a5db54e1b28de0fdd683cd8bd3821db36a6b02a8924f058af5bR3-R47):
Updated styles to support the new review list and its header.

## How to test it?

- Open a PDP and see if the selects are displayed correctly
- Confirm that CMS-configured content is properly displayed

<!--- Describe the steps with bullet points. Is there any external link
that can be used to better test it or an example? --->

### Starters Deploy Preview


[Preview](https://starter-git-feat-filter-sort-select-cli-vtex.vercel.app/)

<!--- Add a link to a deploy preview from `starter.store` with this
branch being used. --->

<!--- Tip: You can get an installable version of this branch from the
CodeSandbox generated when this PR is created. --->

## References

[FEATURE BRANCH](#2676)

[Figma](https://www.figma.com/design/YXU6IX2htN2yg7udpCumZv/Reviews-%26-Ratings?node-id=130-32963&t=esjZ5E67A5FjirJa-4)
[SFS-2171](https://vtex-dev.atlassian.net/browse/SFS-2171)

[SFS-2171]:
https://vtex-dev.atlassian.net/browse/SFS-2171?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Fanny Chien <[email protected]>
Co-authored-by: Lucas Feijó <[email protected]>
>⚠️ THIS PR DEPENDS ON:  ⚠️
> - #2705
> - #2713

## What's the purpose of this pull request?

This PR adds the `ReviewList` with its listing functionality, loading
state, filters, and sorting.

## How it works?

- By default, the list will display 6 reviews. If more reviews are
available, a "Load More" button will appear. Clicking it will load 6
additional reviews at a time.
- If there are no reviews for the product, a message will be displayed
along with a button to open the ReviewModal.
- If a filter is applied but no reviews match the selected criteria, a
different message will appear with a button to reset the filters.

## How to test it?

- Test scenarios where reviews exist and where they do not.
- Test cases with more than 6 reviews and fewer than 6 reviews.
- Apply filters that result in no matching reviews.
- Verify that sorting works correctly.

### Starters Deploy Preview

<!--- Add a link to a deploy preview from `starter.store` with this
branch being used. --->

[Preview](https://starter-git-feat-review-list-vtex.vercel.app/)

## References

[JIRA SFS-2072](https://vtex-dev.atlassian.net/browse/SFS-2072)

[Figma](https://www.figma.com/design/YXU6IX2htN2yg7udpCumZv/Reviews-%26-Ratings?node-id=130-32955&t=5KOdS0Qx4MBzhrNq-4)
[FEATURE BRANCH](#2676)


![image](https://github.com/user-attachments/assets/87eed9ef-9250-4191-b610-33377e06b8fa)

![image](https://github.com/user-attachments/assets/84ad9ab5-1dd5-4245-8d6e-8aa2f11ddec3)

![image](https://github.com/user-attachments/assets/ec4a4715-7df4-4750-ada4-aeebcc12fbb6)

![image](https://github.com/user-attachments/assets/1fe1c002-333c-4db7-9e41-b6866023e39c)

---------

Co-authored-by: Fanny Chien <[email protected]>
## What's the purpose of this pull request?

To adapt the Reviews and Rating types to match schema.org

## How it works?

GraphQL Types and resolvers were adapted to match schema.org, and also
legacy code was removed
@artursantiago
artursantiago marked this pull request as ready for review May 29, 2025 18:53
@artursantiago
artursantiago requested a review from a team as a code owner May 29, 2025 18:53
@artursantiago
artursantiago requested review from eduardoformiga and ommeirelles and removed request for a team May 29, 2025 18:53
@matheusps
matheusps changed the base branch from main to dev October 27, 2025 17:32
@eduardoformiga
eduardoformiga force-pushed the dev branch 2 times, most recently from 6c7ef8e to 4d4ac3a Compare May 7, 2026 15:18

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants