Skip to content

Commit

Permalink
feat: refactor code to simplify logic for showing rate option
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirhBeigi committed Oct 14, 2024
1 parent e01a919 commit ebe8f1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/common/apis/services/reviews/getReviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,37 @@ import { useQuery } from '@tanstack/react-query';
import { ServerStateKeysEnum } from '../../serverStateKeysEnum';

export interface ReviewParams {
slug: string;
sort: 'default_order' | 'created_at' | 'count_like';
slug?: string;
sort?: 'default_order' | 'created_at' | 'count_like';
search?: string;
user_id?: string;
not_recommended?: boolean;
visited?: boolean;
center_id?: string;
offset?: number;
showOnlyPositiveFeedbacks: boolean;
showOnlyPositiveFeedbacks?: boolean;
book_id?: string;
}

export const getReviews = async (params: ReviewParams) => {
const { data } = await apiGatewayClient.get(`/ravi/v1/feedbacks`, {
params: {
where: [
`(doctor_slug,eq,${params.slug})`,
params.slug && `(doctor_slug,eq,${params.slug})`,
`(reply_to_feedback_id,is,null)`,
params.search && `(description,like,${params.search})`,
params.user_id && `(user_id,eq,${params.user_id})`,
params.not_recommended && `(recommended,eq,0)`,
params.visited && `(visit_status,eq,visited)`,
params.center_id && `(center_id,eq,${params.center_id})`,
params.showOnlyPositiveFeedbacks && `(avg_rate_value,gt,3.5)`,
params.book_id && `(book_id,eq,${params.book_id})`,
]
.filter(Boolean)
.join('~and'),
limit: 10,
offset: params?.offset ?? 0,
sort: `-${params.sort}`,
...(params.sort && { sort: `-${params.sort}` }),
},
});
return data;
Expand Down
8 changes: 7 additions & 1 deletion src/modules/myTurn/components/turn/body/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useRouter } from 'next/router';
import Location from '../../location/location';
import Rate from '../../rate/rate';
import TurnDetails from '../../turnDetails';
import { useGetReview } from '@/common/apis/services/reviews/getReviews';

interface TurnBodyProps {
detailsData: Array<{ id: number; name: string; value: string | React.ReactNode }>;
Expand All @@ -30,10 +31,15 @@ export const TurnBody: React.FC<TurnBodyProps> = props => {
const { detailsData, status, feedbackUrl, location, centerType, id, centerId, doctorInfo, paymentStatus } = props;
const router = useRouter();
const { customize } = useCustomize();
const feedback = useGetReview({
book_id: id,
});

const shouldShowLocation = centerType !== CenterType.consult;
const shouldShowRate =
((centerId !== CENTERS.CONSULT && status === BookStatus.expired) || (centerId === CENTERS.CONSULT && status === BookStatus.visited)) &&
feedback.isSuccess &&
feedback?.data?.pageInfo?.totalRows === 0 &&
(status === BookStatus.expired || status === BookStatus.visited) &&
feedbackUrl;

const handleClickCard = () => {
Expand Down

0 comments on commit ebe8f1b

Please sign in to comment.