Header.tsx 2.15 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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    <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>
            <button
              onClick={() => logout(() => navigate("/"))}
              className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md"
            >
              로그아웃
            </button>
            <Link to="/surveys">
              <button className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md">
                프로필
              </button>
            </Link>
          </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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
      <div className="md:hidden">
        {user.isLoggedIn ? (
          <div className="flex px-4">
            <button
              onClick={() => logout(() => navigate("/"))}
              className="mr-3"
            >
              <LogoutIcon className="h-7 w-7" />
            </button>
            <Link to="/surveys">
              <UserIcon className="h-7 w-7" />
            </Link>
          </div>
        ) : (
          <div className="flex px-4">
            <Link to="/login">
              <LoginIcon className="h-7 w-7" />
            </Link>
          </div>
        )}
66
67
      </div>
    </div>
Yoon, Daeki's avatar
Yoon, Daeki committed
68
69
  );
};