handle disable button if no data include in page add doctor

This commit is contained in:
Ehsan
2024-10-11 23:54:01 +03:30
parent 2f49c9e8c7
commit aecba57176
5 changed files with 29 additions and 6 deletions
+1 -2
View File
@@ -37,7 +37,6 @@ function AddDoctorPage() {
{ name: "پنج شنبه", morning_time: ["", ""], evening_time: ["", ""] },
],
});
console.log(data);
const components = [
<GeneralInformation
@@ -71,7 +70,7 @@ function AddDoctorPage() {
md:pt-[30px] pb-0 md:pb-[12px] lg:pb-[24px] px-0 md:px-[14px] lg:px-[26px] xl:px-[56px]"
>
<Step value={value} />
<div className="mt-[32px] px-[56px]">{components[value]}</div>
<div className="mt-[32px]">{components[value]}</div>
</div>
</div>
);
@@ -8,6 +8,7 @@ import EditField from "@/app/component/EditField";
import ContentText from "@/app/component/ContentText";
import ArrowLeftPA from "@/components/icons/ArrowLeftPA";
import AutoCompleteSelect from "@/app/component/element/AutoCompleteSelect";
import { checkAllValues } from "@/helper";
function Form({ setValue, parent, data, setData }) {
const changeData = (value, type, name) =>
@@ -91,8 +92,9 @@ function Form({ setValue, parent, data, setData }) {
</div>
<div className="mt-[40px] w-full flex justify-end">
<Button
className="!bg-[#5559CE] !w-full md:!w-fit !shadow-none !rounded-[4px] !gap-[4px] !text-[#EFEFEF] !text-[14px] md:!text-[16px] !font-medium"
className="!w-full md:!w-fit !shadow-none !rounded-[4px] !gap-[4px] !text-[#EFEFEF] !text-[14px] md:!text-[16px] !font-medium"
onClick={() => setValue((prev) => prev + 1)}
disabled={!checkAllValues(data)}
variant="contained"
>
ثبت اطلاعات
@@ -3,7 +3,7 @@ import Head from "./Head";
function GeneralInformation({ setValue, parent, data, setData }) {
return (
<div className="opacity-page pb-[24px]">
<div className="opacity-page pb-[24px] px-[56px]">
<Head />
<Form
parent={parent}
@@ -1,14 +1,16 @@
import ArrowLeftPA from "@/components/icons/ArrowLeftPA";
import { Button } from "@mui/material";
import Form from "./Form";
import { checkAllValues } from "@/helper";
function OfficeInformation({ setValue, parent, data, setData }) {
return (
<div className="opacity-page pb-[24px]">
<div className="opacity-page pb-[24px] px-[56px]">
<Form parent={parent} setData={setData} data={data.office} />
<div className="mt-[40px] w-full flex justify-end">
<Button
className="!bg-[#5559CE] !w-full md:!w-fit !shadow-none !rounded-[4px] !gap-[4px] !text-[#EFEFEF] !text-[14px] md:!text-[16px] !font-medium"
className="!w-full md:!w-fit !shadow-none !rounded-[4px] !gap-[4px] !text-[#EFEFEF] !text-[14px] md:!text-[16px] !font-medium"
disabled={!checkAllValues(data)}
onClick={() => setValue((prev) => prev + 1)}
variant="contained"
>
+20
View File
@@ -21,3 +21,23 @@ export const convertToJalali = (date) => {
export const handleTwoLength = (value) =>
String(value).length === 1 ? `0${value}` : value;
export const checkAllValues = (data) => {
for (let key in data) {
if (typeof data[key] === "object" && data[key] !== null) {
if ("value" in data[key]) {
if (!data[key].value) {
console.log(false);
return false;
}
} else {
if (!checkAllValues(data[key])) {
console.log(false);
return false;
}
}
}
}
console.log(true);
return true;
};