From 41fce5d85bde373ac3651d3ac646982334e8dc0d Mon Sep 17 00:00:00 2001 From: mh_mohammadi Date: Sat, 17 Feb 2024 17:02:42 +0330 Subject: [PATCH 1/8] feat: Change rating API in result cards --- src/modules/search/components/card/card.tsx | 44 +++++++++++++++++---- src/modules/search/hooks/useSearch.ts | 1 + src/modules/search/view/result/index.tsx | 1 + 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/modules/search/components/card/card.tsx b/src/modules/search/components/card/card.tsx index c39b21af..cdeea4a2 100644 --- a/src/modules/search/components/card/card.tsx +++ b/src/modules/search/components/card/card.tsx @@ -3,6 +3,7 @@ import Button from '@/common/components/atom/button'; import Card from '@/common/components/atom/card'; import Divider from '@/common/components/atom/divider'; import Text from '@/common/components/atom/text'; +import Skeleton from '@/common/components/atom/skeleton'; import DoctorIcon from '@/common/components/icons/doctor'; import EyeIcon from '@/common/components/icons/eye'; import LikeIcon from '@/common/components/icons/like'; @@ -14,6 +15,10 @@ import getConfig from 'next/config'; import Link from 'next/link'; import { useMemo } from 'react'; import Badge, { BadgeProps } from '../badge'; +import { useFeatureIsOn } from '@growthbook/growthbook-react'; +import { useCountOfFeedbacks } from '@/common/apis/services/rate/countOfFeedbacks'; +import { useSatisfactionPercent } from '@/common/apis/services/rate/satisfactionPercent'; + const { publicRuntimeConfig } = getConfig(); interface SearchCardProps { @@ -29,6 +34,7 @@ interface SearchCardProps { isOnline?: boolean; experience?: number; url?: string; + slug?: string; rate?: { satisfaction: number; count: number; @@ -57,6 +63,14 @@ interface SearchCardProps { export const SearchCard = (props: SearchCardProps) => { const { baseInfo, details, actions, type, sendEventWhenClick, avatarSize = 'md', className, avatarPriority = false, alt } = props; + const shouldUseFeedbackWebService = useFeatureIsOn('search:use-feedback-webservice'); + const slug = baseInfo.slug ?? ''; + const enabled = shouldUseFeedbackWebService && !!baseInfo.slug; + + const { data: satisfactionPercent, isLoading: satisfactionPercentLoading } = useSatisfactionPercent({ slug }, { enabled }); + const { data: countOfFeedbacks, isLoading: countOfFeedbacksLoading } = useCountOfFeedbacks({ slug }, { enabled }); + const isFetchedData = satisfactionPercent && countOfFeedbacks && countOfFeedbacks.result > 0; + const fullName = useMemo(() => baseInfo?.displayName ?? `${baseInfo?.name} ${baseInfo?.family}`, [baseInfo]); const imageAlt = useMemo(() => `${fullName} ${baseInfo?.expertise}`, [fullName, baseInfo.expertise]); @@ -110,15 +124,29 @@ export const SearchCard = (props: SearchCardProps) => { {baseInfo?.expertise} )} - {type === 'doctor' && (baseInfo?.rate?.count ?? 0) > 0 && ( + {type === 'doctor' && ((!shouldUseFeedbackWebService && (baseInfo?.rate?.count ?? 0) > 0) || shouldUseFeedbackWebService) && (
-
- - - {baseInfo?.rate?.satisfaction}٪ - - ({baseInfo?.rate?.count} نظر) -
+ {shouldUseFeedbackWebService ? ( + satisfactionPercentLoading || countOfFeedbacksLoading ? ( + + ) : shouldUseFeedbackWebService && !isFetchedData ? null : ( +
+ + + {shouldUseFeedbackWebService ? satisfactionPercent.result.toFixed() : baseInfo?.rate?.satisfaction}٪ + + ({shouldUseFeedbackWebService ? countOfFeedbacks.result : baseInfo?.rate?.count} نظر) +
+ ) + ) : ( +
+ + + {baseInfo?.rate?.satisfaction}٪ + + ({baseInfo?.rate?.count} نظر) +
+ )} {baseInfo?.experience && ( <> diff --git a/src/modules/search/hooks/useSearch.ts b/src/modules/search/hooks/useSearch.ts index 418a28c2..f7653b97 100644 --- a/src/modules/search/hooks/useSearch.ts +++ b/src/modules/search/hooks/useSearch.ts @@ -52,6 +52,7 @@ export type Result = { title: string; type: 'doctor' | 'center'; url: string; + slug?: string; view: string; price: string; server_id: number; diff --git a/src/modules/search/view/result/index.tsx b/src/modules/search/view/result/index.tsx index 8e97b1d3..4e2420bb 100644 --- a/src/modules/search/view/result/index.tsx +++ b/src/modules/search/view/result/index.tsx @@ -85,6 +85,7 @@ export const Result = () => { satisfaction: item.satisfaction, }, url: item.url, + slug: item.slug }} type={item.type} details={{ From f4c0f30475d8b4f4e86dfbbced0f3a8a65deef84 Mon Sep 17 00:00:00 2001 From: mh_mohammadi Date: Sat, 17 Feb 2024 17:33:49 +0330 Subject: [PATCH 2/8] fix bug --- src/modules/search/components/card/card.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/search/components/card/card.tsx b/src/modules/search/components/card/card.tsx index cdeea4a2..6c1e09ab 100644 --- a/src/modules/search/components/card/card.tsx +++ b/src/modules/search/components/card/card.tsx @@ -63,9 +63,9 @@ interface SearchCardProps { export const SearchCard = (props: SearchCardProps) => { const { baseInfo, details, actions, type, sendEventWhenClick, avatarSize = 'md', className, avatarPriority = false, alt } = props; - const shouldUseFeedbackWebService = useFeatureIsOn('search:use-feedback-webservice'); + const shouldUseFeedbackWebService = !useFeatureIsOn('search:use-feedback-webservice'); const slug = baseInfo.slug ?? ''; - const enabled = shouldUseFeedbackWebService && !!baseInfo.slug; + const enabled = shouldUseFeedbackWebService && !!slug; const { data: satisfactionPercent, isLoading: satisfactionPercentLoading } = useSatisfactionPercent({ slug }, { enabled }); const { data: countOfFeedbacks, isLoading: countOfFeedbacksLoading } = useCountOfFeedbacks({ slug }, { enabled }); @@ -126,16 +126,16 @@ export const SearchCard = (props: SearchCardProps) => { )} {type === 'doctor' && ((!shouldUseFeedbackWebService && (baseInfo?.rate?.count ?? 0) > 0) || shouldUseFeedbackWebService) && (
- {shouldUseFeedbackWebService ? ( + {enabled ? ( satisfactionPercentLoading || countOfFeedbacksLoading ? ( - ) : shouldUseFeedbackWebService && !isFetchedData ? null : ( + ) : !isFetchedData ? null : (
- {shouldUseFeedbackWebService ? satisfactionPercent.result.toFixed() : baseInfo?.rate?.satisfaction}٪ + {satisfactionPercent.result.toFixed()}٪ - ({shouldUseFeedbackWebService ? countOfFeedbacks.result : baseInfo?.rate?.count} نظر) + ({countOfFeedbacks.result} نظر)
) ) : ( From 848b46402e4609c4cdd7969a928e48201987f522 Mon Sep 17 00:00:00 2001 From: mh_mohammadi Date: Sat, 17 Feb 2024 17:37:18 +0330 Subject: [PATCH 3/8] feature flag --- src/modules/search/components/card/card.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/search/components/card/card.tsx b/src/modules/search/components/card/card.tsx index 6c1e09ab..846881b1 100644 --- a/src/modules/search/components/card/card.tsx +++ b/src/modules/search/components/card/card.tsx @@ -63,7 +63,7 @@ interface SearchCardProps { export const SearchCard = (props: SearchCardProps) => { const { baseInfo, details, actions, type, sendEventWhenClick, avatarSize = 'md', className, avatarPriority = false, alt } = props; - const shouldUseFeedbackWebService = !useFeatureIsOn('search:use-feedback-webservice'); + const shouldUseFeedbackWebService = useFeatureIsOn('search:use-feedback-webservice'); const slug = baseInfo.slug ?? ''; const enabled = shouldUseFeedbackWebService && !!slug; From cef9ca9b15834e1126b8d47d57b0d9ebc24efb7a Mon Sep 17 00:00:00 2001 From: mh_mohammadi Date: Sun, 18 Feb 2024 15:46:41 +0330 Subject: [PATCH 4/8] fix: Add slug props to SearchCard component --- src/modules/booking/components/recommend/card/card.tsx | 1 + src/modules/booking/views/index.tsx | 1 + src/modules/bookingV2/components/recommend/card/card.tsx | 1 + src/modules/bookingV3/views/index.tsx | 1 + .../home/components/onlineVisitPromote/onlineVisitPromote.tsx | 1 + src/modules/profile/views/listOfDoctors/listOfDoctors.tsx | 1 + src/modules/profile/views/services/bulk.tsx | 1 + src/modules/search/components/consultBanner/consultBanner.tsx | 1 + 8 files changed, 8 insertions(+) diff --git a/src/modules/booking/components/recommend/card/card.tsx b/src/modules/booking/components/recommend/card/card.tsx index 87651340..505a34e1 100644 --- a/src/modules/booking/components/recommend/card/card.tsx +++ b/src/modules/booking/components/recommend/card/card.tsx @@ -50,6 +50,7 @@ export const RecommendCard = (props: RecommendCardProps) => { displayName: doctor.displayName, avatar: doctor.image, url: doctor.url, + slug: doctor.url.split("/")[2], expertise: doctor.displayExpertise, isVerify: !doctor.isBulk, rate: { diff --git a/src/modules/booking/views/index.tsx b/src/modules/booking/views/index.tsx index 3169e501..fffdaf96 100644 --- a/src/modules/booking/views/index.tsx +++ b/src/modules/booking/views/index.tsx @@ -859,6 +859,7 @@ const BookingSteps = (props: BookingStepsProps) => { { displayName: doctor.displayName, avatar: doctor.image, url: doctor.url, + slug: doctor.url.split("/")[2], expertise: doctor.displayExpertise, isVerify: !doctor.isBulk, rate: { diff --git a/src/modules/bookingV3/views/index.tsx b/src/modules/bookingV3/views/index.tsx index 51c6a998..65d8bfa8 100644 --- a/src/modules/bookingV3/views/index.tsx +++ b/src/modules/bookingV3/views/index.tsx @@ -298,6 +298,7 @@ const BookingSteps = (props: BookingStepsProps) => { { { key={doctor.id} type="doctor" baseInfo={{ + slug: doctor.slug, displayName: doctor.title, avatar: doctor.image, url: doctor.url, diff --git a/src/modules/profile/views/services/bulk.tsx b/src/modules/profile/views/services/bulk.tsx index f4636248..f65b34f6 100644 --- a/src/modules/profile/views/services/bulk.tsx +++ b/src/modules/profile/views/services/bulk.tsx @@ -115,6 +115,7 @@ export const BulkService = ({ displayName, expertises }: BulkServiceProps) => { { Date: Sat, 17 Feb 2024 17:02:42 +0330 Subject: [PATCH 5/8] feat: Change rating API in result cards --- src/modules/search/components/card/card.tsx | 44 +++++++++++++++++---- src/modules/search/hooks/useSearch.ts | 1 + src/modules/search/view/result/index.tsx | 1 + 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/modules/search/components/card/card.tsx b/src/modules/search/components/card/card.tsx index 167e7da5..53e34a92 100644 --- a/src/modules/search/components/card/card.tsx +++ b/src/modules/search/components/card/card.tsx @@ -3,6 +3,7 @@ import Button from '@/common/components/atom/button'; import Card from '@/common/components/atom/card'; import Divider from '@/common/components/atom/divider'; import Text from '@/common/components/atom/text'; +import Skeleton from '@/common/components/atom/skeleton'; import DoctorIcon from '@/common/components/icons/doctor'; import EyeIcon from '@/common/components/icons/eye'; import LikeIcon from '@/common/components/icons/like'; @@ -14,6 +15,10 @@ import getConfig from 'next/config'; import Link from 'next/link'; import { useMemo } from 'react'; import Badge, { BadgeProps } from '../badge'; +import { useFeatureIsOn } from '@growthbook/growthbook-react'; +import { useCountOfFeedbacks } from '@/common/apis/services/rate/countOfFeedbacks'; +import { useSatisfactionPercent } from '@/common/apis/services/rate/satisfactionPercent'; + const { publicRuntimeConfig } = getConfig(); interface SearchCardProps { @@ -29,6 +34,7 @@ interface SearchCardProps { isOnline?: boolean; experience?: number; url?: string; + slug?: string; rate?: { satisfaction: number; count: number; @@ -57,6 +63,14 @@ interface SearchCardProps { export const SearchCard = (props: SearchCardProps) => { const { baseInfo, details, actions, type, sendEventWhenClick, avatarSize = 'md', className, avatarPriority = false, alt } = props; + const shouldUseFeedbackWebService = useFeatureIsOn('search:use-feedback-webservice'); + const slug = baseInfo.slug ?? ''; + const enabled = shouldUseFeedbackWebService && !!baseInfo.slug; + + const { data: satisfactionPercent, isLoading: satisfactionPercentLoading } = useSatisfactionPercent({ slug }, { enabled }); + const { data: countOfFeedbacks, isLoading: countOfFeedbacksLoading } = useCountOfFeedbacks({ slug }, { enabled }); + const isFetchedData = satisfactionPercent && countOfFeedbacks && countOfFeedbacks.result > 0; + const fullName = useMemo(() => baseInfo?.displayName ?? `${baseInfo?.name} ${baseInfo?.family}`, [baseInfo]); const imageAlt = useMemo(() => `${fullName} ${baseInfo?.expertise}`, [fullName, baseInfo.expertise]); @@ -110,15 +124,29 @@ export const SearchCard = (props: SearchCardProps) => { {baseInfo?.expertise} )} - {type === 'doctor' && (baseInfo?.rate?.count ?? 0) > 0 && ( + {type === 'doctor' && ((!shouldUseFeedbackWebService && (baseInfo?.rate?.count ?? 0) > 0) || shouldUseFeedbackWebService) && (
-
- - - {baseInfo?.rate?.satisfaction}٪ - - ({baseInfo?.rate?.count} نظر) -
+ {shouldUseFeedbackWebService ? ( + satisfactionPercentLoading || countOfFeedbacksLoading ? ( + + ) : shouldUseFeedbackWebService && !isFetchedData ? null : ( +
+ + + {shouldUseFeedbackWebService ? satisfactionPercent.result.toFixed() : baseInfo?.rate?.satisfaction}٪ + + ({shouldUseFeedbackWebService ? countOfFeedbacks.result : baseInfo?.rate?.count} نظر) +
+ ) + ) : ( +
+ + + {baseInfo?.rate?.satisfaction}٪ + + ({baseInfo?.rate?.count} نظر) +
+ )} {baseInfo?.experience && ( <> diff --git a/src/modules/search/hooks/useSearch.ts b/src/modules/search/hooks/useSearch.ts index 418a28c2..f7653b97 100644 --- a/src/modules/search/hooks/useSearch.ts +++ b/src/modules/search/hooks/useSearch.ts @@ -52,6 +52,7 @@ export type Result = { title: string; type: 'doctor' | 'center'; url: string; + slug?: string; view: string; price: string; server_id: number; diff --git a/src/modules/search/view/result/index.tsx b/src/modules/search/view/result/index.tsx index 6ebec3ce..9aa3e6df 100644 --- a/src/modules/search/view/result/index.tsx +++ b/src/modules/search/view/result/index.tsx @@ -134,6 +134,7 @@ export const Result = () => { satisfaction: item.satisfaction, }, url: item.url, + slug: item.slug }} type={item.type} details={{ From 9748578c76111de361449b300cf286c8101df1e2 Mon Sep 17 00:00:00 2001 From: mh_mohammadi Date: Sat, 17 Feb 2024 17:33:49 +0330 Subject: [PATCH 6/8] fix bug --- src/modules/search/components/card/card.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/search/components/card/card.tsx b/src/modules/search/components/card/card.tsx index 53e34a92..bd9f4f99 100644 --- a/src/modules/search/components/card/card.tsx +++ b/src/modules/search/components/card/card.tsx @@ -63,9 +63,9 @@ interface SearchCardProps { export const SearchCard = (props: SearchCardProps) => { const { baseInfo, details, actions, type, sendEventWhenClick, avatarSize = 'md', className, avatarPriority = false, alt } = props; - const shouldUseFeedbackWebService = useFeatureIsOn('search:use-feedback-webservice'); + const shouldUseFeedbackWebService = !useFeatureIsOn('search:use-feedback-webservice'); const slug = baseInfo.slug ?? ''; - const enabled = shouldUseFeedbackWebService && !!baseInfo.slug; + const enabled = shouldUseFeedbackWebService && !!slug; const { data: satisfactionPercent, isLoading: satisfactionPercentLoading } = useSatisfactionPercent({ slug }, { enabled }); const { data: countOfFeedbacks, isLoading: countOfFeedbacksLoading } = useCountOfFeedbacks({ slug }, { enabled }); @@ -126,16 +126,16 @@ export const SearchCard = (props: SearchCardProps) => { )} {type === 'doctor' && ((!shouldUseFeedbackWebService && (baseInfo?.rate?.count ?? 0) > 0) || shouldUseFeedbackWebService) && (
- {shouldUseFeedbackWebService ? ( + {enabled ? ( satisfactionPercentLoading || countOfFeedbacksLoading ? ( - ) : shouldUseFeedbackWebService && !isFetchedData ? null : ( + ) : !isFetchedData ? null : (
- {shouldUseFeedbackWebService ? satisfactionPercent.result.toFixed() : baseInfo?.rate?.satisfaction}٪ + {satisfactionPercent.result.toFixed()}٪ - ({shouldUseFeedbackWebService ? countOfFeedbacks.result : baseInfo?.rate?.count} نظر) + ({countOfFeedbacks.result} نظر)
) ) : ( From af1dbdd3cd1ec818e79e795a73d199c5ad72dc5f Mon Sep 17 00:00:00 2001 From: mh_mohammadi Date: Sat, 17 Feb 2024 17:37:18 +0330 Subject: [PATCH 7/8] feature flag --- src/modules/search/components/card/card.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/search/components/card/card.tsx b/src/modules/search/components/card/card.tsx index bd9f4f99..3fefd58f 100644 --- a/src/modules/search/components/card/card.tsx +++ b/src/modules/search/components/card/card.tsx @@ -63,7 +63,7 @@ interface SearchCardProps { export const SearchCard = (props: SearchCardProps) => { const { baseInfo, details, actions, type, sendEventWhenClick, avatarSize = 'md', className, avatarPriority = false, alt } = props; - const shouldUseFeedbackWebService = !useFeatureIsOn('search:use-feedback-webservice'); + const shouldUseFeedbackWebService = useFeatureIsOn('search:use-feedback-webservice'); const slug = baseInfo.slug ?? ''; const enabled = shouldUseFeedbackWebService && !!slug; From 2d25aa84f4cd0238051d723061c3d41572e9df51 Mon Sep 17 00:00:00 2001 From: mh_mohammadi Date: Sun, 18 Feb 2024 15:46:41 +0330 Subject: [PATCH 8/8] fix: Add slug props to SearchCard component --- src/modules/booking/components/recommend/card/card.tsx | 1 + src/modules/booking/views/index.tsx | 1 + src/modules/bookingV2/components/recommend/card/card.tsx | 1 + src/modules/bookingV3/views/index.tsx | 1 + .../home/components/onlineVisitPromote/onlineVisitPromote.tsx | 1 + src/modules/profile/views/listOfDoctors/listOfDoctors.tsx | 1 + src/modules/profile/views/services/bulk.tsx | 1 + src/modules/search/components/consultBanner/consultBanner.tsx | 1 + 8 files changed, 8 insertions(+) diff --git a/src/modules/booking/components/recommend/card/card.tsx b/src/modules/booking/components/recommend/card/card.tsx index 87651340..505a34e1 100644 --- a/src/modules/booking/components/recommend/card/card.tsx +++ b/src/modules/booking/components/recommend/card/card.tsx @@ -50,6 +50,7 @@ export const RecommendCard = (props: RecommendCardProps) => { displayName: doctor.displayName, avatar: doctor.image, url: doctor.url, + slug: doctor.url.split("/")[2], expertise: doctor.displayExpertise, isVerify: !doctor.isBulk, rate: { diff --git a/src/modules/booking/views/index.tsx b/src/modules/booking/views/index.tsx index 3169e501..fffdaf96 100644 --- a/src/modules/booking/views/index.tsx +++ b/src/modules/booking/views/index.tsx @@ -859,6 +859,7 @@ const BookingSteps = (props: BookingStepsProps) => { { displayName: doctor.displayName, avatar: doctor.image, url: doctor.url, + slug: doctor.url.split("/")[2], expertise: doctor.displayExpertise, isVerify: !doctor.isBulk, rate: { diff --git a/src/modules/bookingV3/views/index.tsx b/src/modules/bookingV3/views/index.tsx index 51c6a998..65d8bfa8 100644 --- a/src/modules/bookingV3/views/index.tsx +++ b/src/modules/bookingV3/views/index.tsx @@ -298,6 +298,7 @@ const BookingSteps = (props: BookingStepsProps) => { { { key={doctor.id} type="doctor" baseInfo={{ + slug: doctor.slug, displayName: doctor.title, avatar: doctor.image, url: doctor.url, diff --git a/src/modules/profile/views/services/bulk.tsx b/src/modules/profile/views/services/bulk.tsx index f4636248..f65b34f6 100644 --- a/src/modules/profile/views/services/bulk.tsx +++ b/src/modules/profile/views/services/bulk.tsx @@ -115,6 +115,7 @@ export const BulkService = ({ displayName, expertises }: BulkServiceProps) => { {