Skip to content

Commit

Permalink
#109 feat: 친구 신청 api 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
MyungJiwoo committed Nov 13, 2024
1 parent ea591c0 commit a555ebb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/api/ConnectionApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,16 @@ export const getRecommendedFriendsList = async (
return null;
}
};

// * 친구 신청 post
export const postFollow = async (memberId: string): Promise<FollowersListData | null> => {
try {
const response = await axiosInstance.post(`/member/follow`, {
memberId: memberId,
});
return response.data.data;
} catch (error) {
console.error('Error fetching data:', error);
return null;
}
};
7 changes: 6 additions & 1 deletion src/components/Connection/Connection.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { postFollow } from '../../api/ConnectionApi';
import { FollowInfo } from '../../types/ConnectionType';
import * as S from './ConnectionStyled';

Expand All @@ -6,14 +7,18 @@ interface ConnectionProps {
}

const Connection = ({ follower }: ConnectionProps) => {
const follow = () => {
postFollow(follower.memberId!); // memberId는 항상 존재하기 때문에 !로 검사 생략
};

return (
<S.ConnectionLayout>
<S.ProfileImageWrapper src={follower.profileImage} />
<S.ConnectionUserWrapper>
<p className="name">{follower.name}</p>
<p className="nickName">{follower.nickname}</p>
</S.ConnectionUserWrapper>
<S.FriendRequestButtonWrapper>
<S.FriendRequestButtonWrapper onClick={follow}>
<p>친구 신청</p>
</S.FriendRequestButtonWrapper>
</S.ConnectionLayout>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/MyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useQuery } from '@tanstack/react-query';
import Pagination from '@mui/material/Pagination';
import { notifications, unreadCount } from '../contexts/sseAtom';
import { Helmet } from 'react-helmet-async';
import { useFollowersList } from '../hooks/useFollowersList';

const MyPage = () => {
const navigate = useNavigate();
Expand All @@ -28,6 +29,7 @@ const MyPage = () => {
queryKey: ['alarmNoti'],
queryFn: getAlarmList,
});
const { data: followersList } = useFollowersList(0, 8);

console.log(alarmNoti);
const [teamBool, setTeamBool] = useState<string>('personal'); // 기본값으로 팀 탭을 보여줌
Expand Down Expand Up @@ -287,7 +289,7 @@ const MyPage = () => {
)}
</S.CaptionText>
<S.CaptionText onClick={() => navigate(`/connections`)}>
<span>친구 10명</span>
<span>친구 {followersList?.pageInfoResDto.totalItems}</span>
</S.CaptionText>
</Flex>
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion src/types/ConnectionType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type FollowInfo = {
memberId?: number;
memberId?: string;
nickname?: string;
name?: string;
profileImage?: string;
Expand Down

0 comments on commit a555ebb

Please sign in to comment.