diff --git a/src/components/common/notification-modal/NotificationCard.tsx b/src/components/common/notification-modal/NotificationCard.tsx index b13e4697..1b92f235 100644 --- a/src/components/common/notification-modal/NotificationCard.tsx +++ b/src/components/common/notification-modal/NotificationCard.tsx @@ -1,11 +1,11 @@ -import { useContext } from 'react'; -import { Link } from 'react-router-dom'; -import { AuthContext } from '@/context/AuthContext'; +import { useNavigate } from 'react-router-dom'; +import { putAlerts } from '@/api/alertApi'; import calculateTimeDifference from '@/utils/calculateTimeDifference'; import formatWorkTime from '@/utils/formatWorkTime'; interface NotificationCardProps { - id: string; // 가게 id + alertId: string; // 알림 id + noticeId: string; // 공고 id status: 'accepted' | 'rejected'; // 공고 지원 상태 restaurantName: string; // 음식점 이름 startsAt: string; // 공고 시작 시간 (ISO 8601 문자열) @@ -20,7 +20,8 @@ interface NotificationCardProps { */ export default function NotificationCard({ - id, + alertId, + noticeId, status, restaurantName, startsAt, @@ -31,13 +32,28 @@ export default function NotificationCard({ startsAt, workhour, }); - const { role } = useContext(AuthContext); + const navigate = useNavigate(); const formattedCreatedAt = calculateTimeDifference(createdAt); const formattedStatus = status === 'accepted' ? '승인' : '거절'; const formattedStatusClass = status === 'accepted' ? 'text-blue-20' : 'text-red-20'; + const handleClick = () => { + const userId = localStorage.getItem('userId'); + + if (!userId) { + console.error('userId를 찾을 수 없습니다.'); + return; + } + + try { + putAlerts(userId, alertId); // 알림 읽음 처리 + navigate(`/${noticeId}`); + } catch (error) { + console.error(error); + } + }; return ( - +
{status === 'accepted' ? (
@@ -51,6 +67,6 @@ export default function NotificationCard({

{formattedCreatedAt}

- +
); } diff --git a/src/components/common/notification-modal/NotificationModal.tsx b/src/components/common/notification-modal/NotificationModal.tsx index e15b5abc..67e2e546 100644 --- a/src/components/common/notification-modal/NotificationModal.tsx +++ b/src/components/common/notification-modal/NotificationModal.tsx @@ -33,7 +33,8 @@ export default function NotificationModal({ data.map((data) => (