Header.tsx 1.83 KB
Newer Older
1
import React from "react";
2
import { Link, useLocation } from "react-router-dom";
Yoon, Daeki's avatar
Yoon, Daeki committed
3
import { useAuth } from "../auth/auth.context";
4

Yoon, Daeki's avatar
Yoon, Daeki committed
5
6
export const Header = () => {
  const { user, logout } = useAuth();
7
  const location = useLocation();
Yoon, Daeki's avatar
Yoon, Daeki committed
8
9
10
11
12
13

  return (
    <div className="bg-white border-b-2 border-b-themeColor px-2 sm:px-4 py-2.5">
      <div className="container flex flex-wrap justify-between items-center mx-auto">
        <Link to="/" className="font-bold text-2xl text-themeColor">
          Simple Survey Form
14
        </Link>
Yoon, Daeki's avatar
Yoon, Daeki committed
15
16
        <div className="md:flex items-center justify-end md:flex-1 lg:w-0">
          {user.isLoggedIn ? (
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
            <div className="">
              <button
                onClick={() => logout()}
                className="whitespace-nowrap font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md"
              >
                로그아웃
              </button>
              {location.pathname === "/profile" ? (
                ""
              ) : (
                <Link
                  to="/profile"
                  className="whitespace-nowrap font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md"
                >
                  프로필
                </Link>
              )}
            </div>
Yoon, Daeki's avatar
Yoon, Daeki committed
35
          ) : (
36
37
38
39
40
41
42
43
44
45
46
47
48
49
            <div>
              <Link
                to="/login"
                className="whitespace-nowrap font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md"
              >
                로그인
              </Link>
              <Link
                to="/signup"
                className="whitespace-nowrap font-bold text-white hover:bg-blue-500 mx-1 py-2 px-3 bg-themeColor rounded-md "
              >
                회원가입
              </Link>
            </div>
Yoon, Daeki's avatar
Yoon, Daeki committed
50
51
          )}
        </div>
52
53
      </div>
    </div>
Yoon, Daeki's avatar
Yoon, Daeki committed
54
55
  );
};