From e777a2dfa4e0afaa8563cde637c8e438cca9b6a2 Mon Sep 17 00:00:00 2001 From: Ehsan Date: Fri, 18 Oct 2024 18:11:03 +0330 Subject: [PATCH] handle validate field in step 3 page add-doctor --- .../clinic/components/about/ListBime.js | 2 -- components/panel/addDoctor/index.js | 9 ++------ .../addDoctor/listMenu/workingDays/List.js | 3 ++- .../addDoctor/listMenu/workingDays/index.js | 22 ++++++++++++++----- .../listMenu/workingDays/modal/index.js | 8 +++++-- .../panel/userAccount/bank/cards/index.js | 2 -- helper/index.js | 11 +++++++--- 7 files changed, 35 insertions(+), 22 deletions(-) diff --git a/components/clinic/components/about/ListBime.js b/components/clinic/components/about/ListBime.js index 3577f3e..b0e2ecf 100644 --- a/components/clinic/components/about/ListBime.js +++ b/components/clinic/components/about/ListBime.js @@ -8,8 +8,6 @@ function ListBime({ data, loading }) { const list = useRef(); const handleScroll = (type) => { - console.log(list); - list.current.scrollBy({ left: type === "left" ? -200 : 200, behavior: "smooth", diff --git a/components/panel/addDoctor/index.js b/components/panel/addDoctor/index.js index f48dc7d..2d2b006 100644 --- a/components/panel/addDoctor/index.js +++ b/components/panel/addDoctor/index.js @@ -9,7 +9,7 @@ import GeneralInformation from "./listMenu/generalInformation"; import Step from "./Step"; function AddDoctorPage() { - const [value, setValue] = useState(2); + const [value, setValue] = useState(0); const [data, setData] = useState({ general: { name: { value: "احسان احمدی", isEdit: false }, @@ -93,12 +93,7 @@ function AddDoctorPage() { setData={setData} setValue={setValue} />, - , + , ]; return ( diff --git a/components/panel/addDoctor/listMenu/workingDays/List.js b/components/panel/addDoctor/listMenu/workingDays/List.js index 1d626b4..17fca09 100644 --- a/components/panel/addDoctor/listMenu/workingDays/List.js +++ b/components/panel/addDoctor/listMenu/workingDays/List.js @@ -12,7 +12,7 @@ import { import ContentModal from "./modal"; import EditOrangeAD from "@/components/icons/EditOrangeAD"; -function List({ parent, data, setData }) { +function List({ parent, data, setData, setIsDisable }) { const [open, setOpen] = useState(false); const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); @@ -142,6 +142,7 @@ function List({ parent, data, setData }) { setData={setData} dataChange={dataChange} handleClose={handleClose} + setIsDisable={setIsDisable} /> ); diff --git a/components/panel/addDoctor/listMenu/workingDays/index.js b/components/panel/addDoctor/listMenu/workingDays/index.js index afba1de..27766f4 100644 --- a/components/panel/addDoctor/listMenu/workingDays/index.js +++ b/components/panel/addDoctor/listMenu/workingDays/index.js @@ -1,21 +1,33 @@ import { Button } from "@mui/material"; import List from "./List"; import ArrowLeftWhiteD from "@/components/icons/ArrowLeftWhiteD"; +import { useState } from "react"; + +function WorkingDays({ parent, data, setData }) { + const [isDisable, setIsDisable] = useState(true); -function WorkingDays({ setValue, parent, data, setData }) { return (

لیست روزهای کاری

- +
); diff --git a/components/panel/addDoctor/listMenu/workingDays/modal/index.js b/components/panel/addDoctor/listMenu/workingDays/modal/index.js index a85c4c9..dd7b6f8 100644 --- a/components/panel/addDoctor/listMenu/workingDays/modal/index.js +++ b/components/panel/addDoctor/listMenu/workingDays/modal/index.js @@ -3,7 +3,8 @@ import { styleDefault } from "@/mui"; import { Box, Button, Modal } from "@mui/material"; import Radios from "./Radios"; import Form from "./Form"; -import { useEffect, useState } from "react"; +import { useState } from "react"; +import { checkTimes } from "@/helper"; function ContentModal({ open, @@ -12,6 +13,7 @@ function ContentModal({ parent, dataChange, handleClose, + setIsDisable, }) { const [value, setValue] = useState(0); const [isVacation, setIsVacation] = useState(false); @@ -25,6 +27,8 @@ function ContentModal({ setIsVacation(valueRadio); setValue(valueRadio); + const disable = checkTimes(newData).includes(false); + !disable && setIsDisable(disable); }; const closeModal = () => { @@ -51,8 +55,8 @@ function ContentModal({
{data.map((item, idx) => ( diff --git a/helper/index.js b/helper/index.js index 11a2e8e..4008171 100644 --- a/helper/index.js +++ b/helper/index.js @@ -27,17 +27,22 @@ export const checkAllValues = (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; }; + +export const checkTimes = (arr) => { + return arr.map((day) => { + const hasMorningTime = day.morning_time.some((time) => time !== ""); + const hasEveningTime = day.evening_time.some((time) => time !== ""); + return hasMorningTime && hasEveningTime; + }); +};