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 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 (
|
||||
<div
|
||||
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"
|
||||
/>
|
||||
</Content>
|
||||
<Content title="نام و نام خانوادگی">
|
||||
<Content title="نام">
|
||||
<EditField changeData={changeData} data={data?.name} name="name" />
|
||||
</Content>
|
||||
<Content title="نام خانوادگی">
|
||||
<EditField changeData={changeData} data={data?.family} name="family" />
|
||||
</Content>
|
||||
<Content title="نوع بیمه">
|
||||
<DefaultSelect
|
||||
updateData={(name, val) => changeData(val, "value", name)}
|
||||
label="نوع بیمه"
|
||||
name="basic_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>
|
||||
</div>
|
||||
|
||||
@@ -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({
|
||||
<Form
|
||||
data={data}
|
||||
insurance={insurance}
|
||||
supplementaryInsurance={supplementaryInsurance}
|
||||
changeData={changeData}
|
||||
isForAnother={isForAnother}
|
||||
/>
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user