prop loading روی Button فقط در MUI v6+ پشتیبانی میشود؛ این پروژه v5 است و هشدار "Received false for a non-boolean attribute loading" میداد. - دکمههای login/verify: disabled + CircularProgress شرطی (بازخورد بصری حفظ شد) - بقیه دکمهها: loading → disabled (ادغام با disabled موجود در صورت وجود) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
66 lines
1.7 KiB
JavaScript
66 lines
1.7 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({ data }) {
|
|
const [comment, setComment] = useState("");
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const resetData = () => {
|
|
setComment("");
|
|
setLoading(false);
|
|
data.is_open_answer = false;
|
|
};
|
|
|
|
const sendReq = () => {
|
|
setLoading(true);
|
|
const body = {
|
|
comment,
|
|
doctor_id: data?.doctor?.id,
|
|
parent: data?.parent,
|
|
};
|
|
|
|
request
|
|
.postDoctorComment(body)
|
|
.then(() => {
|
|
alert(
|
|
"success",
|
|
"کامنت شما با موفقیت ثبت شد و پس از تأیید نمایش داده میشود."
|
|
);
|
|
resetData();
|
|
})
|
|
.catch(() => {
|
|
alert("error", "خطایی رخ داد! لطفاً دوباره تلاش کنید.");
|
|
resetData();
|
|
});
|
|
};
|
|
|
|
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"}`}
|
|
>
|
|
<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;
|