63 lines
2.0 KiB
JavaScript
63 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;
|