-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSubHeader.tsx
More file actions
107 lines (94 loc) · 2.78 KB
/
SubHeader.tsx
File metadata and controls
107 lines (94 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { useLocation, useNavigate } from "react-router-dom";
import { useState } from "react";
import useMbtiTestState from "@/store/useMbtiTestState";
import ActionConfirmModal from "@/components/modal/ActionConfirmModal";
import ShareModal from "@/components/modal/ShareModal";
type SubHeaderProps = {
title: string;
showPreviousIcon?: boolean;
showShareIcon?: boolean;
};
const SubHeader = ({
title = "",
showPreviousIcon = true,
showShareIcon = true
}: SubHeaderProps) => {
const navigate = useNavigate();
const { pathname, state } = useLocation();
const { currentPage, setPreviousStep } = useMbtiTestState();
const [isLeaveChatModalOpen, setIsLeaveChatModalOpen] = useState(false);
const [shareModalIsOpen, setShareModalIsOpen] = useState(false);
const isProgressPage = pathname === "/mbti-test-progress";
const isChatPage = pathname === "/chat";
const isFirstQuestionPage = currentPage === 1;
const mode = state?.mode;
const handleGoBack = () => {
if (isProgressPage && !isFirstQuestionPage) {
setPreviousStep();
return;
}
if (isChatPage) {
return mode === "fastFriend"
? setIsLeaveChatModalOpen(true)
: navigate("/");
}
if (isFirstQuestionPage) {
navigate(-1);
}
};
const handleCancel = () => setIsLeaveChatModalOpen(false);
const handleConfirm = () => {
setIsLeaveChatModalOpen(false);
navigate("/");
};
return (
<>
<header className="relative flex h-[56px] w-full items-center justify-between border-b border-gray-100 bg-white">
{showPreviousIcon && (
<img
src="/public/icon/arrow_left.svg"
alt="Go To Back"
className="absolute left-4 cursor-pointer"
width={9}
height={16}
onClick={handleGoBack}
/>
)}
<h1 className="absolute left-1/2 -translate-x-1/2 font-bold text-gray-900">
{title}
</h1>
{showShareIcon && (
<button
onClick={() => setShareModalIsOpen(true)}
className="absolute right-4"
>
<img
src="/public/icon/share.svg"
alt="Share"
width={16}
height={16}
/>
</button>
)}
</header>
{isLeaveChatModalOpen && (
<ActionConfirmModal
title="채팅방 나가기"
message={["대화가 저장 되지않아요", "정말 나갈까요?"]}
cancelText="취소"
confirmText="확인"
onCancel={handleCancel}
onConfirm={handleConfirm}
/>
)}
{shareModalIsOpen && (
<ShareModal
closeModal={() => {
setShareModalIsOpen(false);
}}
/>
)}
</>
);
};
export default SubHeader;