@@ -2,22 +2,80 @@ import logo from '@/assets/icons/logo.svg';
22import sad from '@/assets/icons/sad-icon.svg' ;
33import MusicAnimation from './MusicAnimation' ;
44import Button from './Button' ;
5+ import { useSheetStore } from '@/store/sheetStore' ;
6+ import { useEffect , useState } from 'react' ;
7+ import dayjs from 'dayjs' ;
8+ import duration from 'dayjs/plugin/duration' ;
9+ import { cancelChatRequest } from '@/apis/chat' ;
10+ import { useNavigate } from 'react-router' ;
11+ dayjs . extend ( duration ) ;
512
613export default function ChatConnectLoadingSheet ( ) {
14+ const navigate = useNavigate ( ) ;
715 //zustand로 관리
816 //거절, 취소하거나 홈으로 가기 누르면 false로
9- const isConnecting = false ;
17+ const { currentRecord , closeAllSheets , closeSheet } = useSheetStore ( ) ;
1018
11- const isFail = false ;
12- const isReceiver = true ;
13- if ( ! isConnecting ) return null ;
14- if ( isFail ) {
19+ const [ timeLeft , setTimeLeft ] = useState ( 60 ) ;
20+
21+ const [ connetFail , setConnectFail ] = useState ( false ) ;
22+
23+ const handleClickToHome = ( ) => {
24+ closeAllSheets ( ) ;
25+ navigate ( '/home' ) ;
26+ } ;
27+
28+ useEffect ( ( ) => {
29+ const endTime = new Date ( ) . getTime ( ) + 60 * 1000 ; // 현재 시간 + 60초
30+
31+ const interval = setInterval ( ( ) => {
32+ const diff = Math . max ( 0 , Math . ceil ( ( endTime - new Date ( ) . getTime ( ) ) / 1000 ) ) ; // 남은 초 계산
33+
34+ setTimeLeft ( diff ) ;
35+
36+ if ( diff <= 0 ) {
37+ clearInterval ( interval ) ;
38+ setTimeLeft ( 0 ) ; // 0초로 고정
39+ }
40+ } , 1000 ) ;
41+
42+ return ( ) => clearInterval ( interval ) ; //interval 정리
43+ } , [ ] ) ;
44+
45+ useEffect ( ( ) => {
46+ if ( timeLeft === 0 ) {
47+ setConnectFail ( true ) ;
48+ }
49+ } , [ timeLeft ] ) ;
50+
51+ const formattedTime = dayjs . duration ( timeLeft , 'seconds' ) . format ( 'mm:ss' ) ;
52+
53+ //채팅 요청 취소
54+ const cancel = async ( ) => {
55+ console . log ( currentRecord ) ;
56+ if ( ! currentRecord ) {
57+ console . log ( 'record가 존재하지 않습니다' ) ;
58+ return ;
59+ }
60+ try {
61+ await cancelChatRequest ( currentRecord . recordId ) ;
62+ console . log ( '채팅 취소' ) ;
63+
64+ closeSheet ( 'isChatLoadingSheetOpen' ) ;
65+ } catch ( error ) {
66+ console . log ( error ) ;
67+ }
68+ } ;
69+
70+ const isReceiver = false ;
71+
72+ if ( connetFail ) {
1573 return (
1674 < div className = "fixed inset-0 flex justify-center items-center z-50" >
1775 < div className = "relative w-full max-w-[600px] h-screen px-3 bg-background flex flex-col justify-center items-center" >
1876 < img src = { logo } className = "w-[186px] h-[40px] mb-5" alt = "로고" />
1977 < p className = "h4-b text-center text-gray-50 mb-2" >
20- < span className = "text-primary-normal" > 하입뽀이일곱자 </ span >
78+ < span className = "text-primary-normal" > { currentRecord ?. nickName } </ span >
2179 < span > 님과 연결되지 않았어요</ span >
2280 </ p >
2381
@@ -27,7 +85,9 @@ export default function ChatConnectLoadingSheet() {
2785 < img src = { sad } alt = "연결실패" />
2886
2987 < div className = "absolute bottom-10 flex gap-[6px] px-3 w-full" >
30- < Button variant = "primary" > 홈으로 가기</ Button >
88+ < Button onClick = { handleClickToHome } variant = "primary" >
89+ 홈으로 가기
90+ </ Button >
3191 </ div >
3292 </ div >
3393 </ div >
@@ -38,9 +98,15 @@ export default function ChatConnectLoadingSheet() {
3898 < div className = "relative w-full max-w-[600px] h-screen px-3 bg-background flex flex-col justify-center items-center" >
3999 < img src = { logo } className = "w-[186px] h-[40px] mb-5" alt = "로고" />
40100 < p className = "h4-b text-center text-gray-50 mb-2" >
41- < span className = "text-primary-normal" > 하입뽀이일곱자</ span >
42101 { /* 요청하는 사람일 결우 */ }
43- { ! isReceiver && < span > 님에게 대화 요청 중...</ span > }
102+ { ! isReceiver && (
103+ < span >
104+ < span className = "text-primary-normal" > { currentRecord ?. nickName } </ span > 님에게 대화 요청
105+ 중...
106+ </ span >
107+ ) }
108+ { /* 받는 사람일 경우 */ }
109+ { isReceiver && < span className = "text-primary-normal" > 보내는 사람</ span > }
44110 </ p >
45111 { /* 요청하는 사람일 결우 */ }
46112 { ! isReceiver && (
@@ -51,15 +117,18 @@ export default function ChatConnectLoadingSheet() {
51117 { /* 받는 사람일 경우 */ }
52118 { isReceiver && (
53119 < p className = "caption-r text-center text-gray-60 mb-5" >
54- < span > 하입뽀이일곱자 </ span > 님이 대화를 요청했어요 < br /> 함께 이야기해 볼까요?
120+ < span > 보내는 사람 </ span > 님이 대화를 요청했어요 < br /> 함께 이야기해 볼까요?
55121 </ p >
56122 ) }
57123
58124 < MusicAnimation />
59- < p className = "body-large-b text-primary-normal mt-[120px] mb-2" > 03:00 </ p >
125+ < p className = "body-large-b text-primary-normal mt-[120px] mb-2" > { formattedTime } </ p >
60126 { /* 요청하는 사람일 결우 */ }
61127 { ! isReceiver && (
62- < button className = "caption-r text-gray-50 cursor-pointer border-b border-gray-50" >
128+ < button
129+ onClick = { cancel }
130+ className = "caption-r text-gray-50 cursor-pointer border-b border-gray-50"
131+ >
63132 취소하기
64133 </ button >
65134 ) }
0 commit comments