diff --git a/src/components/AlarmBlock.tsx b/src/components/AlarmBlock.tsx index be0e3a2..77217c0 100644 --- a/src/components/AlarmBlock.tsx +++ b/src/components/AlarmBlock.tsx @@ -11,11 +11,29 @@ type Props = { isRead: boolean; }; const AlarmBlock = ({ message, isRead }: Props) => { - const nameMatch = message.match(/([가-힣]+)(?=님)/); - const dashboardMatch = message.match(/\s(.+?)\s대시보드/); - const numberMatch = message.match(/\d+$/); + const modifiedMessage = message.replace(/^[^:]+: /, ''); - const name = nameMatch ? nameMatch[0] : null; + let nameMatch; + let dashboardMatch; + let description; + if (message.includes('팀 대시보드 초대')) { + nameMatch = modifiedMessage.split('님')[0]; + dashboardMatch = modifiedMessage.match(/\s(.+?)\s대시보드/); + description = `${dashboardMatch ? dashboardMatch[1] : ''} 대시보드 초대`; + } else if (message.includes('팀 초대 수락')) { + nameMatch = modifiedMessage.split('님')[0]; + description = `초대를 수락하였습니다`; + } else if (message.includes('챌린지 블록이 생성되었습니다')) { + const index = modifiedMessage.indexOf('챌린지 블록이 생성되었습니다'); + nameMatch = message.slice(0, index).trim(); + description = '챌린지 블록이 생성되었습니다'; + } else { + nameMatch = `반가워요! ${modifiedMessage.split('님')[0]}님이`; + description = `챌린지에 참여했습니다`; + } + const numberMatch = modifiedMessage.match(/\d+$/); + + const name = nameMatch ? nameMatch : null; const dashboard = dashboardMatch ? dashboardMatch[0] : null; const number = numberMatch ? numberMatch[0] : ''; const [, setUpdate] = useAtom(navbarUpdateTriggerAtom); @@ -33,7 +51,7 @@ const AlarmBlock = ({ message, isRead }: Props) => { {name} - {dashboard} 초대 + {description} {number !== '' ? 수락 : ''} diff --git a/src/hooks/useSSE.ts b/src/hooks/useSSE.ts index 57b6902..5b12f68 100644 --- a/src/hooks/useSSE.ts +++ b/src/hooks/useSSE.ts @@ -44,23 +44,9 @@ export const useSSE = () => { eventSource.current.onmessage = event => { console.log(event.data); if (!event.data.includes('연결')) { - const modifiedMessage = event.data.replace(/\d+$/, ''); - + const modifiedMessage = event.data.replace(/^[^:]+: /, '').replace(/\d+$/, ''); customErrToast(modifiedMessage); setUnReadCount(prev => prev + 1); - - // if (setAlarmNoti) - // setAlarmNoti(prev => { - // if (prev) { - // return { - // ...prev, - // data: { - // ...prev.data, - // notificationInfoResDto: [modifiedMessage, ...prev.data.notificationInfoResDto], - // }, - // }; - // } - // }); } }; @@ -82,7 +68,7 @@ export const useSSE = () => { connectToSSE(); }, 3000); // 3초 후 재연결 }; - }, [setConnected, setMessages, setUnReadCount]); + }, [setConnected, setMessages]); useEffect(() => { // 첫 연결 시도 diff --git a/src/pages/MyPage.tsx b/src/pages/MyPage.tsx index 4596504..5f9e90c 100644 --- a/src/pages/MyPage.tsx +++ b/src/pages/MyPage.tsx @@ -45,13 +45,13 @@ const MyPage = () => { const [visibleAlarm, setAlarmVisible] = useState(false); const [visibleModal, setModalVisible] = useState(false); - const onAlarmVisibleFunc = () => { + const onAlarmVisibleFunc = async () => { setAlarmVisible(prev => !prev); if (unReadCount !== 0) { // unReadCount가 0이 아닐 때만 업데이트 setUnReadCount(0); } - updateAlarmIsRead(); + await updateAlarmIsRead(); }; const onModalVisibleFunc = () => { @@ -183,6 +183,7 @@ const MyPage = () => { {teamBlockData?.teamDashboardInfoResDto.map((item, idx) => { const { dashboardId, title, joinMembers, description } = item; + console.log(dashboardId, title); return ( { {challengeBlockData?.challengeInfoResDto.map((item, idx) => { - const { title, cycle } = item; + const { title, contents, cycle, challengeId } = item; + return ( - - + { + navigate(`/challenge/${challengeId}`); + }} + > + ); })}
{dashboard} 초대
{description}