SubjectForm.js 2.08 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { useState, useEffect } from 'react';
import BtnGroup from "../Buttons/BtnGroup";
import styles from "./form.module.scss";

const SubjectForm = () => {
  const [subject, setSubject] = useState({
    lectureName: "",
    prof: "",
    classRoom: ""
  })
  const [disabled, setDisabled] = useState(true)

  useEffect(() => {
    let isMounted = true;
    const checkInfo = { lectureName: subject.lectureName, prof: subject.prof, classRoom: subject.classRoom }

    if (isMounted) {
      const isSubject = Object.values(checkInfo).every((el) => Boolean(el));
      isSubject ? setDisabled(false) : setDisabled(true);
    }
    return () => {
      isMounted = false;
    }
  }, [subject])

  function handleChange(e) {
    const { name, value } = e.target
    setSubject({ ...subject, [name]: value })

  }
  return (
    <>
      <div className="position-absolute top-50 start-50 translate-middle" style={{ width: "80%" }}>
        <div>
          <div className="mb-5 d-flex flex-row">
            <label className="form-label fs-4" style={{ width: "100px" }}>강의명</label>
            <input className="form-control border-top-0 border-end-0 border-start-0" style={{ boxShadow: "none", borderRadius: "0" }} name="lectureName" onChange={handleChange} />
          </div>
Choi Ga Young's avatar
Choi Ga Young committed
39
          <div className="mb-5 pt-2 d-flex flex-row">
40
41
42
            <label className="form-label fs-4" style={{ width: "100px" }}>교수명</label>
            <input className="form-control border-top-0 border-end-0 border-start-0" style={{ boxShadow: "none", borderRadius: "0" }} name="prof" onChange={handleChange} />
          </div>
Choi Ga Young's avatar
Choi Ga Young committed
43
44
          <div className="mb-5 pt-2 d-flex flex-row">
            <label className="form-label fs-4 " style={{ width: "100px" }}>&nbsp;&nbsp;</label>
45
46
47
            <input className="form-control border-top-0 border-end-0 border-start-0" style={{ boxShadow: "none", borderRadius: "0" }} name="classRoom" onChange={handleChange} />
          </div>
        </div>
Choi Ga Young's avatar
Choi Ga Young committed
48
49
50
        <div className="pt-2">
          <BtnGroup disabled={disabled} />
        </div>
51
52
53
54
55
56
      </div>
    </>
  )
}

export default SubjectForm;