@@ -7,13 +7,14 @@ import { SearchParams } from 'nuqs/server';
77import { Stream , Streamable } from '@/vibes/soul/lib/streamable' ;
88import { FeaturedProductCarousel } from '@/vibes/soul/sections/featured-product-carousel' ;
99import { ProductDetail } from '@/vibes/soul/sections/product-detail' ;
10- import { getSessionCustomerAccessToken } from '~/auth' ;
10+ import { auth , getSessionCustomerAccessToken } from '~/auth' ;
1111import { pricesTransformer } from '~/data-transformers/prices-transformer' ;
1212import { productCardTransformer } from '~/data-transformers/product-card-transformer' ;
1313import { productOptionsTransformer } from '~/data-transformers/product-options-transformer' ;
1414import { getPreferredCurrencyCode } from '~/lib/currency' ;
1515
1616import { addToCart } from './_actions/add-to-cart' ;
17+ import { submitReview } from './_actions/submit-review' ;
1718import { ProductAnalyticsProvider } from './_components/product-analytics-provider' ;
1819import { ProductSchema } from './_components/product-schema' ;
1920import { ProductViewed } from './_components/product-viewed' ;
@@ -80,7 +81,8 @@ export default async function Product({ params, searchParams }: Props) {
8081
8182 const { product : baseProduct , settings } = await getProduct ( productId , customerAccessToken ) ;
8283
83- const reviewsEnabled = settings ?. reviews . enabled ?? false ;
84+ const reviewsEnabled = Boolean ( settings ?. reviews . enabled && ! settings . display . showProductRating ) ;
85+ const showRating = Boolean ( settings ?. reviews . enabled && settings . display . showProductRating ) ;
8486
8587 if ( ! baseProduct ) {
8688 return notFound ( ) ;
@@ -510,6 +512,21 @@ export default async function Product({ params, searchParams }: Props) {
510512 } ;
511513 } ) ;
512514
515+ const streamableUser = Streamable . from ( async ( ) => {
516+ const session = await auth ( ) ;
517+ const firstName = session ?. user ?. firstName ?? '' ;
518+ const lastName = session ?. user ?. lastName ?? '' ;
519+
520+ if ( ! firstName || ! lastName ) {
521+ return { email : session ?. user ?. email ?? '' , name : '' } ;
522+ }
523+
524+ const lastInitial = lastName . charAt ( 0 ) . toUpperCase ( ) ;
525+ const obfuscatedName = `${ firstName } ${ lastInitial } .` ;
526+
527+ return { email : session ?. user ?. email ?? '' , name : obfuscatedName } ;
528+ } ) ;
529+
513530 return (
514531 < >
515532 < ProductAnalyticsProvider data = { streamableAnalyticsData } >
@@ -538,6 +555,7 @@ export default async function Product({ params, searchParams }: Props) {
538555 images : streamableImages ,
539556 price : streamablePrices ,
540557 reviewsEnabled,
558+ showRating,
541559 subtitle : baseProduct . brand ?. name ,
542560 rating : baseProduct . reviewSummary . averageRating ,
543561 accordions : streameableAccordions ,
@@ -547,7 +565,9 @@ export default async function Product({ params, searchParams }: Props) {
547565 backorderDisplayData : streamableBackorderDisplayData ,
548566 } }
549567 quantityLabel = { t ( 'ProductDetails.quantity' ) }
568+ reviewFormAction = { submitReview }
550569 thumbnailLabel = { t ( 'ProductDetails.thumbnail' ) }
570+ user = { streamableUser }
551571 />
552572 </ ProductAnalyticsProvider >
553573
@@ -562,7 +582,7 @@ export default async function Product({ params, searchParams }: Props) {
562582 title = { t ( 'RelatedProducts.title' ) }
563583 />
564584
565- { reviewsEnabled && (
585+ { showRating && (
566586 < Reviews
567587 productId = { productId }
568588 searchParams = { searchParams }
0 commit comments