Skip to content

Commit

Permalink
release : feat/78-FE_kick (#79)
Browse files Browse the repository at this point in the history
멤버 추방 기능 구현
  • Loading branch information
KimKyuHoi authored May 30, 2024
2 parents d513a25 + 0cea7e9 commit 1ffaa76
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 13 deletions.
23 changes: 23 additions & 0 deletions front/src/hooks/queries/group/deleteKickMemQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { queryClient } from '@hooks/queries/Http';

import { deleteKickMem } from '@services/group/deleteKickMem';

import { useMutation } from '@tanstack/react-query';

export const useDeleteKickMem = () => {
const { mutate, isPending, isError, error } = useMutation({
mutationFn: ({
groupId,
targetUserId,
}: {
groupId: string | undefined;
targetUserId: string | undefined;
}) => deleteKickMem(groupId, targetUserId),
onSuccess: () => {
// console.log('Query invalidated');
queryClient.invalidateQueries({ queryKey: ['kickMember'] });
},
});

return { mutate, isPending, isError, error };
};
55 changes: 42 additions & 13 deletions front/src/pages/group/components/AdminTeamProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { BiBookmark, BiMoney, BiSolidCrown, BiMailSend } from 'react-icons/bi';
import { IoIosClose } from 'react-icons/io';
import { useParams } from 'react-router-dom';

import Text from '@components/typography/Text';

import { useDeleteKickMem } from '@hooks/queries/group/deleteKickMemQuery';

import { ISelectGroupProps } from '@interfaces/GroupInterface';

import { useSelectGroupData } from '@/hooks/queries/group/getSelectGroupQuery';
import styled from '@emotion/styled';

const TeamLayout = styled.div`
Expand Down Expand Up @@ -89,8 +93,19 @@ const ListLayout = styled.div`
flex-direction: column;
`;

const AdminProfileLayout = styled.div`
display: flex;
flex-direction: row;
justify-content: left;
align-items: center;
width: 100%;
`;

const AdminTeamProfile = ({ groupData }: { groupData: ISelectGroupProps }) => {
console.log(groupData);
const { groupId } = useParams<string>();
const { mutate: kickMem } = useDeleteKickMem();
const { refetch: refreshData } = useSelectGroupData(groupId);

return (
<TeamLayout>
Expand Down Expand Up @@ -146,23 +161,37 @@ const AdminTeamProfile = ({ groupData }: { groupData: ISelectGroupProps }) => {
<ListLayout>
{groupData.users.map((contributor) => (
<ContributorLayout key={contributor.loginId}>
<ProfileImg imgUrl={contributor.profileUrl} />
<ProfileTextLayout>
<Text
color='var(--color-black)'
size='var(--size-xs)'
weight='700'
>
{contributor.loginId}
<AdminProfileLayout>
<ProfileImg imgUrl={contributor.profileUrl} />
<ProfileTextLayout>
<Text
color='var(--color-black)'
size='var(--size-xs)'
weight='700'
>
{contributor.loginId}
</Text>
</ProfileTextLayout>
<Text color='#333' size='var(--size-xs)' weight='600'>
{contributor.name}
</Text>
</ProfileTextLayout>
<Text color='#333' size='var(--size-xs)' weight='600'>
{contributor.name}
</Text>
</AdminProfileLayout>
<IoIosClose
size={24}
onClick={() => {
confirm('내보내시겠습니까?');
const isConfirmed =
window.confirm('정말로 추방하시겠습니까?');
if (isConfirmed && typeof groupId === 'string') {
const transformedData = {
groupId: groupId,
targetUserId: contributor.id,
};
kickMem(transformedData, {
onSuccess: () => {
refreshData();
},
});
}
}}
/>
</ContributorLayout>
Expand Down
18 changes: 18 additions & 0 deletions front/src/services/group/deleteKickMem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BASE_URI } from '@constants/URI';

import { instance } from '@services/API_JWT';

export const deleteKickMem = async (
groupId: string | undefined,
targetUserId: string | undefined
) => {
try {
const response = await instance.delete(
`${BASE_URI}/groups/${groupId}/kick/${targetUserId}`
);
return response.data;
} catch (error) {
console.error('Error fetching UserData:', error);
throw error;
}
};

0 comments on commit 1ffaa76

Please sign in to comment.