@@ -7,18 +7,15 @@ import { Flex } from '@components/shared/Flex';
7
7
import { Image } from '@components/shared/Image' ;
8
8
import { Text } from '@components/shared/Text' ;
9
9
10
- import { useCreatePersonalChatRoomMutation } from '@hooks/mutations/useCreatePersonalChatRoomMutation' ;
11
- import { useAllChatRoomListQuery } from '@hooks/queries/useAllChatRoomListQuery' ;
12
10
import { useMemberProfileQuery } from '@hooks/queries/useMemberProfileQuery' ;
13
- import { usePersonalChatRoomExistedQuery } from '@hooks/queries/usePersonalChatRoomExistedQuery ' ;
11
+ import { useChatOnButtonClick } from '@hooks/useChatOnButtonClick ' ;
14
12
15
13
import { theme } from '@styles/theme' ;
16
14
17
15
import { useLoginInfoStore } from '@stores/loginInfo.store' ;
18
16
19
17
import { Member } from '@type/models' ;
20
18
21
- import { CHAT_ROOM_TAB_TITLE } from '@consts/chatRoomTabTitle' ;
22
19
import { PATH_NAME } from '@consts/pathName' ;
23
20
24
21
import Social from '@assets/follow.svg?react' ;
@@ -55,17 +52,10 @@ type NumberedItemProps = {
55
52
} ;
56
53
57
54
export const Profile = ( { memberId } : { memberId : Member [ 'id' ] } ) => {
58
- const myId = useLoginInfoStore ( ( state ) => state . loginInfo ?. id ) ;
55
+ const myId = useLoginInfoStore ( ( state ) => state . loginInfo ?. id ) ?? null ;
59
56
const navigate = useNavigate ( ) ;
60
57
61
- const { data : profileData } = useMemberProfileQuery ( { memberId } ) ;
62
- const { data : isChatExisted } = usePersonalChatRoomExistedQuery ( {
63
- receiverId : memberId ,
64
- } ) ;
65
- const { data : individualRooms } = useAllChatRoomListQuery ( {
66
- type : CHAT_ROOM_TAB_TITLE . INDIVIDUAL ,
67
- } ) ;
68
- const { mutateAsync } = useCreatePersonalChatRoomMutation ( ) ;
58
+ const { data : profile } = useMemberProfileQuery ( { memberId } ) ;
69
59
70
60
const [ isHeartClicked , setIsHeartClicked ] = useState ( false ) ;
71
61
@@ -77,34 +67,27 @@ export const Profile = ({ memberId }: { memberId: Member['id'] }) => {
77
67
navigate ( path ) ;
78
68
} ;
79
69
80
- const handleClickChattingButton = async ( ) => {
81
- if ( ! isChatExisted ?. existed ) {
82
- const { id : roomId } = await mutateAsync ( { receiverId : memberId } ) ;
83
-
84
- moveToPage ( PATH_NAME . GET_CHAT_PATH ( String ( roomId ) ) ) ;
85
- } else {
86
- const { id : roomId } = individualRooms . find (
87
- ( { roomName } ) => roomName === profileData . nickname
88
- ) ! ;
89
-
90
- moveToPage ( PATH_NAME . GET_CHAT_PATH ( String ( roomId ) ) ) ;
91
- }
92
- } ;
70
+ const { handleClickChattingButton } = useChatOnButtonClick ( {
71
+ targetId : memberId ,
72
+ targetNickname : profile . nickname ,
73
+ navigate,
74
+ myId,
75
+ } ) ;
93
76
94
77
return (
95
78
< Main >
96
79
< FlexItem >
97
80
< Flex align = "flex-end" gap = { 8 } >
98
81
< Text size = { 24 } lineHeight = "" >
99
- { profileData . nickname }
82
+ { profile . nickname }
100
83
</ Text >
101
84
< Text size = { 12 } >
102
- { profileData . addressDepth1 + ' ' + profileData . addressDepth2 }
85
+ { profile . addressDepth1 + ' ' + profile . addressDepth2 }
103
86
</ Text >
104
87
</ Flex >
105
88
< Flex justify = "center" gap = { 40 } align = "center" >
106
89
< Avatar
107
- src = { profileData . profileImageUrl }
90
+ src = { profile . profileImageUrl }
108
91
size = { 100 }
109
92
border = { `1px solid ${ theme . PALETTE . GRAY_400 } ` }
110
93
/>
@@ -115,13 +98,13 @@ export const Profile = ({ memberId }: { memberId: Member['id'] }) => {
115
98
< NumberedItem
116
99
text = "매너스코어"
117
100
icon = { < Heart /> }
118
- count = { profileData . mannerScore }
101
+ count = { profile . mannerScore }
119
102
color = "pink"
120
103
/>
121
104
< NumberedItem
122
105
text = "평가한 사람"
123
106
icon = { < HandHeart /> }
124
- count = { profileData . mannerScoreCount }
107
+ count = { profile . mannerScoreCount }
125
108
color = "black"
126
109
/>
127
110
</ NumberedItemWrapper >
@@ -140,16 +123,16 @@ export const Profile = ({ memberId }: { memberId: Member['id'] }) => {
140
123
</ Flex >
141
124
) }
142
125
< ProfileField category = "포지션" >
143
- { profileData . positions . length
144
- ? profileData . positions . map ( ( position ) => (
126
+ { profile . positions . length
127
+ ? profile . positions . map ( ( position ) => (
145
128
< ItemBox key = { position } > { position } </ ItemBox >
146
129
) )
147
130
: '없음' }
148
131
</ ProfileField >
149
132
< ProfileField category = "소속 크루" >
150
133
< CrewGroup >
151
- { profileData . crews . length
152
- ? profileData . crews . map ( ( crew ) => (
134
+ { profile . crews . length
135
+ ? profile . crews . map ( ( crew ) => (
153
136
< ItemBox border = "none" key = { crew . id } >
154
137
< Image
155
138
src = { crew . profileImageUrl }
@@ -164,7 +147,7 @@ export const Profile = ({ memberId }: { memberId: Member['id'] }) => {
164
147
< ProfileField category = "획득한 뱃지" > { '없음' } </ ProfileField >
165
148
< ProfileField category = "자기소개" >
166
149
< Introduce >
167
- < Text > { profileData . introduction } </ Text >
150
+ < Text > { profile . introduction } </ Text >
168
151
</ Introduce >
169
152
</ ProfileField >
170
153
</ FlexItem >
0 commit comments