design and handle modal add, edit and delete in all tabs dashboard & change list & update data profile_other
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import ModalDeleteItem from "../../components/modal/ModalDeleteItem";
|
||||
import TextLoading from "@/app/component/loading/Text";
|
||||
import { TableCell, TableRow } from "@mui/material";
|
||||
import ModalEditItem from "../../components/modal/ModalEditItem";
|
||||
import Content from "./modal/Content";
|
||||
import { useState } from "react";
|
||||
|
||||
function ItemMedication({ row, idx, changeData }) {
|
||||
const contentData = {
|
||||
name: row.name,
|
||||
dose: row.dose,
|
||||
frequency: row.frequency,
|
||||
};
|
||||
const [data, setData] = useState(contentData);
|
||||
const resetData = () => setData(contentData);
|
||||
|
||||
return (
|
||||
<TableRow
|
||||
key={idx}
|
||||
className="!border-0 !border-b !border-[#DBDBDB] dark:!border-transparent"
|
||||
>
|
||||
<TableCell
|
||||
className="!pr-[18px] dark:!border-transparent !text-[#616161] dark:!text-[#A1A1A1] !text-[16px] !font-medium !text-nowrap"
|
||||
align="center"
|
||||
>
|
||||
<TextLoading width={15} height={18} loading={false}>
|
||||
{idx + 1}
|
||||
</TextLoading>
|
||||
</TableCell>
|
||||
<TableCell className="!pr-[18px] dark:!border-transparent !text-[#616161] dark:!text-[#A1A1A1] !text-[16px] !font-medium !text-nowrap">
|
||||
<TextLoading width={15} height={18} loading={false}>
|
||||
{row.name}
|
||||
</TextLoading>
|
||||
</TableCell>
|
||||
<TableCell className="!pr-[18px] dark:!border-transparent !text-[#616161] dark:!text-[#A1A1A1] !text-[16px] !font-medium !text-nowrap">
|
||||
<TextLoading width={15} height={18} loading={false}>
|
||||
{row.dose}
|
||||
</TextLoading>
|
||||
</TableCell>
|
||||
<TableCell className="!pr-[18px] dark:!border-transparent !text-[#616161] dark:!text-[#A1A1A1] !text-[16px] !font-medium !text-nowrap">
|
||||
<TextLoading width={15} height={18} loading={false}>
|
||||
{row.frequency}
|
||||
</TextLoading>
|
||||
</TableCell>
|
||||
<TableCell
|
||||
className="!pr-[18px] dark:!border-transparent !text-[#616161] dark:!text-[#A1A1A1] !text-[16px] !font-medium !text-nowrap"
|
||||
align="right"
|
||||
>
|
||||
<div className="flex items-center justify-center gap-[4px]">
|
||||
<ModalDeleteItem
|
||||
id={idx}
|
||||
name="medications"
|
||||
changeData={changeData}
|
||||
/>
|
||||
<ModalEditItem
|
||||
id={idx}
|
||||
data={data}
|
||||
title="داروی مصرفی"
|
||||
name="medications"
|
||||
resetData={resetData}
|
||||
changeData={changeData}
|
||||
>
|
||||
<Content data={data} setData={setData} />
|
||||
</ModalEditItem>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
}
|
||||
|
||||
export default ItemMedication;
|
||||
@@ -1,13 +1,10 @@
|
||||
import CustomTable from "@/app/component/CustomTable";
|
||||
import TextLoading from "@/app/component/loading/Text";
|
||||
import EditB from "@/components/icons/EditB";
|
||||
import TrashB from "@/components/icons/TrashB";
|
||||
import { Button, TableCell, TableRow } from "@mui/material";
|
||||
import Head from "../../components/Head";
|
||||
import ModalAddMedications from "./modal";
|
||||
import { useState } from "react";
|
||||
import ItemMedication from "./ItemMedication";
|
||||
|
||||
function Medications({ data }) {
|
||||
function Medications({ data, changeData }) {
|
||||
const tableHead = ["ردیف", "نام دارو", "دوز مصرفی", "تعداد و زمان مصرف", ""];
|
||||
const centerTable = [0];
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -15,57 +12,32 @@ function Medications({ data }) {
|
||||
return (
|
||||
<div>
|
||||
<Head text="لیست دارو های مصرفی">
|
||||
<ModalAddMedications open={open} setOpen={setOpen} />
|
||||
<ModalAddMedications
|
||||
open={open}
|
||||
setOpen={setOpen}
|
||||
changeData={changeData}
|
||||
/>
|
||||
</Head>
|
||||
<CustomTable
|
||||
zeroRadius={true}
|
||||
tableHead={tableHead}
|
||||
centerTable={centerTable}
|
||||
>
|
||||
{data.medications.map((row, idx) => (
|
||||
<TableRow
|
||||
key={idx}
|
||||
className="!border-0 !border-b !border-[#DBDBDB] dark:!border-transparent"
|
||||
>
|
||||
<TableCell
|
||||
className="!pr-[18px] dark:!border-transparent !text-[#616161] dark:!text-[#A1A1A1] !text-[16px] !font-medium !text-nowrap"
|
||||
align="center"
|
||||
>
|
||||
<TextLoading width={15} height={18} loading={false}>
|
||||
{idx + 1}
|
||||
</TextLoading>
|
||||
</TableCell>
|
||||
<TableCell className="!pr-[18px] dark:!border-transparent !text-[#616161] dark:!text-[#A1A1A1] !text-[16px] !font-medium !text-nowrap">
|
||||
<TextLoading width={15} height={18} loading={false}>
|
||||
{row.name}
|
||||
</TextLoading>
|
||||
</TableCell>
|
||||
<TableCell className="!pr-[18px] dark:!border-transparent !text-[#616161] dark:!text-[#A1A1A1] !text-[16px] !font-medium !text-nowrap">
|
||||
<TextLoading width={15} height={18} loading={false}>
|
||||
{row.dose}
|
||||
</TextLoading>
|
||||
</TableCell>
|
||||
<TableCell className="!pr-[18px] dark:!border-transparent !text-[#616161] dark:!text-[#A1A1A1] !text-[16px] !font-medium !text-nowrap">
|
||||
<TextLoading width={15} height={18} loading={false}>
|
||||
{row.frequency}
|
||||
</TextLoading>
|
||||
</TableCell>
|
||||
<TableCell
|
||||
className="!pr-[18px] dark:!border-transparent !text-[#616161] dark:!text-[#A1A1A1] !text-[16px] !font-medium !text-nowrap"
|
||||
align="right"
|
||||
>
|
||||
<div className="flex items-center justify-center gap-[4px]">
|
||||
<Button className="!min-w-fit !p-1" variant="text">
|
||||
<TrashB />
|
||||
</Button>
|
||||
<Button className="!min-w-fit !p-1" variant="text">
|
||||
<EditB />
|
||||
</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</CustomTable>
|
||||
{data.medications.length ? (
|
||||
<CustomTable
|
||||
zeroRadius={true}
|
||||
tableHead={tableHead}
|
||||
centerTable={centerTable}
|
||||
>
|
||||
{data.medications.map((row, idx) => (
|
||||
<ItemMedication
|
||||
key={idx}
|
||||
row={row}
|
||||
idx={idx}
|
||||
changeData={changeData}
|
||||
/>
|
||||
))}
|
||||
</CustomTable>
|
||||
) : (
|
||||
<p className="text-center py-10 text-gray-500">
|
||||
هیچ داروی مصرفی وجود ندارد!
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import FieldLabel from "@/components/contactUs/FieldLabel";
|
||||
import Field from "@/app/component/Field";
|
||||
|
||||
function Content({ setData, data }) {
|
||||
const handleChange = (name, value) =>
|
||||
setData((prev) => ({ ...prev, [name]: value }));
|
||||
|
||||
return (
|
||||
<div className="mt-[32px] md:mt-[36px] lg:mt-[40px] flex flex-col gap-[24px] md:gap-[28px] lg:gap-[32px] px-0 sm:px-[52px]">
|
||||
<FieldLabel title="نام دارو">
|
||||
<Field
|
||||
title=""
|
||||
type="text"
|
||||
name="name"
|
||||
isPlaceHolder={true}
|
||||
value={data?.name}
|
||||
handleChange={handleChange}
|
||||
/>
|
||||
</FieldLabel>
|
||||
<FieldLabel title="دوز مصرفی (mg)">
|
||||
<Field
|
||||
title=""
|
||||
type="number"
|
||||
name="dose"
|
||||
isPlaceHolder={true}
|
||||
value={data?.dose.match(/\d+/)[0]}
|
||||
handleChange={(name, value) => handleChange(name, `${value}mg`)}
|
||||
/>
|
||||
</FieldLabel>
|
||||
<FieldLabel title="تعداد و زمان مصرف">
|
||||
<Field
|
||||
title=""
|
||||
type="text"
|
||||
name="frequency"
|
||||
isPlaceHolder={true}
|
||||
value={data?.frequency}
|
||||
handleChange={handleChange}
|
||||
/>
|
||||
</FieldLabel>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Content;
|
||||
@@ -2,10 +2,24 @@ import { styleDefault } from "@/mui";
|
||||
import AddBtn from "../../../components/AddBtn";
|
||||
import UpdateBtn from "../../../components/UpdateBtn";
|
||||
import { Button, Modal } from "@mui/material";
|
||||
import { useState } from "react";
|
||||
import Content from "./Content";
|
||||
|
||||
function ModalAddMedications({ open, setOpen, changeData }) {
|
||||
const contentItem = {
|
||||
name: "",
|
||||
dose: "",
|
||||
frequency: "",
|
||||
};
|
||||
|
||||
function ModalAddMedications({ open, setOpen }) {
|
||||
const handleOpen = () => setOpen(true);
|
||||
const handleClose = () => setOpen(false);
|
||||
const [newItem, setNewItem] = useState(contentItem);
|
||||
const handleAddData = () => {
|
||||
changeData("add", "medications", null, newItem);
|
||||
setNewItem(contentItem);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -24,16 +38,19 @@ function ModalAddMedications({ open, setOpen }) {
|
||||
>
|
||||
<div>
|
||||
<div className="flex justify-between w-full">
|
||||
<p className="text-[#3B3B3B] text-[20px] font-bold">اضافه کردن دارو های مصرفی</p>
|
||||
<p className="text-[#3B3B3B] text-[20px] font-bold">
|
||||
اضافه کردن دارو های مصرفی
|
||||
</p>
|
||||
</div>
|
||||
{/* <Content /> */}
|
||||
<Content setData={setNewItem} />
|
||||
</div>
|
||||
<Button
|
||||
className="!mt-[32px] md:!mt-[36px] lg:!mt-[40px] !px-3 !py-2 !text-[16px] !font-medium !w-fit !mr-auto"
|
||||
onClick={handleClose}
|
||||
onClick={handleAddData}
|
||||
disabled={!newItem.name || !newItem.dose || !newItem.frequency}
|
||||
variant="contained"
|
||||
>
|
||||
اعمال تغییرات
|
||||
اضافه کردن
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
Reference in New Issue
Block a user