Header.tsx 5.86 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

jang dong hyeok's avatar
jang dong hyeok committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  const [windowSize, setWindowSize] = useState({
    width: window.innerWidth,
    height: window.innerHeight,
  });

  const handleResize = () => {
    setWindowSize({
      width: window.innerWidth,
      height: window.innerHeight,
    });
  };
  useEffect(() => {
    window.addEventListener("resize", handleResize);
    return () => {
      window.removeEventListener("resize", handleResize);
    };
  }, []);

Yoon, Daeki's avatar
Yoon, Daeki committed
29
30
  return (
    <div className="bg-white border-b-2 border-b-themeColor px-2 sm:px-4 py-2.5">
jang dong hyeok's avatar
jang dong hyeok committed
31
      <div className="container flex flex-wrap place-content-center mx-auto">
Yoon, Daeki's avatar
Yoon, Daeki committed
32
33
        <Link to="/" className="font-bold text-2xl text-themeColor">
          Simple Survey Form
34
        </Link>
jang dong hyeok's avatar
jang dong hyeok committed
35
36
37
38
39
40
41
42
43
44
45
        {windowSize.width < 768 ? (
          <UserIcon className="h-7 w-7 absolute top-4 right-2" onClick="" />
        ) : (
          <div className="md:flex items-center justify-end md:flex-1 lg:w-0">
            {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"
                >
                  로그아웃
46
                </button>
jang dong hyeok's avatar
jang dong hyeok committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
                <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 ">
                    회원가입
                  </button>
                </Link>
              </div>
            )}
          </div>
        )}
        {/* <div className="flex items-center md:order-2">
          <button
            type="button"
            className="flex mr-3 text-sm bg-gray-800 rounded-full md:mr-0 focus:ring-4 focus:ring-gray-300 dark:focus:ring-gray-600"
            id="user-menu-button"
            aria-expanded="false"
            data-dropdown-toggle="user-dropdown"
            data-dropdown-placement="bottom"
          >
            <span className="sr-only">Open user menu</span>
            <img
              className="w-8 h-8 rounded-full"
              src="/docs/images/people/profile-picture-3.jpg"
              alt="user photo"
            />
          </button>
          <div
            className="hidden z-50 my-4 text-base list-none bg-white rounded divide-y divide-gray-100 shadow dark:bg-gray-700 dark:divide-gray-600"
            id="user-dropdown"
          >
            <div className="py-3 px-4">
              <span className="block text-sm text-gray-900 dark:text-white">
                Bonnie Green
              </span>
              <span className="block text-sm font-medium text-gray-500 truncate dark:text-gray-400">
                name@flowbite.com
              </span>
96
            </div>
jang dong hyeok's avatar
jang dong hyeok committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
            <ul className="py-1" aria-labelledby="user-menu-button">
              <li>
                <a
                  href="#"
                  className="block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
                >
                  Dashboard
                </a>
              </li>
              <li>
                <a
                  href="#"
                  className="block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
                >
                  Settings
                </a>
              </li>
              <li>
                <a
                  href="#"
                  className="block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
                >
                  Earnings
                </a>
              </li>
              <li>
                <a
                  href="#"
                  className="block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white"
                >
                  Sign out
                </a>
              </li>
            </ul>
          </div>
          <button
            data-collapse-toggle="mobile-menu-2"
            type="button"
            className="inline-flex items-center p-2 ml-1 text-sm text-gray-500 rounded-lg md:hidden hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-gray-200"
            aria-controls="mobile-menu-2"
            aria-expanded="false"
          >
            <span className="sr-only">Open main menu</span>
            <UserIcon className="w-7 h-7 absolute top-4 right-2" />
            <svg
              className="w-6 h-6"
              aria-hidden="true"
              fill="currentColor"
              viewBox="0 0 20 20"
              xmlns="http://www.w3.org/2000/svg"
            >
              <path
                fill-rule="evenodd"
                d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 15a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z"
                clip-rule="evenodd"
              ></path>
            </svg>
          </button>
        </div> */}
156
157
      </div>
    </div>
Yoon, Daeki's avatar
Yoon, Daeki committed
158
159
  );
};