handle change data and update data in dashboard page for all tabs

This commit is contained in:
Ehsan
2025-06-11 16:52:01 +03:30
parent 72ed07071c
commit bf64271d14
26 changed files with 235 additions and 118 deletions
@@ -3,7 +3,7 @@ import TextLoading from "@/app/component/loading/Text";
import { TableCell, TableRow } from "@mui/material";
import ModalEditItem from "@/components/dashboard/userAccount/components/modal/ModalEditItem";
import Content from "./modal/Content";
import { useState } from "react";
import { useEffect, useState } from "react";
function ItemRelatives({ row, idx, changeData }) {
const contentData = {
@@ -12,9 +12,19 @@ function ItemRelatives({ row, idx, changeData }) {
phone: row.contact.phone,
address: row.contact.address,
};
const [data, setData] = useState(contentData);
const resetData = () => setData(contentData);
useEffect(() => {
setData({
name: row.name,
relation: row.relation,
phone: row.contact.phone,
address: row.contact.address,
});
}, [row]);
return (
<TableRow
key={idx}
@@ -4,7 +4,9 @@ import Head from "@/components/dashboard/userAccount/components/Head";
import ModalAddRelatives from "./modal";
import ItemRelatives from "./ItemRelatives";
function Relatives({ data, changeData }) {
function Relatives({ data, changeData, loading, updateData }) {
const { other } = data;
const { relatives } = other && other[0];
const tableHead = ["ردیف", "نام", "نسبت", "شماره تماس", "آدرس", ""];
const centerTable = [0];
const [open, setOpen] = useState(false);
@@ -14,17 +16,19 @@ function Relatives({ data, changeData }) {
<Head text="لیست بستگان">
<ModalAddRelatives
open={open}
loading={loading}
setOpen={setOpen}
changeData={changeData}
updateData={updateData}
/>
</Head>
{data.medications.length ? (
{relatives.length ? (
<CustomTable
zeroRadius={true}
tableHead={tableHead}
centerTable={centerTable}
>
{data.relatives.map((row, idx) => (
{relatives.map((row, idx) => (
<ItemRelatives
key={idx}
row={row}
@@ -6,7 +6,7 @@ import Content from "./Content";
import { useState } from "react";
import CloseModalD from "@/components/icons/CloseModalD";
function ModalAddRelatives({ open, setOpen, changeData }) {
function ModalAddRelatives({ open, setOpen, changeData, loading, updateData }) {
const contentItem = {
name: "",
relation: "",
@@ -36,7 +36,7 @@ function ModalAddRelatives({ open, setOpen, changeData }) {
<>
{/* Button Modal */}
<>
<UpdateBtn />
<UpdateBtn updateData={updateData} loading={loading} />
<AddBtn handleOpen={handleOpen} />
</>