"question.txt" did not exist on "95be2e8bb3836ee06a8959848af4264fbe38f4dd"
Header.tsx 4.07 KB
Newer Older
1
2
import React, { useState } from "react";
import { Link, useNavigate } from "react-router-dom";
3
import { useAuth } from "../auth";
4
import { 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
  const [isClicked, setIsClicked] = useState(false);
jang dong hyeok's avatar
jang dong hyeok committed
11

12
13
  const handleHeaderClick = () => {
    setIsClicked(!isClicked);
jang dong hyeok's avatar
jang dong hyeok committed
14
15
  };

Yoon, Daeki's avatar
Yoon, Daeki committed
16
  return (
17
    <div className="bg-white border-b-2 border-b-themeColor px-2 sm:px-4 py-3.5">
18
19
      <div className="container flex flex-wrap md:justify-start place-content-center mx-auto">
        <Link to="/" className="font-bold text-2xl text-themeColor text-start">
20
          Simple Survey
21
        </Link>
jang dong hyeok's avatar
jang dong hyeok committed
22
        <div className="absolute right-4 top-2 hidden md:flex items-center justify-end md:flex-1">
23
          {user.isLoggedIn ? (
24
            <div>
25
26
27
28
29
30
              <button
                onClick={() => logout(() => navigate("/"))}
                className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md"
              >
                로그아웃
              </button>
31
              <Link to="/surveys">
32
33
                <button className="font-bold text-gray-600 hover:text-themeColor mx-1 py-2 px-3 rounded-md">
                  프로필
34
                </button>
35
36
37
              </Link>
            </div>
          ) : (
38
            <div>
39
40
41
42
43
44
              <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">
45
                <button className="font-bold text-white hover:bg-themeColor2 mx-1 py-2 px-3 bg-themeColor rounded-md ">
46
                  회원가입
47
                </button>
48
49
50
51
52
53
54
55
56
57
58
59
              </Link>
            </div>
          )}
        </div>

        <button
          className="flex md:hidden w-8 h-8 rounded-full absolute top-4 right-5"
          onClick={handleHeaderClick}
        >
          <UserIcon />
          {isClicked ? (
            user.isLoggedIn ? (
60
61
62
              <div className="fixed top-14 right-1 w-48 bg-themeColor3 flex flex-col rounded-lg">
                <div className="p-3">안녕하세요.</div>
                <div className="pl-3 pr-3 pb-3">
jang dong hyeok's avatar
jang dong hyeok committed
63
64
65
66
67
                  만들어진 설문을 확인하시려면 프로필을 눌러주세요.
                </div>
                <div className="flex border-themeColor border-t-2">
                  <Link to="/login">
                    <div
68
                      className="p-2 w-24 border-r-2 border-themeColor text-center text-l text-gray-600 hover:text-themeColor"
jang dong hyeok's avatar
jang dong hyeok committed
69
70
71
72
73
                      onClick={() => logout(() => navigate("/"))}
                    >
                      로그아웃
                    </div>
                  </Link>
74
                  <Link to="/surveys">
75
                    <div className="p-2 w-24 text-center text-l text-gray-600 hover:text-themeColor">
jang dong hyeok's avatar
jang dong hyeok committed
76
77
78
79
                      프로필
                    </div>
                  </Link>
                </div>
jang dong hyeok's avatar
jang dong hyeok committed
80
81
              </div>
            ) : (
82
83
84
85
86
87
              <div className="fixed top-14 right-1 w-48 bg-themeColor3 flex flex-col rounded-lg">
                <div className="p-3">로그아웃 상태입니다.</div>
                <div className="pl-3 pr-3 pb-3">
                  설문지를 만드시려면 로그인해주세요.
                </div>
                <div className="flex border-themeColor border-t-2">
jang dong hyeok's avatar
jang dong hyeok committed
88
                  <Link to="/login">
89
                    <div className="p-2 w-24 border-r-2 border-themeColor justify-center text-l text-gray-600 hover:text-themeColor">
90
91
                      로그인
                    </div>
jang dong hyeok's avatar
jang dong hyeok committed
92
93
                  </Link>
                  <Link to="/signup">
94
                    <div className="p-2 w-24 justify-center text-l text-gray-600 hover:text-themeColor">
jang dong hyeok's avatar
jang dong hyeok committed
95
96
97
98
                      회원가입
                    </div>
                  </Link>
                </div>
jang dong hyeok's avatar
jang dong hyeok committed
99
              </div>
100
101
102
103
104
            )
          ) : (
            <></>
          )}
        </button>
105
106
      </div>
    </div>
Yoon, Daeki's avatar
Yoon, Daeki committed
107
108
  );
};