Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/features/Friends/SharedScheduleItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface SharedScheduleItemProps {
endDate?: string
sharerName: string
accentColor: string
isOwner?: boolean
onCancelSuccess?: () => void
}

Expand All @@ -23,6 +24,7 @@ export default function SharedScheduleItem({
endDate,
sharerName = '이름없음',
accentColor = '#5c6ac4',
isOwner = false,
onCancelSuccess,
}: SharedScheduleItemProps) {
const queryClient = useQueryClient()
Expand All @@ -44,25 +46,27 @@ export default function SharedScheduleItem({
? formatDate(startDate)
: `${formatDate(startDate)} - ${formatDate(endDate)}`

const leaveEventMutation = useMutation({
mutationFn: () => eventShareApi.leaveEvent(eventId),
const cancelShareMutation = useMutation({
mutationFn: () =>
isOwner ? eventShareApi.deleteEventParticipants(eventId) : eventShareApi.leaveEvent(eventId),
onSuccess: (response) => {
if (response.isSuccess) {
queryClient.invalidateQueries({ queryKey: ['calendar'] })
queryClient.invalidateQueries({ queryKey: ['events'] })
queryClient.invalidateQueries({ queryKey: ['todos'] })
queryClient.invalidateQueries({ queryKey: ['sharedEvents'] })

showToast({
title: '그룹 탈퇴 완료',
message: '성공적으로 탈퇴되었습니다.',
title: isOwner ? '공유 해제 완료' : '그룹 탈퇴 완료',
message: isOwner ? '성공적으로 공유가 해제되었습니다.' : '성공적으로 탈퇴되었습니다.',
toastType: 'success',
})

onCancelSuccess?.()
} else {
showToast({
title: '탈퇴 처리 실패',
message: response.message || '탈퇴 처리에 실패했습니다.',
title: isOwner ? '공유 해제 실패' : '탈퇴 처리 실패',
message: response.message || '처리에 실패했습니다.',
toastType: 'error',
})
}
Expand All @@ -80,8 +84,12 @@ export default function SharedScheduleItem({
})

const handleCancelShare = () => {
if (window.confirm('정말 이 공유 이벤트에서 탈퇴하시겠습니까?')) {
leaveEventMutation.mutate()
const confirmMessage = isOwner
? '소유자가 공유를 해제하면 다른 참가자들의 공유 일정도 함께 삭제됩니다. 정말 공유를 해제하시겠습니까?'
: '정말 이 공유 이벤트에서 탈퇴하시겠습니까?'

if (window.confirm(confirmMessage)) {
cancelShareMutation.mutate()
}
}

Expand All @@ -94,14 +102,14 @@ export default function SharedScheduleItem({
</S.TitleArea>

<S.MetaArea>
<S.SharerBadge>공유자: {sharerName}</S.SharerBadge>
<S.SharerBadge>{isOwner ? '내 이벤트(Owner)' : `공유자: ${sharerName}`}</S.SharerBadge>
<S.CancelButton
bgColor="#fff1f0"
textColor="#ff4d4f"
onClick={handleCancelShare}
disabled={leaveEventMutation.isPending}
disabled={cancelShareMutation.isPending}
>
{leaveEventMutation.isPending ? '취소 중...' : '공유 취소'}
{cancelShareMutation.isPending ? '처리 중...' : isOwner ? '공유 해제' : '공유 취소'}
</S.CancelButton>
</S.MetaArea>
</S.Container>
Expand Down
1 change: 1 addition & 0 deletions src/pages/main/FriendsPage/FriendsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export default function FriendsPage() {
endDate={item.endDate}
sharerName={item.ownerName}
accentColor={getAccentColor(index + 3)}
isOwner={item.isOwner}
onCancelSuccess={handleActionSuccess}
/>
))
Expand Down
6 changes: 6 additions & 0 deletions src/shared/api/friends/eventShare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export const eventShareApi = {
const { data } = await axiosInstance.get<InvitationsApiResponse>(`${BASE_URL}/invitations`)
return data
},
deleteEventParticipants: async (eventId: number): Promise<LeaveEventResponse> => {
const { data } = await axiosInstance.delete<LeaveEventResponse>(
`/events/${eventId}/participants`,
)
return data
},
leaveEvent: async (eventId: number): Promise<LeaveEventResponse> => {
const { data } = await axiosInstance.delete<LeaveEventResponse>(
`/events/${eventId}/participants/leave`,
Expand Down
1 change: 1 addition & 0 deletions src/shared/types/eventShare/eventShare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { TCommonResponse } from '../common/common'
export interface SharedEvent {
eventId: number
ownerName: string
isOwner: boolean
title: string
startDate: string
endDate: string
Expand Down
Loading