Info.js 1.69 KB
Newer Older
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
1
2
import userApi from "../../apis/user.api";
import { useEffect, useState } from "react";
Kim, Chaerin's avatar
Kim, Chaerin committed
3
import catchErrors from "../../context/catchError";
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
4
5
6
7
8
9
10
11

const userprofile = localStorage.getItem("user");
const INIT_PROFILE = {
  name: "",
  email: "a",
  id: "",
  phone: "",
};
이재연's avatar
이재연 committed
12

Kim, Chaerin's avatar
Kim, Chaerin committed
13
const Info = () => {
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
14
  const [profile, setProfile] = useState(INIT_PROFILE);
Kim, Chaerin's avatar
Kim, Chaerin committed
15
  const [error, setError]= useState("");
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
16
17
18
19
20

  async function getProfile(userID) {
    try {
      const data = await userApi.getUser(userID);
      setProfile(data);
Kim, Chaerin's avatar
Kim, Chaerin committed
21
22
23
    } catch (error) {
      catchErrors(error, setError);
    }
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
24
25
26
27
28
  }
  useEffect(() => {
    getProfile(userprofile);
  }, [userprofile]);

이재연's avatar
이재연 committed
29
  return (
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
30
    
이재연's avatar
이재연 committed
31
    <div className="container" style={{ background: "#FCF4FF" }}>
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
32
      
이재연's avatar
이재연 committed
33
      <div
이재연's avatar
이재연 committed
34
        className="row justify-content-center  my-4"
이재연's avatar
이재연 committed
35
36
        style={{ fontSize: "25px", fontWeight: "bold" }}
      >
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
37
        {profile.email} #{profile.id}
이재연's avatar
이재연 committed
38
39
40
      </div>
      <div className="row">
        <div className="col-3"></div>
이재연's avatar
이재연 committed
41
        <div className="col-6 my-2">
이재연's avatar
이재연 committed
42
43
44
          <h2 className="mb-3" style={{ fontSize: "13px", fontWeight: "bold" }}>
            이름
          </h2>
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
45
46
47
48
49
50
          <h2
            className="mb-4 mt-2"
            style={{ fontSize: "25px", fontWeight: "bold" }}
          >
            {profile.name}
          </h2>
이재연's avatar
이재연 committed
51
52
53
54
55
56
          <h2
            className="mb-3 mt-2"
            style={{ fontSize: "13px", fontWeight: "bold" }}
          >
            전화번호
          </h2>
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
57
58
59
60
61
62
          <h2
            className="mb-3 mt-2"
            style={{ fontSize: "25px", fontWeight: "bold" }}
          >
            {profile.phone}
          </h2>
Kim, Chaerin's avatar
Kim, Chaerin committed
63
        </div>
이재연's avatar
이재연 committed
64
65
66
67
        <div className="col"></div>
      </div>
    </div>
  );
Kim, Chaerin's avatar
Kim, Chaerin committed
68
69
70
};

export default Info;