StudyPlanPage.js 1.21 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import { useState, useEffect } from "react";
Choi Ga Young's avatar
Choi Ga Young committed
2
import { useParams } from "react-router-dom";
Kim, Subin's avatar
Kim, Subin committed
3
4
5
import Menu from "../components/Menu/Menu";
import BackBtn from "../components/Buttons/BackBtn";
import AddplanList from "../components/StudyPlan/AddplanList";
Kim, Subin's avatar
Kim, Subin committed
6
7
8
9
import Footer from "../components/Footer";
import subjectApi from "../apis/subject.api";
import catchErrors from "../utils/catchErrors";
import { useAuth } from "../utils/context";
10

11
const StudyPlanPage = () => {
Kim, Subin's avatar
Kim, Subin committed
12
13
14
    const { user } = useAuth()
    const [planList, setPlanList] = useState({})
    const [error, setError] = useState("");
Choi Ga Young's avatar
Choi Ga Young committed
15
    const { subjectId } = useParams();
Kim, Subin's avatar
Kim, Subin committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

    useEffect(() => {
        getPlanList()
    }, [])

    async function getPlanList() {
        try {
            setError("")
            const res = await subjectApi.allSubject(user.id, subjectId)
            setPlanList(res[0])
        } catch (error) {
            catchErrors(error, setError)
        }
    }

31
    return (
32
33
34
        <>
            <Menu />
            <BackBtn />
Kim, Subin's avatar
Kim, Subin committed
35
36
37
            <h2 className="text-center">{planList.name}</h2>
            <AddplanList planList={planList} />
            <Footer pathname={`studyplan/submit/${subjectId}`} />
38
        </>
39
40
41
42
    )
}

export default StudyPlanPage