1- import { useLocation , useNavigate } from "react-router-dom"
1+ import { useLocation , useNavigate } from "react-router-dom" ;
2+ import { useState } from "react" ;
23import useMbtiTestState from "@/store/useMbtiTestState" ;
3-
4+ import ActionConfirmModal from "@/components/modal/ActionConfirmModal" ;
45
56type SubHeaderProps = {
67 title : string ;
@@ -11,52 +12,83 @@ type SubHeaderProps = {
1112const SubHeader = ( {
1213 title = "" ,
1314 showPreviousIcon = true ,
14- showShareIcon = false ,
15+ showShareIcon = false
1516} : SubHeaderProps ) => {
16-
1717 const navigate = useNavigate ( ) ;
18- const { pathname} = useLocation ( ) ;
18+ const { pathname, state } = useLocation ( ) ;
1919 const { currentPage, setPreviousStep } = useMbtiTestState ( ) ;
20+ const [ isLeaveChatModalOpen , setIsLeaveChatModalOpen ] = useState ( false ) ;
21+
2022 const isProgressPage = pathname === "/mbti-test-progress" ;
2123 const isChatPage = pathname === "/chat" ;
2224 const isFirstQuestionPage = currentPage === 1 ;
23-
25+ const mode = state ?. mode ;
26+
2427 const handleGoBack = ( ) => {
25- if ( isProgressPage && ! isFirstQuestionPage ) setPreviousStep ( ) ;
26- else if ( isChatPage ) {
27- // 채팅 취소 모달 오픈 로직 추가 부탁드려요 헤헤 -> 4.9 정준영
28+ if ( isProgressPage && ! isFirstQuestionPage ) {
29+ setPreviousStep ( ) ;
30+ return ;
31+ }
32+
33+ if ( isChatPage ) {
34+ return mode === "fastFriend"
35+ ? setIsLeaveChatModalOpen ( true )
36+ : navigate ( "/" ) ;
37+ }
38+
39+ if ( isFirstQuestionPage ) {
40+ navigate ( - 1 ) ;
2841 }
29- else if ( isFirstQuestionPage ) navigate ( - 1 ) ;
3042 } ;
31-
43+
44+ const handleCancel = ( ) => setIsLeaveChatModalOpen ( false ) ;
45+
46+ const handleConfirm = ( ) => {
47+ setIsLeaveChatModalOpen ( false ) ;
48+ navigate ( "/" ) ;
49+ } ;
50+
3251 return (
33- < header className = "relative flex h-[56px] w-full flex-row items-center justify-center border-b border-gray-100 bg-white" >
34- { showPreviousIcon && (
35- < img
36- src = "/public/icon/arrow_left.svg"
37- alt = "Go To Back"
38- className = "absolute left-[18.77px] cursor-pointer"
39- width = { 9.87 }
40- height = { 16 }
41- onClick = { handleGoBack }
42- />
43- ) }
44-
45- < h1 className = "absolute left-1/2 -translate-x-1/2 transform text-[18px] font-bold text-gray-900" >
46- { title }
47- </ h1 >
48-
49- { showShareIcon && (
50- < img
51- src = "/public/icon/share.svg"
52- alt = "Share"
53- className = "absolute right-[20px] cursor-pointer"
54- width = { 16 }
55- height = { 16 }
56- />
57- ) }
58- </ header >
59- ) ;
60- }
61-
62- export default SubHeader ;
52+ < >
53+ < header className = "relative flex h-[56px] w-full flex-row items-center justify-center border-b border-gray-100 bg-white" >
54+ { showPreviousIcon && (
55+ < img
56+ src = "/public/icon/arrow_left.svg"
57+ alt = "Go To Back"
58+ className = "absolute left-[18.77px] cursor-pointer"
59+ width = { 9.87 }
60+ height = { 16 }
61+ onClick = { handleGoBack }
62+ />
63+ ) }
64+
65+ < h1 className = "absolute left-1/2 -translate-x-1/2 transform text-[18px] font-bold text-gray-900" >
66+ { title }
67+ </ h1 >
68+
69+ { showShareIcon && (
70+ < img
71+ src = "/public/icon/share.svg"
72+ alt = "Share"
73+ className = "absolute right-[20px] cursor-pointer"
74+ width = { 16 }
75+ height = { 16 }
76+ />
77+ ) }
78+ </ header >
79+
80+ { isLeaveChatModalOpen && (
81+ < ActionConfirmModal
82+ title = "채팅방 나가기"
83+ message = { [ "대화가 저장 되지않아요" , "정말 나갈까요?" ] }
84+ cancelText = "취소"
85+ confirmText = "확인"
86+ onCancel = { handleCancel }
87+ onConfirm = { handleConfirm }
88+ />
89+ ) }
90+ </ >
91+ ) ;
92+ } ;
93+
94+ export default SubHeader ;
0 commit comments