Profile.js 1.75 KB
Newer Older
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
1
2
3
4
5
6
import { Link, useParams } from "react-router-dom";
import { useState, useEffect } from "react";
import userApi from "../../apis/user.api";

const userprofile = localStorage.getItem("user");
const INIT_PROFILE = {
Kim, Chaerin's avatar
Kim, Chaerin committed
7
  img: "",
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
8
};
이재연's avatar
이재연 committed
9

Kim, Chaerin's avatar
Kim, Chaerin committed
10
const Profile = () => {
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
11
12
13
14
15
  const [profile, setProfile] = useState(INIT_PROFILE);

  async function getProfile(userID) {
    try {
      const data = await userApi.getUser(userID);
Kim, Chaerin's avatar
Kim, Chaerin committed
16
      setProfile(data.img);
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
17
18
19
20
    } catch (error) {}
  }
  useEffect(() => {
    getProfile(userprofile);
Kim, Chaerin's avatar
Kim, Chaerin committed
21
  }, []);
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
22
23

  const { id } = useParams();
Kim, Chaerin's avatar
Kim, Chaerin committed
24

이재연's avatar
이재연 committed
25
  return (
이재연's avatar
이재연 committed
26
    <div className="container" style={{ background: "#FCF4FF" }}>
이재연's avatar
이재연 committed
27
28
29
30
      <>
        <div className="row">
          <form>
            <label
우지원's avatar
우지원 committed
31
              className="form-label mx-2 my-4"
이재연's avatar
이재연 committed
32
33
34
35
              style={{ fontSize: "18px", fontWeight: "bold" }}
            >
              프로필 정보
            </label>
이재연's avatar
이재연 committed
36
37
38
39
40
            <Link to={`/profile/${id}/update`}>
              <button
                type="button"
                className="btn btn-outline-white "
                style={{
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
41
                  background: "#d4cafb",
이재연's avatar
이재연 committed
42
43
44
45
46
47
48
                  fontSize: "13px",
                  fontWeight: "bold",
                }}
              >
                수정
              </button>
            </Link>
이재연's avatar
이재연 committed
49
50
51
          </form>
          <div className="col"></div>
          <div className="col">
52
53
            <div className="d-flex justify-content-center">
              <img
Kim, Chaerin's avatar
Kim, Chaerin committed
54
                alt="profileImg"
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
55
                src={`/uploads/${profile}`}
이재연's avatar
이재연 committed
56
                className="rounded-circle mt-2"
57
58
59
                style={{ height: "320px", width: "320px" }}
              />
            </div>
이재연's avatar
이재연 committed
60
61
          </div>
          <div className="col"></div>
Kim, Chaerin's avatar
Kim, Chaerin committed
62
        </div>
이재연's avatar
이재연 committed
63
64
65
      </>
    </div>
  );
Kim, Chaerin's avatar
Kim, Chaerin committed
66
67
68
};

export default Profile;