Header.tsx 2.1 KB
Newer Older
1
2
import React, { useState } from "react";
import { Link, useNavigate } from "react-router-dom";
3
import { useAuth } from "../auth";
Jiwon Yoon's avatar
Jiwon Yoon committed
4
import { LoginIcon, LogoutIcon, SurveyIcon, UserIcon } from "../icons";
5

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

  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
11
12
13
14
15
16
17
    <div className="flex items-center justify-between bg-white border-b-2 border-b-themeColor py-3.5">
      <Link to="/" className="font-bold text-2xl text-themeColor px-4">
        Simple Survey
      </Link>
      <div className="hidden md:flex">
        {user.isLoggedIn ? (
          <div>
18
19
20
21
22
            <Link to="/surveys">
              <button className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md">
                프로필
              </button>
            </Link>
Jiwon Yoon's avatar
Jiwon Yoon committed
23
24
25
26
27
28
29
30
31
32
33
34
            <button
              onClick={() => logout(() => navigate("/"))}
              className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md"
            >
              로그아웃
            </button>
          </div>
        ) : (
          <div>
            <Link to="/login">
              <button className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md">
                로그인
35
              </button>
Jiwon Yoon's avatar
Jiwon Yoon committed
36
37
38
39
40
41
42
43
44
            </Link>
            <Link to="/signup">
              <button className="font-bold text-white hover:bg-themeColor2 mx-1 py-2 px-3 bg-themeColor rounded-md ">
                회원가입
              </button>
            </Link>
          </div>
        )}
      </div>
45

Jiwon Yoon's avatar
Jiwon Yoon committed
46
47
48
49
      <div className="md:hidden">
        {user.isLoggedIn ? (
          <div className="flex px-4">
            <Link to="/surveys">
50
              <UserIcon className="h-7 w-7 mx-4" />
Jiwon Yoon's avatar
Jiwon Yoon committed
51
            </Link>
52
53
54
            <button onClick={() => logout(() => navigate("/"))}>
              <LogoutIcon className="h-7 w-7" />
            </button>
Jiwon Yoon's avatar
Jiwon Yoon committed
55
56
57
58
59
60
61
62
          </div>
        ) : (
          <div className="flex px-4">
            <Link to="/login">
              <LoginIcon className="h-7 w-7" />
            </Link>
          </div>
        )}
63
64
      </div>
    </div>
Yoon, Daeki's avatar
Yoon, Daeki committed
65
66
  );
};