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 74b7b90 commit d6774b9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/components/AlarmBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@ import styled from 'styled-components';
import Flex from './Flex';
import theme from '../styles/Theme/Theme';
import { postTeamDashboard } from '../api/TeamDashBoardApi';
import { customErrToast } from '../utils/customErrorToast';
import { useAtom } from 'jotai';
import { navbarUpdateTriggerAtom } from '../contexts/atoms';

type Props = {
message: string;
isRead: boolean;
};
const AlarmBlock = ({ message, isRead }: Props) => {
const nameMatch = message.match(/([가-힣]+)(?=님)/);

const dashboardMatch = message.match(/\s(.+?)\s대시보드/);

const numberMatch = message.match(/\d+$/);

const name = nameMatch ? nameMatch[0] : null;
const dashboard = dashboardMatch ? dashboardMatch[0] : null;
const number = numberMatch ? numberMatch[0] : '';
const [, setUpdate] = useAtom(navbarUpdateTriggerAtom);

const onAcceptHandler = () => {
postTeamDashboard(number);
const onAcceptHandler = async () => {
const response = await postTeamDashboard(number);
if (response) {
customErrToast(`${dashboard} 초대를 수락했습니다.`);
}
setUpdate(prev => !prev);
};

return (
<AlarmContainer isRead={isRead}>
<Flex alignItems="center">
Expand Down
23 changes: 20 additions & 3 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@ import { useQuery } from '@tanstack/react-query';
import { userInfoApi } from '../api/UserApi';
import { useAtom } from 'jotai';
import { nicknameAtom } from '../contexts/NickName';
import { searchPersonalDashBoard, searchTeamDashBoard } from '../api/BoardApi';
import { navbarUpdateTriggerAtom } from '../contexts/atoms';
import { unreadCount } from '../contexts/sseAtom';

const Navbar = () => {
const { dashboard } = usePersonalDashBoardSearch();
const { teamDashboard } = useTeamDashBoard();
const { data: UserInfo, refetch } = useQuery({ queryKey: ['userinfo'], queryFn: userInfoApi });
const { data: dashboard } = useQuery({
queryKey: ['personalDashboard'],
queryFn: searchPersonalDashBoard,
});
const { data: teamDashboard, refetch } = useQuery({
queryKey: ['teamDashBoard'],
queryFn: searchTeamDashBoard,
});
const { data: UserInfo, refetch: refetchTeamDashboard } = useQuery({
queryKey: ['userinfo'],
queryFn: userInfoApi,
});
const [nickname, setNickname] = useAtom(nicknameAtom);
const [update] = useAtom(navbarUpdateTriggerAtom);

// 닉네임을 API에서 받아와서 atom에 저장
useEffect(() => {
Expand All @@ -24,6 +37,10 @@ const Navbar = () => {
}
}, [UserInfo, nickname, setNickname]);

//네브바 렌더링 트리거
useEffect(() => {
refetch();
}, [update]);
return (
<S.NavBarLayout>
<div>
Expand Down
2 changes: 2 additions & 0 deletions src/contexts/atoms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { atom } from 'jotai';
import { TeamDashboardList } from '../types/MyPage';

// 데이터를 다시 불러오는 트리거 상태를 관리할 atom
export const fetchTriggerAtom = atom(0);
export const navbarUpdateTriggerAtom = atom(false);

0 comments on commit d6774b9

Please sign in to comment.