From eb78b74216cd529dfe92cdbc57ec1cb2e0f05748 Mon Sep 17 00:00:00 2001 From: sinamong0620 Date: Wed, 25 Sep 2024 03:08:22 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#68=20fix=20:=20=EC=95=8C=EB=9E=8C=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/AlarmBlock.tsx | 28 +++++++++++++++++++++++----- src/hooks/useSSE.ts | 18 ++---------------- src/pages/MyPage.tsx | 17 ++++++++++++----- 3 files changed, 37 insertions(+), 26 deletions(-) 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}`); + }} + > +
); })} From 4fa878f2d21fab874aff323d01a861c0eb5c077e Mon Sep 17 00:00:00 2001 From: sinamong0620 Date: Wed, 25 Sep 2024 03:11:48 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#68=20refactor:=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EC=BD=94=EB=93=9C=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/styles/MyPageStyled.tsx | 2 +- src/types/MyPage.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/styles/MyPageStyled.tsx b/src/styles/MyPageStyled.tsx index 92042bf..a9e5335 100644 --- a/src/styles/MyPageStyled.tsx +++ b/src/styles/MyPageStyled.tsx @@ -199,7 +199,7 @@ export const AlarmDataContainer = styled.div` right: 10px; top: 0px; width: 20.25rem; - max-height: 40.25rem; + max-height: 39.25rem; background: white; border: 1px solid #f4f4f4; border-radius: 1rem; diff --git a/src/types/MyPage.ts b/src/types/MyPage.ts index bb3b5df..5d2ec12 100644 --- a/src/types/MyPage.ts +++ b/src/types/MyPage.ts @@ -42,6 +42,11 @@ interface TeamDashboardInfoResDto { } //* 챌린지 대시보드 정보 타입 +interface MemberInfo { + memberId: number; + picture: string; + nickname: string; +} interface ChallengeInfoResDto { challengeId: number; title: string; @@ -58,7 +63,7 @@ interface ChallengeInfoResDto { participantCount: number; isParticipant: boolean; isAuthor: boolean; - completedMembers: string[]; + completedMembers: MemberInfo[]; } export interface PersonalDashboardList {