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:
@@ -1,20 +1,11 @@
|
||||
import { alert, isUserLoggedIn } from "@/helper";
|
||||
import { Button } from "@mui/material";
|
||||
import React from "react";
|
||||
|
||||
function BtnNewComment({ handleOpen }) {
|
||||
const handleClick = () => {
|
||||
if (isUserLoggedIn()) {
|
||||
handleOpen();
|
||||
} else {
|
||||
alert("warning", "برای ارسال کامنت باید ابتدا وارد حساب کاربری شوید.");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={handleClick}
|
||||
onClick={handleOpen}
|
||||
className="!py-[6px] md:!py-2 lg:!py-[9px] !px-[16px] sm:!px-[23px] md:!px-[29px]
|
||||
lg:!px-[36px] !mr-0 md:!mr-4 !rounded !w-full md:!w-fit"
|
||||
>
|
||||
|
||||
@@ -7,46 +7,42 @@ import ProgressDetail from "@/data/progress_detail.json";
|
||||
import BtnNewComment from "./BtnNewComment";
|
||||
import Content from "./content";
|
||||
import { request } from "@/services/response";
|
||||
import Cookies from "js-cookie";
|
||||
import { alert, isUserLoggedIn } from "@/helper";
|
||||
|
||||
function ModalAnswer({ doctor }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const handleOpen = () => setOpen(true);
|
||||
const handleClose = () => setOpen(false);
|
||||
const [eligible, setEligible] = useState(false);
|
||||
const [comment, setComment] = useState({
|
||||
defaultRate: false,
|
||||
uuid: "",
|
||||
rate: ProgressDetail,
|
||||
detail: {
|
||||
comment: "",
|
||||
doctor_id: doctor?.id,
|
||||
},
|
||||
rate: ProgressDetail.map((item) => ({ ...item, progress: 0 })),
|
||||
detail: { comment: "" },
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const isLogged = Cookies.get("access_token");
|
||||
if (!doctor?.uuid || !isUserLoggedIn()) return;
|
||||
|
||||
if (doctor && doctor.uuid && isLogged) {
|
||||
let newRate = comment.rate;
|
||||
request
|
||||
.getDoctorRate(doctor.uuid)
|
||||
.then((res) => {
|
||||
if (res.doctor_id) {
|
||||
newRate.map((item) => (item.progress = res[item.name]));
|
||||
setComment({
|
||||
...comment,
|
||||
defaultRate: true,
|
||||
uuid: res.uuid,
|
||||
rate: newRate,
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
//
|
||||
});
|
||||
request
|
||||
.getRateEligibility(doctor.uuid)
|
||||
.then((res) => setEligible(!!res.data?.eligible))
|
||||
.catch(() => setEligible(false));
|
||||
}, [doctor?.uuid]);
|
||||
|
||||
const handleOpen = () => {
|
||||
if (!isUserLoggedIn()) {
|
||||
alert("warning", "برای ثبت نظر باید ابتدا وارد حساب کاربری شوید.");
|
||||
return;
|
||||
}
|
||||
}, []);
|
||||
if (!eligible) {
|
||||
alert(
|
||||
"warning",
|
||||
"فقط کاربرانی که در یک ماه گذشته نزد این پزشک نوبت تاییدشده داشتهاند میتوانند نظر ثبت کنند."
|
||||
);
|
||||
return;
|
||||
}
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
const handleClose = () => setOpen(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -2,62 +2,51 @@ import React, { useState } from "react";
|
||||
import Field from "@/app/component/fields/Field";
|
||||
import { Button } from "@mui/material";
|
||||
import { request } from "@/services/response";
|
||||
import { alert } from "@/helper";
|
||||
import ArrowLeftD from "@/components/icons/ArrowLeftD";
|
||||
|
||||
function Form({
|
||||
doctor,
|
||||
setOpen,
|
||||
comment,
|
||||
loading,
|
||||
changeData,
|
||||
setComment,
|
||||
setLoading,
|
||||
}) {
|
||||
function Form({ doctor, setOpen, comment, loading, changeData, setComment, setLoading }) {
|
||||
const [isError, setIsError] = useState(false);
|
||||
|
||||
const sendReq = () => {
|
||||
if (comment?.detail?.comment) {
|
||||
setLoading(true);
|
||||
|
||||
request
|
||||
.postDoctorComment(comment.detail)
|
||||
.then(() => {
|
||||
let newComment = comment.rate;
|
||||
newComment = {
|
||||
doctor_id: doctor?.id,
|
||||
accuracy_of_diagnosis: newComment[1].progress,
|
||||
doctor_expertise: newComment[4].progress,
|
||||
doctor_behavior: newComment[2].progress,
|
||||
clinic_cleanliness: newComment[3].progress,
|
||||
waiting_time_at_clinic: newComment[0].progress,
|
||||
};
|
||||
setComment({
|
||||
...comment,
|
||||
detail: {
|
||||
...comment.detail,
|
||||
comment: "",
|
||||
},
|
||||
});
|
||||
|
||||
request[comment.defaultRate ? "patchDoctorRate" : "postDoctorRate"](
|
||||
newComment,
|
||||
comment.uuid
|
||||
)
|
||||
.then(() => {
|
||||
setLoading(false);
|
||||
setOpen(false);
|
||||
})
|
||||
.catch(() => {
|
||||
setLoading(false);
|
||||
setOpen(false);
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
setLoading(false);
|
||||
setOpen(false);
|
||||
});
|
||||
const handleRatingError = (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", "خطایی رخ داد! لطفاً دوباره تلاش کنید.");
|
||||
}
|
||||
};
|
||||
|
||||
const sendReq = async () => {
|
||||
const text = comment?.detail?.comment;
|
||||
if (!text) {
|
||||
setIsError(true);
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
await request.postDoctorComment({ doctor_uuid: doctor.uuid, comment: text });
|
||||
|
||||
const rate = { doctor_uuid: doctor.uuid };
|
||||
comment.rate.forEach((item) => {
|
||||
rate[item.name] = item.progress;
|
||||
});
|
||||
await request.postDoctorRate(rate);
|
||||
|
||||
setComment({ ...comment, detail: { ...comment.detail, comment: "" } });
|
||||
alert("success", "نظر شما ثبت شد و پس از تأیید نمایش داده میشود.");
|
||||
setOpen(false);
|
||||
} catch (err) {
|
||||
handleRatingError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -71,7 +60,7 @@ function Form({
|
||||
<div className="flex flex-col gap-[16px] justify-center items-start mt-[24px]">
|
||||
<p className="text-[#495057] text-[16px] font-bold">متن نظر</p>
|
||||
<Field
|
||||
type="number"
|
||||
type="text"
|
||||
error={isError}
|
||||
multiline={true}
|
||||
handleChange={handleChange}
|
||||
|
||||
@@ -39,7 +39,7 @@ function Content({
|
||||
<>
|
||||
<div className="flex items-center justify-between w-full">
|
||||
<p className="text-[16px] text-[#525252] font-bold">
|
||||
امتیاز شما به دکتر مهران امینی
|
||||
امتیاز شما به {doctor?.name}
|
||||
</p>
|
||||
<div className="cursor-pointer" onClick={handleClose}>
|
||||
<CloseModalD />
|
||||
|
||||
Reference in New Issue
Block a user