refactor: add supplementary insurance handling in Form component and update Detail component to fetch insurance data
This commit is contained in:
@@ -2,8 +2,8 @@ import Content from "./Content";
|
|||||||
import EditField from "../../../app/component/fields/EditField";
|
import EditField from "../../../app/component/fields/EditField";
|
||||||
import DefaultSelect from "@/app/component/selectors/DefaultSelect";
|
import DefaultSelect from "@/app/component/selectors/DefaultSelect";
|
||||||
|
|
||||||
function Form({ changeData, insurance, data, isForAnother }) {
|
function Form({ changeData, insurance, supplementaryInsurance, data, isForAnother }) {
|
||||||
const findVal = () => {
|
const findBasicInsuranceVal = () => {
|
||||||
return insurance?.find(
|
return insurance?.find(
|
||||||
(g) =>
|
(g) =>
|
||||||
g.id ===
|
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 (
|
return (
|
||||||
<div
|
<div
|
||||||
className="grid mt-[12px] sm:mt-[14px] md:mt-[17px] lg:mt-[20px] items-start
|
className="grid mt-[12px] sm:mt-[14px] md:mt-[17px] lg:mt-[20px] items-start
|
||||||
@@ -26,16 +34,28 @@ function Form({ changeData, insurance, data, isForAnother }) {
|
|||||||
name="national_code"
|
name="national_code"
|
||||||
/>
|
/>
|
||||||
</Content>
|
</Content>
|
||||||
<Content title="نام و نام خانوادگی">
|
<Content title="نام">
|
||||||
<EditField changeData={changeData} data={data?.name} name="name" />
|
<EditField changeData={changeData} data={data?.name} name="name" />
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content title="نام خانوادگی">
|
||||||
|
<EditField changeData={changeData} data={data?.family} name="family" />
|
||||||
|
</Content>
|
||||||
<Content title="نوع بیمه">
|
<Content title="نوع بیمه">
|
||||||
<DefaultSelect
|
<DefaultSelect
|
||||||
updateData={(name, val) => changeData(val, "value", name)}
|
updateData={(name, val) => changeData(val, "value", name)}
|
||||||
label="نوع بیمه"
|
label="نوع بیمه"
|
||||||
name="basic_insurance"
|
name="basic_insurance"
|
||||||
list={insurance}
|
list={insurance}
|
||||||
value={findVal()}
|
value={findBasicInsuranceVal()}
|
||||||
|
/>
|
||||||
|
</Content>
|
||||||
|
<Content title="بیمه تکمیلی">
|
||||||
|
<DefaultSelect
|
||||||
|
updateData={(name, val) => changeData(val, "value", name)}
|
||||||
|
label="بیمه تکمیلی"
|
||||||
|
name="supplementary_insurance"
|
||||||
|
list={supplementaryInsurance}
|
||||||
|
value={findSupplementaryInsuranceVal()}
|
||||||
/>
|
/>
|
||||||
</Content>
|
</Content>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ function Detail({
|
|||||||
setIsPay,
|
setIsPay,
|
||||||
}) {
|
}) {
|
||||||
const [insurance, setInsurance] = useState();
|
const [insurance, setInsurance] = useState();
|
||||||
|
const [supplementaryInsurance, setSupplementaryInsurance] = useState();
|
||||||
const changeData = (value, type, name) =>
|
const changeData = (value, type, name) =>
|
||||||
setData({
|
setData({
|
||||||
...data,
|
...data,
|
||||||
@@ -27,11 +28,19 @@ function Detail({
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// دریافت لیست بیمه پایه
|
||||||
request.getInsuranceType().then((res) => {
|
request.getInsuranceType().then((res) => {
|
||||||
if (res && res.data) {
|
if (res && res.data) {
|
||||||
setInsurance(res.data);
|
setInsurance(res.data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// دریافت لیست بیمه تکمیلی
|
||||||
|
request.getSupplementaryInsurance().then((res) => {
|
||||||
|
if (res && res.data) {
|
||||||
|
setSupplementaryInsurance(res.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -56,6 +65,7 @@ function Detail({
|
|||||||
<Form
|
<Form
|
||||||
data={data}
|
data={data}
|
||||||
insurance={insurance}
|
insurance={insurance}
|
||||||
|
supplementaryInsurance={supplementaryInsurance}
|
||||||
changeData={changeData}
|
changeData={changeData}
|
||||||
isForAnother={isForAnother}
|
isForAnother={isForAnother}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ export const request = {
|
|||||||
getUserInfo: (headers) => api.get("oauth/userinfo", { ...headers, requireAuth: true }),
|
getUserInfo: (headers) => api.get("oauth/userinfo", { ...headers, requireAuth: true }),
|
||||||
getInsuranceType: (page = 1, limit = 10) =>
|
getInsuranceType: (page = 1, limit = 10) =>
|
||||||
api.get(`api/v1/categorys/insurance_type?page=${page}&limit=${limit}`, removeTokenHead),
|
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) =>
|
getDoctors: (params) =>
|
||||||
api.get("api/v1/doctors", {
|
api.get("api/v1/doctors", {
|
||||||
params,
|
params,
|
||||||
|
|||||||
Reference in New Issue
Block a user