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>
64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
import { Button } from "@mui/material";
|
|
import Field from "./Field";
|
|
import { useState } from "react";
|
|
import { request } from "@/services/response";
|
|
import { alert } from "@/helper";
|
|
|
|
function SendAnswer({ doctor, parentUuid, onSent }) {
|
|
const [comment, setComment] = useState("");
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const sendReq = async () => {
|
|
if (!comment.trim()) return;
|
|
setLoading(true);
|
|
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 items-start gap-2 mb-2">
|
|
<Field
|
|
type="text"
|
|
value={comment}
|
|
title="پاسخ شما..."
|
|
isPlaceHolder={true}
|
|
updateValue={(val) => setComment(val)}
|
|
/>
|
|
<Button
|
|
disabled={loading}
|
|
onClick={sendReq}
|
|
variant="contained"
|
|
className="!p-2 !h-10 !text-[12px] !font-medium sm:!py-[10px] md:!px-[12px] !rounded-[8px]
|
|
!shadow-none sm:!shadow-[0px_4px_30px_0px_rgba(56,_160,_162,_0.30)]"
|
|
>
|
|
ارسال پاسخ
|
|
</Button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default SendAnswer;
|