feat: add showPublicScores and showPublicOpinions flags to services with plan-based access control
This commit is contained in:
@@ -17,6 +17,11 @@ export default function OrganizationHeader(props: OrganizationHeaderProps) {
|
||||
const [ratingSummary, setRatingSummary] = useState<RatingTargetSummaryResult>({ averageScore: 0, totalCount: 0 });
|
||||
|
||||
useEffect(() => {
|
||||
if (organization.showPublicScores === false) {
|
||||
setRatingSummary({ averageScore: 0, totalCount: 0 });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!organization.id) {
|
||||
setRatingSummary({ averageScore: 0, totalCount: 0 });
|
||||
return;
|
||||
@@ -32,7 +37,7 @@ export default function OrganizationHeader(props: OrganizationHeaderProps) {
|
||||
.catch(() => {
|
||||
setRatingSummary({ averageScore: 0, totalCount: 0 });
|
||||
});
|
||||
}, [organization.id]);
|
||||
}, [organization.id, organization.showPublicScores]);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -67,7 +72,7 @@ export default function OrganizationHeader(props: OrganizationHeaderProps) {
|
||||
>
|
||||
{organization.description}
|
||||
</p>
|
||||
{ratingSummary.totalCount > 0 && (
|
||||
{organization.showPublicScores !== false && ratingSummary.totalCount > 0 && (
|
||||
<div className={style.organizationRatingSummary}>
|
||||
<Rating
|
||||
className={style.organizationRatingStars}
|
||||
|
||||
@@ -63,6 +63,7 @@ export default function ProductItem(props: ProductItemProps) {
|
||||
variant="card"
|
||||
displayMode="compact"
|
||||
showOpinionCount={false}
|
||||
enabled={product.showPublicScores !== false}
|
||||
/>
|
||||
</div>
|
||||
<div className={style.cardHeader}>
|
||||
@@ -126,7 +127,12 @@ export default function ProductItem(props: ProductItemProps) {
|
||||
<div className={style.itemContent}>
|
||||
<div className={style.itemHeader}>
|
||||
<h3 className={style.itemTitle}>{product.name}</h3>
|
||||
<ServiceRatingSummary serviceId={product.id} variant="row" showOpinionCount={false} />
|
||||
<ServiceRatingSummary
|
||||
serviceId={product.id}
|
||||
variant="row"
|
||||
showOpinionCount={false}
|
||||
enabled={product.showPublicScores !== false}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p
|
||||
|
||||
@@ -32,6 +32,16 @@ const renderStars = (score: number): string => {
|
||||
|
||||
const formatScore = (score: number): string => score.toFixed(1);
|
||||
|
||||
const sortReviewsByScore = (reviews: RatingTargetReviewItem[]): RatingTargetReviewItem[] => {
|
||||
return [...reviews].sort((firstReview, secondReview) => {
|
||||
if (secondReview.score !== firstReview.score) {
|
||||
return secondReview.score - firstReview.score;
|
||||
}
|
||||
|
||||
return new Date(secondReview.createdAt).getTime() - new Date(firstReview.createdAt).getTime();
|
||||
});
|
||||
};
|
||||
|
||||
export default function ReviewsCarousel({
|
||||
targetType,
|
||||
targetId,
|
||||
@@ -50,7 +60,7 @@ export default function ReviewsCarousel({
|
||||
ratingTargetReviews({ targetType, targetId, limit })
|
||||
.then((targetReviews) => {
|
||||
if (active) {
|
||||
setReviews(targetReviews.filter((review) => review.comment.trim().length > 0));
|
||||
setReviews(sortReviewsByScore(targetReviews.filter((review) => review.comment.trim().length > 0)));
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
|
||||
@@ -10,13 +10,19 @@ export interface ServiceRatingSummaryProps {
|
||||
variant?: "card" | "row";
|
||||
displayMode?: "default" | "compact";
|
||||
showOpinionCount?: boolean;
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
export default function ServiceRatingSummary(props: ServiceRatingSummaryProps): React.ReactElement | null {
|
||||
const { serviceId, variant = "card", displayMode = "default", showOpinionCount = true } = props;
|
||||
const { serviceId, variant = "card", displayMode = "default", showOpinionCount = true, enabled = true } = props;
|
||||
const [ratingSummary, setRatingSummary] = useState<RatingTargetSummaryResult>({ averageScore: 0, totalCount: 0 });
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) {
|
||||
setRatingSummary({ averageScore: 0, totalCount: 0 });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!serviceId) {
|
||||
setRatingSummary({ averageScore: 0, totalCount: 0 });
|
||||
return;
|
||||
@@ -42,9 +48,9 @@ export default function ServiceRatingSummary(props: ServiceRatingSummaryProps):
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
}, [serviceId]);
|
||||
}, [serviceId, enabled]);
|
||||
|
||||
if (ratingSummary.totalCount <= 0) {
|
||||
if (!enabled || ratingSummary.totalCount <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,15 @@ import MuiSwitch from "@mui/material/Switch";
|
||||
interface SwitchProps {
|
||||
checked: boolean;
|
||||
onChange: (checked: boolean) => void;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export default function Switch({ checked, onChange }: SwitchProps) {
|
||||
export default function Switch({ checked, onChange, disabled = false }: SwitchProps) {
|
||||
return (
|
||||
<ThemeProvider theme={turnosXpressTheme}>
|
||||
<MuiSwitch
|
||||
checked={checked}
|
||||
disabled={disabled}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
onChange(event.target.checked);
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user