Header.tsx 1.71 KB
Newer Older
1
import React 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

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

  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
15
        </Link>
Yoon, Daeki's avatar
Yoon, Daeki committed
16
17
        <div className="md:flex items-center justify-end md:flex-1 lg:w-0">
          {user.isLoggedIn ? (
18
            <div>
19
              <button
Jiwon Yoon's avatar
Jiwon Yoon committed
20
                onClick={() => logout(() => navigate("/"))}
21
                className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md"
22
23
24
              >
                로그아웃
              </button>
25
26
              <Link to="/profile">
                <button className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md">
27
                  프로필
28
29
                </button>
              </Link>
30
            </div>
Yoon, Daeki's avatar
Yoon, Daeki committed
31
          ) : (
32
            <div>
33
34
35
36
              <Link to="/login">
                <button className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md">
                  로그인
                </button>
37
              </Link>
38
39
40
41
              <Link to="/signup">
                <button className="font-bold text-white hover:bg-blue-500 mx-1 py-2 px-3 bg-themeColor rounded-md ">
                  회원가입
                </button>
42
43
              </Link>
            </div>
Yoon, Daeki's avatar
Yoon, Daeki committed
44
45
          )}
        </div>
46
47
      </div>
    </div>
Yoon, Daeki's avatar
Yoon, Daeki committed
48
49
  );
};