feat(doctor): wire rich rating/review UI to multi-dimensional API

Connect the existing doctor-page review UI to the rebuilt backend contract
(see clinicpro feat/rating-multidimensional).

- page.js fetches the rating aggregate alongside comments and passes
  rateAggregate down to the chart (point / satisfaction / 5 dimensions).
- Submit form sends the five dimensions with doctor_uuid; comment/reply
  send {doctor_uuid, comment, parent}; 401/403 ERR_RATING_NOT_ELIGIBLE
  surface friendly guidance.
- Like/dislike call POST /like/{uuid} with value and update from the
  response; replies render nested.
- ModalAnswer gates the submit button on GET /rate/{uuid}/eligibility.
- services/response.js: getRateEligibility, postCommentsLike(uuid, value),
  drop unused patchDoctorRate. Fix hardcoded modal title; empty-state for
  no comments. Remove orphaned AnswerField.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-16 00:26:20 +03:30
co-authored by Claude Opus 4.8
parent 12917cd900
commit 7d65239615
18 changed files with 320 additions and 287 deletions
+28 -30
View File
@@ -4,44 +4,42 @@ import { useState } from "react";
import { request } from "@/services/response";
import { alert } from "@/helper";
function SendAnswer({ data }) {
function SendAnswer({ doctor, parentUuid, onSent }) {
const [comment, setComment] = useState("");
const [loading, setLoading] = useState(false);
const resetData = () => {
setComment("");
setLoading(false);
data.is_open_answer = false;
};
const sendReq = () => {
const sendReq = async () => {
if (!comment.trim()) return;
setLoading(true);
const body = {
comment,
doctor_id: data?.doctor?.id,
parent: data?.parent,
};
request
.postDoctorComment(body)
.then(() => {
alert(
"success",
"کامنت شما با موفقیت ثبت شد و پس از تأیید نمایش داده می‌شود."
);
resetData();
})
.catch(() => {
alert("error", "خطایی رخ داد! لطفاً دوباره تلاش کنید.");
resetData();
try {
await request.postDoctorComment({
doctor_uuid: doctor?.uuid,
comment,
parent: parentUuid,
});
alert("success", "پاسخ شما ثبت شد و پس از تأیید نمایش داده می‌شود.");
setComment("");
onSent?.();
} catch (err) {
const status = err?.response?.status;
const code = err?.response?.data?.errors?.[0]?.code;
if (status === 401) {
alert("warning", "برای ارسال پاسخ باید ابتدا وارد حساب کاربری شوید.");
} else if (status === 403 && code === "ERR_RATING_NOT_ELIGIBLE") {
alert(
"warning",
"فقط کاربرانی که در یک ماه گذشته نزد این پزشک نوبت تایید‌شده داشته‌اند می‌توانند نظر ثبت کنند."
);
} else {
alert("error", "خطایی رخ داد! لطفاً دوباره تلاش کنید.");
}
} finally {
setLoading(false);
}
};
return (
<div
className={`flex flex-col mt-2 justify-center overflow-hidden transition duration-500 items-start gap-2 mb-2
${data.is_open_answer ? "max-h-fit" : "max-h-0"}`}
>
<div className="flex flex-col mt-2 justify-center items-start gap-2 mb-2">
<Field
type="text"
value={comment}