From 57da755ea15024f627549c92ecf1736eff63efa3 Mon Sep 17 00:00:00 2001 From: Kirill Date: Thu, 21 May 2026 21:10:49 +0500 Subject: [PATCH] feat: real user avatars in reviews, conditional product link --- client/src/entities/review/api/reviews-api.ts | 14 ++++++- .../product-review/ui/ProductReviewsList.tsx | 8 +++- .../widgets/reviews-block/ui/ReviewsBlock.tsx | 40 +++++++++++-------- server/src/routes/api/public-reviews.js | 20 +++++++--- 4 files changed, 57 insertions(+), 25 deletions(-) diff --git a/client/src/entities/review/api/reviews-api.ts b/client/src/entities/review/api/reviews-api.ts index 13bcc6b..584198e 100644 --- a/client/src/entities/review/api/reviews-api.ts +++ b/client/src/entities/review/api/reviews-api.ts @@ -26,8 +26,15 @@ export type PublicReviewFeedItem = { imageUrl: string | null createdAt: string authorDisplay: string - productId: string - productTitle: string + authorAvatar?: string | null + authorAvatarType?: string | null + authorAvatarStyle?: string | null + product: { + id: string + title: string + published: boolean + slug: string + } } export type PublicReviewsLatestResponse = { @@ -48,6 +55,9 @@ export type PublicProductReviewItem = { imageUrl: string | null createdAt: string authorDisplay: string + authorAvatar?: string | null + authorAvatarType?: string | null + authorAvatarStyle?: string | null } export type PublicProductReviewsResponse = { diff --git a/client/src/features/product-review/ui/ProductReviewsList.tsx b/client/src/features/product-review/ui/ProductReviewsList.tsx index 8a0ac36..ed03e3d 100644 --- a/client/src/features/product-review/ui/ProductReviewsList.tsx +++ b/client/src/features/product-review/ui/ProductReviewsList.tsx @@ -19,7 +19,13 @@ function ReviewItem({ rv }: { rv: PublicProductReviewItem }) { - + {rv.authorDisplay} diff --git a/client/src/widgets/reviews-block/ui/ReviewsBlock.tsx b/client/src/widgets/reviews-block/ui/ReviewsBlock.tsx index f392849..71ff824 100644 --- a/client/src/widgets/reviews-block/ui/ReviewsBlock.tsx +++ b/client/src/widgets/reviews-block/ui/ReviewsBlock.tsx @@ -103,9 +103,9 @@ export function ReviewsBlock() { @@ -122,20 +122,26 @@ export function ReviewsBlock() { {formatReviewDate(r.createdAt)} - - {r.productTitle} - + {r.product.published ? ( + + {r.product.title} + + ) : ( + + {r.product.title} + + )} diff --git a/server/src/routes/api/public-reviews.js b/server/src/routes/api/public-reviews.js index ef535b2..a9d86fe 100644 --- a/server/src/routes/api/public-reviews.js +++ b/server/src/routes/api/public-reviews.js @@ -40,8 +40,8 @@ export async function registerPublicReviewRoutes(fastify) { const rows = await prisma.review.findMany({ where: { status: 'approved', product: { published: true } }, include: { - user: { select: { email: true, displayName: true } }, - product: { select: { id: true, title: true } }, + user: { select: { email: true, displayName: true, avatar: true, avatarType: true, avatarStyle: true } }, + product: { select: { id: true, title: true, published: true, slug: true } }, }, orderBy: { createdAt: 'desc' }, take, @@ -54,8 +54,15 @@ export async function registerPublicReviewRoutes(fastify) { imageUrl: r.imageUrl, createdAt: r.createdAt, authorDisplay: publicReviewAuthorDisplay(r.user), - productId: r.productId, - productTitle: r.product?.title ?? '', + authorAvatar: r.user?.avatar ?? null, + authorAvatarType: r.user?.avatarType ?? null, + authorAvatarStyle: r.user?.avatarStyle ?? null, + product: { + id: r.product?.id ?? r.productId, + title: r.product?.title ?? '', + published: r.product?.published ?? false, + slug: r.product?.slug ?? '', + }, })) return { items } @@ -80,7 +87,7 @@ export async function registerPublicReviewRoutes(fastify) { const total = await prisma.review.count({ where }) const rawItems = await prisma.review.findMany({ where, - include: { user: { select: { email: true, displayName: true } } }, + include: { user: { select: { email: true, displayName: true, avatar: true, avatarType: true, avatarStyle: true } } }, orderBy: { createdAt: 'desc' }, skip: (page - 1) * pageSize, take: pageSize, @@ -93,6 +100,9 @@ export async function registerPublicReviewRoutes(fastify) { imageUrl: r.imageUrl, createdAt: r.createdAt, authorDisplay: publicReviewAuthorDisplay(r.user), + authorAvatar: r.user?.avatar ?? null, + authorAvatarType: r.user?.avatarType ?? null, + authorAvatarStyle: r.user?.avatarStyle ?? null, })) return { items, total, page, pageSize }