Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change rating api #238

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/modules/booking/components/recommend/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions src/modules/booking/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ const BookingSteps = (props: BookingStepsProps) => {
<SearchCard
avatarSize="lg"
baseInfo={{
slug: substituteDoctor.slug,
displayName: substituteDoctor.title,
expertise: substituteDoctor.display_expertise,
experience: substituteDoctor.experience,
Expand Down
1 change: 1 addition & 0 deletions src/modules/bookingV2/components/recommend/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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: {
Expand Down
1 change: 1 addition & 0 deletions src/modules/bookingV3/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ const BookingSteps = (props: BookingStepsProps) => {
<SearchCard
avatarSize="lg"
baseInfo={{
slug: substituteDoctor.slug,
displayName: substituteDoctor.title,
expertise: substituteDoctor.display_expertise,
experience: substituteDoctor.experience,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const OnlineVisitPromote = () => {
<SearchCard
avatarSize="lg"
baseInfo={{
slug: substituteDoctor.slug,
displayName: substituteDoctor.title,
expertise: substituteDoctor.display_expertise,
experience: substituteDoctor.experience,
Expand Down
1 change: 1 addition & 0 deletions src/modules/profile/views/listOfDoctors/listOfDoctors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const ListOfDoctors = (props: ListOfDoctorsProps) => {
key={doctor.id}
type="doctor"
baseInfo={{
slug: doctor.slug,
displayName: doctor.title,
avatar: doctor.image,
url: doctor.url,
Expand Down
1 change: 1 addition & 0 deletions src/modules/profile/views/services/bulk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const BulkService = ({ displayName, expertises }: BulkServiceProps) => {
<SearchCard
avatarSize="lg"
baseInfo={{
slug: substituteDoctor.slug,
displayName: substituteDoctor.title,
expertise: substituteDoctor.display_expertise,
experience: substituteDoctor.experience,
Expand Down
44 changes: 36 additions & 8 deletions src/modules/search/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand All @@ -29,6 +34,7 @@ interface SearchCardProps {
isOnline?: boolean;
experience?: number;
url?: string;
slug?: string;
rate?: {
satisfaction: number;
count: number;
Expand Down Expand Up @@ -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 && !!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]);
Expand Down Expand Up @@ -110,15 +124,29 @@ export const SearchCard = (props: SearchCardProps) => {
{baseInfo?.expertise}
</Text>
)}
{type === 'doctor' && (baseInfo?.rate?.count ?? 0) > 0 && (
{type === 'doctor' && ((!shouldUseFeedbackWebService && (baseInfo?.rate?.count ?? 0) > 0) || shouldUseFeedbackWebService) && (
<div className="flex items-center !mt-2 space-s-2 text-sm md:text-base whitespace-nowrap">
<div className="flex items-center space-s-1">
<LikeIcon width={22} height={22} className="text-primary" />
<Text fontWeight="medium" className="text-primary">
{baseInfo?.rate?.satisfaction}٪
</Text>
<Text>({baseInfo?.rate?.count} نظر)</Text>
</div>
{enabled ? (
satisfactionPercentLoading || countOfFeedbacksLoading ? (
<Skeleton w="7rem" h="22px" rounded="md" />
) : !isFetchedData ? null : (
<div className="flex items-center space-s-1">
<LikeIcon width={22} height={22} className="text-primary" />
<Text fontWeight="medium" className="text-primary">
{satisfactionPercent.result.toFixed()}٪
</Text>
<Text>({countOfFeedbacks.result} نظر)</Text>
</div>
)
) : (
<div className="flex items-center space-s-1">
<LikeIcon width={22} height={22} className="text-primary" />
<Text fontWeight="medium" className="text-primary">
{baseInfo?.rate?.satisfaction}٪
</Text>
<Text>({baseInfo?.rate?.count} نظر)</Text>
</div>
)}
{baseInfo?.experience && (
<>
<Divider orientation="vertical" height={20} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export const ConsultBanner = () => {
<SearchCard
avatarSize="lg"
baseInfo={{
slug: substituteDoctor.slug,
displayName: substituteDoctor.title,
expertise: substituteDoctor.display_expertise,
experience: substituteDoctor.experience,
Expand Down
1 change: 1 addition & 0 deletions src/modules/search/hooks/useSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type Result = {
title: string;
type: 'doctor' | 'center';
url: string;
slug?: string;
view: string;
price: string;
server_id: number;
Expand Down
1 change: 1 addition & 0 deletions src/modules/search/view/result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const Result = () => {
satisfaction: item.satisfaction,
},
url: item.url,
slug: item.slug
}}
type={item.type}
details={{
Expand Down