diff --git a/app/api/notification/read/route.ts b/app/api/notification/read/route.ts index 10895895..3b522be9 100644 --- a/app/api/notification/read/route.ts +++ b/app/api/notification/read/route.ts @@ -1,20 +1,12 @@ -import { NextRequest, NextResponse } from 'next/server'; +import { NextResponse } from 'next/server'; import { fetchData } from '@/apis/fetch-data'; -import { - NotificationReadResponse, - NotificationType, -} from '@/features/notification'; +import { NotificationReadResponse } from '@/features/notification'; -export async function PATCH(request: NextRequest) { - const body = (await request.json()) as Promise<{ - notificationId: number; - type: NotificationType; - }>; +export async function PATCH() { const data = await fetchData( `/notification/read`, 'PATCH', - body, ); return NextResponse.json(data); diff --git a/features/notification/apis/use-read-notification.tsx b/features/notification/apis/use-read-notification.tsx index 8be16b0e..bf1a8fc9 100644 --- a/features/notification/apis/use-read-notification.tsx +++ b/features/notification/apis/use-read-notification.tsx @@ -2,19 +2,14 @@ import { useMutation } from '@tanstack/react-query'; -import { NotificationType } from '../types'; import { NotificationReadResponse } from './dto'; -async function readNotification(data: { - notificationId: number; - type: NotificationType; -}): Promise { +async function readNotification(): Promise { const res = await fetch('/api/notification/read', { method: 'PATCH', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify(data), }); // eslint-disable-next-line @typescript-eslint/no-unsafe-return diff --git a/features/notification/components/molecules/cheer-notification.tsx b/features/notification/components/molecules/cheer-notification.tsx index 158399a4..15d2b9e6 100644 --- a/features/notification/components/molecules/cheer-notification.tsx +++ b/features/notification/components/molecules/cheer-notification.tsx @@ -7,13 +7,11 @@ import { formatDateToKoreanExceptYear, } from '@/utils'; -import { useReadNotification } from '../../apis/use-read-notification'; import { layoutStyles, textStyles } from '../../styles'; import { CheerNotificationProps } from '../../types'; import { CheerUpIcon } from '../atoms'; export function CheerNotification({ - notificationId, type, memoryId, hasRead, @@ -22,14 +20,8 @@ export function CheerNotification({ content, createdAt, }: CheerNotificationProps) { - const { mutate: readNotification } = useReadNotification(); - - const handleListElementClick = () => { - readNotification({ notificationId, type }); - }; - return ( - +
  • diff --git a/features/notification/components/organisms/notification-list.tsx b/features/notification/components/organisms/notification-list.tsx index f0c3f9db..3a145be8 100644 --- a/features/notification/components/organisms/notification-list.tsx +++ b/features/notification/components/organisms/notification-list.tsx @@ -1,11 +1,12 @@ 'use client'; +import { useEffect } from 'react'; import { Virtuoso } from 'react-virtuoso'; import { LoadingArea } from '@/components/atoms'; import { css } from '@/styled-system/css'; -import { useGetNotification } from '../../apis'; +import { useGetNotification, useReadNotification } from '../../apis'; import { FollowNotification, NoNotification } from '../molecules'; import { CheerNotification } from '../molecules/cheer-notification'; import { NotificationListSkeleton } from './notification-list-skeleton'; @@ -17,6 +18,7 @@ export function NotificationList() { isFetchingNextPage, getByFarNotificationData, } = useGetNotification(); + const { mutate: readNotification } = useReadNotification(); const handleRangeChanged = (range: { endIndex: number }) => { const currentContentsLastIndex = getByFarNotificationData.length - 1; @@ -25,6 +27,11 @@ export function NotificationList() { } }; + useEffect(() => { + readNotification(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + if (isLoading) return ; return (