From 8c03717cb76ce48673a9f353b3e637811f9735f8 Mon Sep 17 00:00:00 2001
From: hamed <15238-genius.ha@users.noreply.drupalcode.org>
Date: Mon, 17 Nov 2025 15:48:33 +0330
Subject: [PATCH] refactor: add supplementary insurance handling in Form
component and update Detail component to fetch insurance data
---
components/appointment/detail/Form.js | 28 ++++++++++++++++++++++----
components/appointment/detail/index.js | 10 +++++++++
services/response.js | 2 ++
3 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/components/appointment/detail/Form.js b/components/appointment/detail/Form.js
index 239206a..d1fe8b9 100644
--- a/components/appointment/detail/Form.js
+++ b/components/appointment/detail/Form.js
@@ -2,8 +2,8 @@ import Content from "./Content";
import EditField from "../../../app/component/fields/EditField";
import DefaultSelect from "@/app/component/selectors/DefaultSelect";
-function Form({ changeData, insurance, data, isForAnother }) {
- const findVal = () => {
+function Form({ changeData, insurance, supplementaryInsurance, data, isForAnother }) {
+ const findBasicInsuranceVal = () => {
return insurance?.find(
(g) =>
g.id ===
@@ -11,6 +11,14 @@ function Form({ changeData, insurance, data, isForAnother }) {
);
};
+ const findSupplementaryInsuranceVal = () => {
+ return supplementaryInsurance?.find(
+ (g) =>
+ g.id ===
+ (data?.supplementary_insurance?.value ? data?.supplementary_insurance.value.id : false)
+ );
+ };
+
return (
-
+
+
+
+
changeData(val, "value", name)}
label="نوع بیمه"
name="basic_insurance"
list={insurance}
- value={findVal()}
+ value={findBasicInsuranceVal()}
+ />
+
+
+ changeData(val, "value", name)}
+ label="بیمه تکمیلی"
+ name="supplementary_insurance"
+ list={supplementaryInsurance}
+ value={findSupplementaryInsuranceVal()}
/>
diff --git a/components/appointment/detail/index.js b/components/appointment/detail/index.js
index 8b61501..9751fad 100644
--- a/components/appointment/detail/index.js
+++ b/components/appointment/detail/index.js
@@ -17,6 +17,7 @@ function Detail({
setIsPay,
}) {
const [insurance, setInsurance] = useState();
+ const [supplementaryInsurance, setSupplementaryInsurance] = useState();
const changeData = (value, type, name) =>
setData({
...data,
@@ -27,11 +28,19 @@ function Detail({
});
useEffect(() => {
+ // دریافت لیست بیمه پایه
request.getInsuranceType().then((res) => {
if (res && res.data) {
setInsurance(res.data);
}
});
+
+ // دریافت لیست بیمه تکمیلی
+ request.getSupplementaryInsurance().then((res) => {
+ if (res && res.data) {
+ setSupplementaryInsurance(res.data);
+ }
+ });
}, []);
return (
@@ -56,6 +65,7 @@ function Detail({
diff --git a/services/response.js b/services/response.js
index ef6631f..efee94c 100644
--- a/services/response.js
+++ b/services/response.js
@@ -42,6 +42,8 @@ export const request = {
getUserInfo: (headers) => api.get("oauth/userinfo", { ...headers, requireAuth: true }),
getInsuranceType: (page = 1, limit = 10) =>
api.get(`api/v1/categorys/insurance_type?page=${page}&limit=${limit}`, removeTokenHead),
+ getSupplementaryInsurance: (page = 1, limit = 100) =>
+ api.get(`api/v1/categorys/supplementary_insurance?page=${page}&limit=${limit}`, removeTokenHead),
getDoctors: (params) =>
api.get("api/v1/doctors", {
params,