diff --git a/src/pages/result/components/matching-receive-view.tsx b/src/pages/result/components/matching-receive-view.tsx index f262a9a1..e9008bda 100644 --- a/src/pages/result/components/matching-receive-view.tsx +++ b/src/pages/result/components/matching-receive-view.tsx @@ -1,4 +1,3 @@ -import { alarmMutations } from '@apis/alarm/alarm-mutations'; import { matchMutations } from '@apis/match/match-mutations'; import { matchQueries } from '@apis/match/match-queries'; import Button from '@components/button/button/button'; @@ -27,7 +26,6 @@ const MatchingReceiveView = () => { const parsedId = Number(matchId); const { mutate: acceptMatch } = useMutation(matchMutations.MATCH_ACCEPT()); - const { mutate: readAlarm } = useMutation(alarmMutations.READ_ALARM()); const { mutate: rejectMatch } = useMutation(matchMutations.MATCH_REJECT()); const { data, isError } = useQuery(matchQueries.MATCH_DETAIL(parsedId, true)); @@ -62,18 +60,11 @@ const MatchingReceiveView = () => { const handleAccept = () => { acceptMatch(parsedId, { onSuccess: () => { - readAlarm(parsedId, { - onSuccess: () => { - if (cardType === 'group') { - navigate(`${ROUTES.MATCH}?tab=그룹&filter=전체`); - } else { - navigate(`${ROUTES.RESULT(matchId)}?type=success`); - } - }, - onError: () => { - navigate(ROUTES.ERROR); - }, - }); + if (isGroupMatching) { + navigate(`${ROUTES.MATCH}?tab=그룹&filter=전체`); + } else { + navigate(`${ROUTES.RESULT(matchId)}?type=success`); + } fillTabItems.forEach((label) => { queryClient.invalidateQueries({ queryKey: MATCH_KEY.STATUS.SINGLE(label) }); diff --git a/src/shared/apis/alarm/alarm-mutations.ts b/src/shared/apis/alarm/alarm-mutations.ts index 38106df2..1773563c 100644 --- a/src/shared/apis/alarm/alarm-mutations.ts +++ b/src/shared/apis/alarm/alarm-mutations.ts @@ -3,13 +3,15 @@ import { END_POINT } from '@constants/api'; import { ALARM_KEY } from '@constants/query-key'; import queryClient from '@libs/query-client'; import { mutationOptions } from '@tanstack/react-query'; -import type { postReadAlarmResponse } from '@/shared/types/alarm-types'; export const alarmMutations = { - READ_ALARM: () => - mutationOptions({ - mutationKey: ALARM_KEY.READ(), - mutationFn: (matchId) => post(END_POINT.POST_READ_ALARM(matchId)), + READ_ALL_ALARMS: () => + mutationOptions({ + mutationKey: ALARM_KEY.READ_ALL(), + mutationFn: () => post(END_POINT.POST_READ_ALL_ALARMS), + onMutate: async () => { + queryClient.setQueryData(ALARM_KEY.HAS_UNREAD, false); + }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ALARM_KEY.HAS_UNREAD }); }, diff --git a/src/shared/components/bottom-navigation/bottom-navigation.tsx b/src/shared/components/bottom-navigation/bottom-navigation.tsx index e79dfd44..c6be9507 100644 --- a/src/shared/components/bottom-navigation/bottom-navigation.tsx +++ b/src/shared/components/bottom-navigation/bottom-navigation.tsx @@ -1,10 +1,11 @@ +import { alarmMutations } from '@apis/alarm/alarm-mutations'; import { alarmQueries } from '@apis/alarm/alarm-queries'; import { NAV_ITEMS } from '@components/bottom-navigation/constants/bottom-navigation'; import Icon from '@components/icon/icon'; import useAuth from '@hooks/use-auth'; import { cn } from '@libs/cn'; import { ROUTES } from '@routes/routes-config'; -import { useQuery } from '@tanstack/react-query'; +import { useMutation, useQuery } from '@tanstack/react-query'; import { useLocation, useNavigate } from 'react-router-dom'; const BottomNavigation = () => { @@ -14,6 +15,8 @@ const BottomNavigation = () => { const { data: hasUnreadAlarms } = useQuery(alarmQueries.HAS_UNREAD()); + const readAllAlarmsMutation = useMutation(alarmMutations.READ_ALL_ALARMS()); + const isActive = (path: string) => pathname === path; const isDisabled = (path: string) => { @@ -22,6 +25,11 @@ const BottomNavigation = () => { const handleTabClick = (path: string) => { if (isDisabled(path)) return; + + if (path === ROUTES.MATCH && hasUnreadAlarms) { + readAllAlarmsMutation.mutate(); + } + navigate(path); }; diff --git a/src/shared/constants/api.ts b/src/shared/constants/api.ts index c445ae76..d35a6f0d 100644 --- a/src/shared/constants/api.ts +++ b/src/shared/constants/api.ts @@ -48,4 +48,5 @@ export const END_POINT = { // 알림 GET_UNREAD_ALARMS: '/v2/users/alarm', POST_READ_ALARM: (matchId: number | string) => `/v2/users/alarm/${matchId}`, + POST_READ_ALL_ALARMS: '/v2/users/alarms', }; diff --git a/src/shared/constants/query-key.ts b/src/shared/constants/query-key.ts index 6d63743a..5d148bcb 100644 --- a/src/shared/constants/query-key.ts +++ b/src/shared/constants/query-key.ts @@ -66,5 +66,5 @@ export const MATCH_KEY = { export const ALARM_KEY = { HAS_UNREAD: ['alarms', 'hasUnread'] as const, - READ: () => ['alarms', 'read'] as const, + READ_ALL: () => ['alarms', 'read-all'] as const, };