import { useState, useEffect } from 'react'; import BtnGroup from "../Buttons/BtnGroup"; import styles from "./form.module.scss"; const StudyPlanEditForm = () => { const [studyplan, setStudyplan] = useState({ studyplanTitle: "", endDate: "", deadline: "", memo: "" }) const [disabled, setDisabled] = useState(true) useEffect(() => { let isMounted = true; const checkInfo = { studyplanTitle: studyplan.studyplanTitle, endDate: studyplan.endDate, memo: studyplan.memo } if (studyplan.deadline !== "on") { checkInfo.endTime = studyplan.endTime } else { delete checkInfo.endTime } if (isMounted) { const isStudyPlan = Object.values(checkInfo).every((el) => Boolean(el)); isStudyPlan ? setDisabled(false) : setDisabled(true); } return () => { isMounted = false; } }, [studyplan]) function handleChange(e) { const { name, value } = e.target if (name === "deadline") { studyplan.deadline !== "on" ? setStudyplan({ ...studyplan, [name]: value }) : setStudyplan({ ...studyplan, [name]: "off" }) } else { setStudyplan({ ...studyplan, [name]: value }) } } return ( <>
) } export default StudyPlanEditForm