handle update data in tab dashboard
This commit is contained in:
@@ -2,7 +2,6 @@ import Content from "./Content";
|
||||
import DateBirthday from "./DateBirthday";
|
||||
import Field from "./Field";
|
||||
import {
|
||||
insurance,
|
||||
gender,
|
||||
blood_group,
|
||||
marital_status,
|
||||
@@ -11,8 +10,9 @@ import {
|
||||
} from "./listSelector";
|
||||
import AutoSelector from "@/app/component/element/AutoSelector";
|
||||
|
||||
function Form({ data, changeData, prevData }) {
|
||||
const findVal = (list, name) => data && list.find((g) => g.id === data[name]);
|
||||
function Form({ data, userInfo, insurance, changeData, prevData }) {
|
||||
const findVal = (list, name) =>
|
||||
data && list && list.length && list.find((g) => g.id === data[name]);
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-[24px]">
|
||||
@@ -22,8 +22,8 @@ function Form({ data, changeData, prevData }) {
|
||||
iconGray={true}
|
||||
type="number"
|
||||
changeData={changeData}
|
||||
data={data?.work_phone}
|
||||
disable={prevData}
|
||||
data={userInfo?.username}
|
||||
disable={true}
|
||||
name="work_phone"
|
||||
/>
|
||||
</Content>
|
||||
@@ -75,7 +75,9 @@ function Form({ data, changeData, prevData }) {
|
||||
</Content>
|
||||
<Content title="نوع بیمه">
|
||||
<AutoSelector
|
||||
updateData={changeData}
|
||||
updateData={(name, val) => {
|
||||
changeData([Number(val.id)], "value", name);
|
||||
}}
|
||||
value={findVal(insurance, "basic_insurance")}
|
||||
label="نوع بیمه"
|
||||
name="basic_insurance"
|
||||
@@ -88,8 +90,8 @@ function Form({ data, changeData, prevData }) {
|
||||
iconGray={true}
|
||||
type="number"
|
||||
changeData={changeData}
|
||||
data={data?.insurance_number}
|
||||
name="insurance_number"
|
||||
data={data?.supplementary_insurance}
|
||||
name="supplementary_insurance"
|
||||
/>
|
||||
</Content>
|
||||
<Content title="گروه خونی">
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import Form from "./Form";
|
||||
import { Button } from "@mui/material";
|
||||
import ArrowLeftWhiteD from "@/components/icons/ArrowLeftWhiteD";
|
||||
import { request } from "@/services/response";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
function Information({ user, dataUser }) {
|
||||
function Information({ user, data, setData, userInfo, dataUser }) {
|
||||
const [disable, setDisable] = useState(true);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [data, setData] = useState(dataUser || {});
|
||||
const [insurance, setInsurance] = useState();
|
||||
|
||||
useEffect(() => {
|
||||
request
|
||||
.getInsuranceType()
|
||||
.then((res) => {
|
||||
if (res && res.data) {
|
||||
setInsurance(res.data);
|
||||
}
|
||||
})
|
||||
.catch((err) => {});
|
||||
}, []);
|
||||
|
||||
const changeData = (value, type, name) => {
|
||||
disable && setDisable(false);
|
||||
@@ -19,7 +31,10 @@ function Information({ user, dataUser }) {
|
||||
|
||||
const sendReq = () => {
|
||||
setLoading(true);
|
||||
request[dataUser ? "patchUserProfile" : "postUserProfile"](data)
|
||||
request[dataUser ? "patchUserProfile" : "postUserProfile"](
|
||||
data,
|
||||
Cookies.get("uuid")
|
||||
)
|
||||
.then((res) => {
|
||||
setLoading(false);
|
||||
})
|
||||
@@ -30,7 +45,13 @@ function Information({ user, dataUser }) {
|
||||
|
||||
return (
|
||||
<div className="opacity-page">
|
||||
<Form data={data} changeData={changeData} prevData={dataUser} />
|
||||
<Form
|
||||
data={data}
|
||||
userInfo={userInfo}
|
||||
prevData={dataUser}
|
||||
insurance={insurance}
|
||||
changeData={changeData}
|
||||
/>
|
||||
<Button
|
||||
disabled={disable}
|
||||
variant="contained"
|
||||
|
||||
Reference in New Issue
Block a user