Skip to content

Commit 7927d26

Browse files
authored
refactor(reviews): refactor ReviewForm for more flexible rendering (#2753)
1 parent 44f6bc0 commit 7927d26

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

.changeset/metal-chicken-share.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bigcommerce/catalyst-core": minor
3+
---
4+
5+
Refactor the `ReviewForm` to accept `trigger` prop instead of `formButtonLabel` for flexible rendering.

core/vibes/soul/sections/reviews/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Stream, Streamable } from '@/vibes/soul/lib/streamable';
2+
import { Button } from '@/vibes/soul/primitives/button';
23
import { CursorPagination, CursorPaginationInfo } from '@/vibes/soul/primitives/cursor-pagination';
34
import { Rating } from '@/vibes/soul/primitives/rating';
45
import { StickySidebarLayout } from '@/vibes/soul/sections/sticky-sidebar-layout';
@@ -67,7 +68,6 @@ export function Reviews({
6768
return (
6869
<ReviewsEmptyState
6970
action={action}
70-
formButtonLabel={formButtonLabel}
7171
formEmailLabel={formEmailLabel}
7272
formModalTitle={formModalTitle}
7373
formNameLabel={formNameLabel}
@@ -124,7 +124,6 @@ export function Reviews({
124124
</Stream>
125125
<ReviewForm
126126
action={action}
127-
formButtonLabel={formButtonLabel}
128127
formEmailLabel={formEmailLabel}
129128
formModalTitle={formModalTitle}
130129
formNameLabel={formNameLabel}
@@ -136,6 +135,11 @@ export function Reviews({
136135
streamableImages={streamableImages}
137136
streamableProduct={streamableProduct}
138137
streamableUser={streamableUser}
138+
trigger={
139+
<Button className="mx-auto mt-8" size="small" variant="tertiary">
140+
{formButtonLabel}
141+
</Button>
142+
}
139143
/>
140144
</>
141145
}
@@ -225,7 +229,6 @@ export function ReviewsEmptyState({
225229
<p className="text-center">{message}</p>
226230
<ReviewForm
227231
action={action}
228-
formButtonLabel={formButtonLabel}
229232
formEmailLabel={formEmailLabel}
230233
formModalTitle={formModalTitle}
231234
formNameLabel={formNameLabel}
@@ -237,6 +240,11 @@ export function ReviewsEmptyState({
237240
streamableImages={streamableImages}
238241
streamableProduct={streamableProduct}
239242
streamableUser={streamableUser}
243+
trigger={
244+
<Button className="mx-auto mt-8" size="small" variant="tertiary">
245+
{formButtonLabel}
246+
</Button>
247+
}
240248
/>
241249
</div>
242250
</StickySidebarLayout>

core/vibes/soul/sections/reviews/review-form.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type SubmitReviewAction = Action<
2727
interface Props {
2828
productId: number;
2929
action: SubmitReviewAction;
30-
formButtonLabel?: string;
30+
trigger: React.ReactNode;
3131
formModalTitle?: string;
3232
formSubmitLabel?: string;
3333
formRatingLabel?: string;
@@ -43,7 +43,7 @@ interface Props {
4343
export const ReviewForm = ({
4444
productId,
4545
action,
46-
formButtonLabel = 'Write a review',
46+
trigger,
4747
formModalTitle = 'Write a review',
4848
formSubmitLabel = 'Submit',
4949
formRatingLabel = 'Rating',
@@ -107,11 +107,7 @@ export const ReviewForm = ({
107107
isOpen={isOpen}
108108
setOpen={setIsOpen}
109109
title={formModalTitle}
110-
trigger={
111-
<Button className="mx-auto mt-8" size="small" variant="tertiary">
112-
{formButtonLabel}
113-
</Button>
114-
}
110+
trigger={trigger}
115111
>
116112
<div className="flex flex-col gap-6 md:flex-row md:gap-8">
117113
<div className="shrink-0 md:w-48">

0 commit comments

Comments
 (0)