Skip to content

Commit

Permalink
#68 fix : 알람 메시지 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamong0620 committed Sep 24, 2024
1 parent 84b3b92 commit eb78b74
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
28 changes: 23 additions & 5 deletions src/components/AlarmBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -33,7 +51,7 @@ const AlarmBlock = ({ message, isRead }: Props) => {
<Flex alignItems="center">
<UserInfoContainer>
<h6>{name}</h6>
<p>{dashboard} 초대</p>
<p>{description}</p>
</UserInfoContainer>
{number !== '' ? <button onClick={onAcceptHandler}>수락</button> : ''}
</Flex>
Expand Down
18 changes: 2 additions & 16 deletions src/hooks/useSSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
// },
// };
// }
// });
}
};

Expand All @@ -82,7 +68,7 @@ export const useSSE = () => {
connectToSSE();
}, 3000); // 3초 후 재연결
};
}, [setConnected, setMessages, setUnReadCount]);
}, [setConnected, setMessages]);

useEffect(() => {
// 첫 연결 시도
Expand Down
17 changes: 12 additions & 5 deletions src/pages/MyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -183,6 +183,7 @@ const MyPage = () => {
<S.GridContainer>
{teamBlockData?.teamDashboardInfoResDto.map((item, idx) => {
const { dashboardId, title, joinMembers, description } = item;
console.log(dashboardId, title);
return (
<S.TeamBlockWrapper
key={idx}
Expand Down Expand Up @@ -220,10 +221,16 @@ const MyPage = () => {
<div>
<S.GridContainer>
{challengeBlockData?.challengeInfoResDto.map((item, idx) => {
const { title, cycle } = item;
const { title, contents, cycle, challengeId } = item;

return (
<div key={idx}>
<ChallengeBlock key={idx} />
<div
key={idx}
onClick={() => {
navigate(`/challenge/${challengeId}`);
}}
>
<ChallengeBlock key={idx} title={title} description={contents} />
</div>
);
})}
Expand Down

0 comments on commit eb78b74

Please sign in to comment.