Skip to content

Commit c59001c

Browse files
committed
feat : 실시간 알림, UI 구현 완료 + 신고 모달 토스트UI 적용
1 parent f300943 commit c59001c

File tree

7 files changed

+38
-8
lines changed

7 files changed

+38
-8
lines changed

src/apis/admin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const postReports = async (postReportRequest: PostReportRequest) => {
77
return res;
88
} catch (error) {
99
console.error(error);
10+
return null;
1011
}
1112
};
1213

src/apis/notification.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,15 @@ const patchReadNotificationAll = async () => {
3131
}
3232
};
3333

34-
export { getTimeLines, patchReadNotification, patchReadNotificationAll };
34+
const getNotReadCount = async () => {
35+
try {
36+
const res = await client.get('/api/notifications/not-read');
37+
if (!res) throw new Error('안 읽은 알림 수를 가져오는 도중 오류가 발생했습니다.');
38+
console.log(res);
39+
return res;
40+
} catch (error) {
41+
console.error(error);
42+
}
43+
};
44+
45+
export { getTimeLines, patchReadNotification, patchReadNotificationAll, getNotReadCount };

src/components/NotificationButton.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1+
import { getNotReadCount } from '@/apis/notification';
12
import { AlarmIcon } from '@/assets/icons';
23
import useNotificationStore from '@/stores/notificationStore';
4+
import { useEffect } from 'react';
35
import { Link } from 'react-router';
46
import { twMerge } from 'tailwind-merge';
57

68
export default function NotificationButton() {
79
const notReadCount = useNotificationStore((state) => state.notReadCount);
10+
const setNotReadCount = useNotificationStore((state) => state.setNotReadCount);
811
const notReadStyle = twMerge(
912
`absolute -right-1 -bottom-1 flex h-3.5 w-3.5 items-center justify-center rounded-full bg-red-400 text-[8px] text-white`,
1013
notReadCount >= 100 && 'w-4 h-4',
1114
);
1215

16+
const handleGetNotReadCount = async () => {
17+
const res = await getNotReadCount();
18+
if (res?.status === 200) {
19+
const updateNotReadCount: number = res.data.data.notReadCount;
20+
setNotReadCount(updateNotReadCount);
21+
}
22+
};
23+
24+
useEffect(() => {
25+
handleGetNotReadCount();
26+
});
27+
1328
return (
1429
<Link to="/mypage/notifications" className="relative">
1530
{notReadCount > 0 && (

src/components/ReportModal.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { postReports } from '@/apis/admin';
55

66
import ConfirmModal from './ConfirmModal';
77
import TextareaField from './TextareaField';
8+
import useToastStore from '@/stores/toastStore';
89

910
interface ReportModalProps {
1011
reportType: ReportType;
@@ -40,14 +41,16 @@ const ReportModal = ({ reportType, letterId, onClose }: ReportModalProps) => {
4041
else setPostReportRequest((cur) => ({ ...cur, reasonType: reason }));
4142
};
4243

44+
const setToastActive = useToastStore((state) => state.setToastActive);
45+
4346
const handleSubmit = async () => {
4447
const res = await postReports(postReportRequest);
4548
if (res?.status === 200) {
46-
alert('신고 처리되었습니다.');
49+
setToastActive({ title: '신고가 접수되었습니다.', toastType: 'Success' });
4750
console.log(res);
4851
onClose();
49-
} else if (res?.status === 409) {
50-
alert('신고한 이력이 있습니다.');
52+
} else {
53+
setToastActive({ title: '신고한 이력이 있습니다.', toastType: 'Error' });
5154
onClose();
5255
}
5356
};

src/components/ToastItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function ToastItem({ toastObj, index }: { toastObj: ToastObj; ind
2626

2727
const animation = `toast-blink ${toastObj.time}s ease-in-out forwards`;
2828
const toastStyle = twMerge(
29-
'fixed bottom-5 left-1/2 z-40 flex h-[40px] max-w-150 min-w-[300px] w-[100%] -translate-1/2 items-center justify-center rounded-lg caption-sb shadow-[0_1px_6px_rgba(200,200,200,0.2)]',
29+
'fixed bottom-5 left-1/2 z-40 flex h-[40px] max-w-150 min-w-[300px] w-[80%] -translate-1/2 items-center justify-center rounded-lg caption-sb shadow-[0_1px_6px_rgba(200,200,200,0.2)]',
3030
TOAST_POSITION[toastObj.position],
3131
TOAST_DESIGN[toastObj.toastType].style,
3232
);

src/hooks/useServerSentEvents.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const useServerSentEvents = () => {
8282
callReissue();
8383
closeSSE();
8484
recallCountRef.current += 1;
85-
console.log(recallCountRef.current);
85+
console.log('SSE연결 에러 발생');
8686

8787
// 재연결 로직 추가 가능
8888
if (recallCountRef.current < 5) {
@@ -92,7 +92,6 @@ export const useServerSentEvents = () => {
9292
}
9393
};
9494
} catch (error) {
95-
console.log('에러', error);
9695
console.error(error);
9796
}
9897
};

src/pages/Notifications/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import useNotificationStore from '@/stores/notificationStore';
1212
const NotificationsPage = () => {
1313
const navigate = useNavigate();
1414

15+
const decrementNotReadCount = useNotificationStore((state) => state.decrementNotReadCount);
1516
const setNotReadCount = useNotificationStore((state) => state.setNotReadCount);
1617

1718
const [noti, setNoti] = useState<Noti[]>([]);
@@ -55,7 +56,7 @@ const NotificationsPage = () => {
5556
setNoti((curNoti) =>
5657
curNoti.map((noti) => {
5758
if (noti.timelineId === timelineId && !noti.read) {
58-
setNotReadCount(0);
59+
decrementNotReadCount();
5960
return { ...noti, read: true };
6061
}
6162
return noti;

0 commit comments

Comments
 (0)