Header.tsx 4.17 KB
Newer Older
jang dong hyeok's avatar
jang dong hyeok committed
1
import React, { useEffect, useState } from "react";
Jiwon Yoon's avatar
Jiwon Yoon committed
2
import { Link, useLocation, useNavigate } from "react-router-dom";
Yoon, Daeki's avatar
Yoon, Daeki committed
3
import { useAuth } from "../auth/auth.context";
4
import { UserIcon } from "../icons";
5

Yoon, Daeki's avatar
Yoon, Daeki committed
6
7
export const Header = () => {
  const { user, logout } = useAuth();
8
  const location = useLocation();
Jiwon Yoon's avatar
Jiwon Yoon committed
9
  const navigate = useNavigate();
Yoon, Daeki's avatar
Yoon, Daeki committed
10

11
12
13
14
15
16
  const [isClicked, setIsClicked] = useState(false);

  const handleHeaderClick = () => {
    setIsClicked(!isClicked);
  };

Yoon, Daeki's avatar
Yoon, Daeki committed
17
  return (
18
    <div className="bg-white border-b-2 border-b-themeColor px-2 sm:px-4 py-3.5">
jang dong hyeok's avatar
jang dong hyeok committed
19
      <div className="container flex flex-wrap place-content-center mx-auto">
jang dong hyeok's avatar
jang dong hyeok committed
20
21
22
23
        <Link
          to="/"
          className="font-bold text-2xl text-themeColor justify-center"
        >
Yoon, Daeki's avatar
Yoon, Daeki committed
24
          Simple Survey Form
25
        </Link>
jang dong hyeok's avatar
jang dong hyeok committed
26
        <div className="absolute right-4 top-2 hidden md:flex items-center justify-end md:flex-1">
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
          {user.isLoggedIn ? (
            <div className="pt-2">
              <button
                onClick={() => logout(() => navigate("/"))}
                className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md"
              >
                로그아웃
              </button>
              <Link to="/profile">
                <button className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md">
                  프로필
                </button>
              </Link>
            </div>
          ) : (
            <div className="pt-2">
              <Link to="/login">
                <button className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md">
                  로그인
                </button>
              </Link>
              <Link to="/signup">
                <button className="font-bold text-white hover:bg-blue-500 mx-1 py-2 px-3 bg-themeColor rounded-md ">
                  회원가입
51
                </button>
52
53
54
55
56
57
58
59
60
61
62
63
              </Link>
            </div>
          )}
        </div>

        <button
          className="flex md:hidden w-8 h-8 rounded-full absolute top-4 right-5"
          onClick={handleHeaderClick}
        >
          <UserIcon />
          {isClicked ? (
            user.isLoggedIn ? (
jang dong hyeok's avatar
jang dong hyeok committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
              <div className="fixed top-14 justify-center right-1 w-48 h-40 bg-themeColor3 flex flex-col rounded-lg place-content-between">
                <div className="p-1 place-self-center">안녕하세요.</div>
                <div className="p-1 place-self-center">
                  만들어진 설문을 확인하시려면 프로필을 눌러주세요.
                </div>
                <div className="flex border-themeColor border-t-2">
                  <Link to="/login">
                    <div
                      className="p-1 w-24 border-r-2 border-themeColor text-center text-l text-gray-600 hover:text-themeColor"
                      onClick={() => logout(() => navigate("/"))}
                    >
                      로그아웃
                    </div>
                  </Link>
                  <Link to="/profile">
                    <div className="p-1 w-24 text-center text-l text-gray-600 hover:text-themeColor">
                      프로필
                    </div>
                  </Link>
                </div>
jang dong hyeok's avatar
jang dong hyeok committed
84
85
              </div>
            ) : (
jang dong hyeok's avatar
jang dong hyeok committed
86
87
88
89
90
91
              <div className="fixed top-14 right-1 w-48 h-40 bg-themeColor3 flex flex-col  place-content-between">
                <div className="p-1">로그아웃 상태입니다.</div>
                <div className="p-1">설문지를 만드시려면 로그인해주세요.</div>
                <div className="flex ">
                  <Link to="/login">
                    <div className="p-1 w-24 justify-center text-l text-gray-600 hover:text-themeColor">
92
93
                      로그인
                    </div>
jang dong hyeok's avatar
jang dong hyeok committed
94
95
96
97
98
99
100
                  </Link>
                  <Link to="/signup">
                    <div className="p-1 w-24 justify-center text-l text-gray-600 hover:text-themeColor">
                      회원가입
                    </div>
                  </Link>
                </div>
jang dong hyeok's avatar
jang dong hyeok committed
101
              </div>
102
103
104
105
106
            )
          ) : (
            <></>
          )}
        </button>
107
108
      </div>
    </div>
Yoon, Daeki's avatar
Yoon, Daeki committed
109
110
  );
};