handle update data in tab dashboard
This commit is contained in:
@@ -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