1
1
import { ErrorBoundary } from 'react-error-boundary' ;
2
- import toast from 'react-hot-toast' ;
3
2
import { useNavigate , useParams } from 'react-router-dom' ;
4
3
5
4
import { Avatar } from '@components/Avatar' ;
@@ -9,7 +8,6 @@ import { Button } from '@components/shared/Button';
9
8
import { Flex } from '@components/shared/Flex' ;
10
9
import { Text } from '@components/shared/Text' ;
11
10
12
- import { useCrewParticipateCreateMutation } from '@hooks/mutations/useCrewParticipateCreateMutation' ;
13
11
import { useCrewDetailQuery } from '@hooks/queries/useCrewDetailQuery' ;
14
12
15
13
import { theme } from '@styles/theme' ;
@@ -34,9 +32,11 @@ import {
34
32
PageContent ,
35
33
PageWrapper ,
36
34
ProfileImage ,
35
+ ToolTipWrapper ,
37
36
} from './CrewsDetailPage.styles' ;
38
37
import { ParticipateButton } from './ParticipateButton' ;
39
38
39
+ /** TODO 좌측 상단에 모집중, 내가 속한 크루, 내가 만든 크루 툴팁 보여주기 */
40
40
export const CrewsDetailPage = ( ) => {
41
41
const { id } = useParams ( ) ;
42
42
if ( id === undefined || isNaN ( Number ( id ) ) ) {
@@ -45,20 +45,16 @@ export const CrewsDetailPage = () => {
45
45
46
46
const loginInfo = useLoginInfoStore ( ( state ) => state . loginInfo ) ;
47
47
const { data : crew } = useCrewDetailQuery ( { crewId : Number ( id ) } ) ;
48
- const { mutate : participateMutate } = useCrewParticipateCreateMutation ( ) ;
48
+
49
49
const navigate = useNavigate ( ) ;
50
50
const handleClickMemberProfile = ( id : number | string ) =>
51
51
navigate ( PATH_NAME . GET_PROFILE_PATH ( String ( id ) ) ) ;
52
52
53
- const renderManageButton =
54
- loginInfo !== null &&
55
- loginInfo . id !== null &&
56
- crew . leader . id === loginInfo . id ;
57
- const renderParticipateButton =
58
- loginInfo !== null &&
59
- loginInfo . id !== null &&
60
- crew . leader . id !== loginInfo . id &&
61
- crew . members . every ( ( member ) => member . id !== loginInfo . id ) ;
53
+ const vacancy = crew . maxMemberCount - crew . memberCount > 0 ;
54
+ const isMyCrew = crew . leader . id === loginInfo ?. id ;
55
+ const isParticipant = crew . members . some (
56
+ ( member ) => member . id === loginInfo ?. id
57
+ ) ;
62
58
63
59
return (
64
60
< PageWrapper >
@@ -77,6 +73,21 @@ export const CrewsDetailPage = () => {
77
73
width = { 80 }
78
74
/>
79
75
< Text > { crew . name } </ Text >
76
+ { isMyCrew && (
77
+ < ToolTipWrapper >
78
+ < Text > 내가 만든 크루</ Text >
79
+ </ ToolTipWrapper >
80
+ ) }
81
+ { ! isMyCrew && isParticipant && (
82
+ < ToolTipWrapper >
83
+ < Text > 내가 속한 크루</ Text >
84
+ </ ToolTipWrapper >
85
+ ) }
86
+ { vacancy && ! isMyCrew && ! isParticipant && (
87
+ < ToolTipWrapper >
88
+ < Text > 모집중</ Text >
89
+ </ ToolTipWrapper >
90
+ ) }
80
91
</ CrewProfileInfo >
81
92
< Text size = { 20 } weight = { 700 } >
82
93
크루 소개
@@ -125,7 +136,7 @@ export const CrewsDetailPage = () => {
125
136
</ InfoItem >
126
137
</ Flex >
127
138
< ButtonWrapper >
128
- { renderManageButton && (
139
+ { isMyCrew && (
129
140
< Button
130
141
{ ...theme . BUTTON_PROPS . LARGE_RED_BUTTON_PROPS }
131
142
height = "50px"
@@ -137,28 +148,16 @@ export const CrewsDetailPage = () => {
137
148
크루 관리
138
149
</ Button >
139
150
) }
140
- { renderParticipateButton && (
141
- < ErrorBoundary
142
- fallback = { < > </ > }
143
- onError = { ( ) => toast . error ( '크루 가입여부를 불러올 수 없습니다' ) }
144
- >
151
+ { loginInfo && ! isMyCrew && (
152
+ < ErrorBoundary fallback = { < > </ > } >
145
153
< ParticipateButton
146
- memberId = { Number ( loginInfo . id ) }
154
+ loginId = { loginInfo . id ! }
147
155
crewId = { crew . id }
148
- onClick = { ( ) =>
149
- participateMutate (
150
- { crewId : crew . id } ,
151
- {
152
- onSuccess : ( ) => {
153
- toast ( '가입 신청되었습니다' ) ;
154
- } ,
155
- }
156
- )
157
- }
156
+ vacancy = { vacancy }
158
157
/>
159
158
</ ErrorBoundary >
160
159
) }
161
- { loginInfo === null && (
160
+ { loginInfo === null && vacancy && (
162
161
< Button
163
162
{ ...theme . BUTTON_PROPS . LARGE_RED_BUTTON_PROPS }
164
163
height = "50px"
@@ -168,6 +167,15 @@ export const CrewsDetailPage = () => {
168
167
로그인 후 가입 신청하기
169
168
</ Button >
170
169
) }
170
+ { loginInfo === null && ! vacancy && (
171
+ < Button
172
+ { ...theme . BUTTON_PROPS . LARGE_GRAY_OUTLINED_BUTTON_PROPS }
173
+ height = "50px"
174
+ width = "100%"
175
+ >
176
+ 신청 마감
177
+ </ Button >
178
+ ) }
171
179
</ ButtonWrapper >
172
180
</ PageContent >
173
181
</ PageWrapper >
0 commit comments