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

const userprofile = localStorage.getItem("user");
const INIT_PROFILE = {
  img:"",
};
이재연's avatar
이재연 committed
10

Kim, Chaerin's avatar
Kim, Chaerin committed
11
const Profile = () => {
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
12
13
  
  const [profile, setProfile] = useState(INIT_PROFILE);
14
  const [error,setError]= useState("");
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
15
16
17
18
19
  async function getProfile(userID) {
    try {
      const data = await userApi.getUser(userID);
      setProfile(data.img)
      
20
21
22
    } catch (error) {
      catchErrors(error, setError);
    }
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
23
24
25
26
27
28
29
30
  }
  useEffect(() => {
    getProfile(userprofile);
  }, [userprofile]);


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

export default Profile;