Skip to content

Commit

Permalink
Feature/#378 팀 이미지 삭제 (#379)
Browse files Browse the repository at this point in the history
* feat: 팀 이미지 삭제 api 정의

#378

* feat: 팀 이미지 삭제 버튼 구현

#378

* feat: 팀 이미지 삭제 api 연결

#378
  • Loading branch information
yeonddori authored Jan 26, 2025
1 parent b36beee commit 924bc2f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/app/api/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ const patchEditTeamImage = (token: string, teamId: number, file: FormData) =>
},
});

const deleteTeamImage = (token: string, teamId: number) =>
teamFetcher(`/teams/${teamId}/image`, {
method: 'DELETE',
headers: {
Authorization: `Bearer ${token}`,
},
});

const deleteTeam = (token: string, teamId: number) =>
teamFetcher(`/teams/${teamId}`, {
method: 'DELETE',
Expand Down Expand Up @@ -109,6 +117,7 @@ export {
useGetTeamInfoQuery,
putEditTeam,
patchEditTeamImage,
deleteTeamImage,
deleteTeam,
postInviteTeam,
postJoinTeam,
Expand Down
51 changes: 42 additions & 9 deletions src/containers/team/TeamModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client';

import { Flex, Text, Textarea, Image } from '@chakra-ui/react';
import { Flex, Text, Textarea, Image, IconButton, Box } from '@chakra-ui/react';
import { useEffect, useRef, useState } from 'react';
import { BiEdit, BiFile } from 'react-icons/bi';
import { BiEdit, BiFile, BiTrash } from 'react-icons/bi';

import { patchEditTeamImage, postCreateTeam, putEditTeam } from '@/app/api/team';
import { deleteTeamImage, patchEditTeamImage, postCreateTeam, putEditTeam } from '@/app/api/team';
import IconBox from '@/components/IconBox';
import ActionModal from '@/components/Modal/ActionModal';
import S3_URL from '@/constants/s3Url';
Expand All @@ -30,10 +30,12 @@ const TeamModal = ({ teamInfo, isOpen, onClose }: TeamModalProps) => {
const [thumbnail, setThumbnail] = useState<File | null>();
const [alertName, setAlertName] = useState<boolean>(false);
const [alertDescription, setAlertDescription] = useState<boolean>(false);
const [isImageDeleted, setIsImageDeleted] = useState<boolean>(false);

const createTeam = useMutateWithToken(postCreateTeam);
const editTeam = useMutateWithToken(putEditTeam);
const editTeamImage = useMutateWithToken(patchEditTeamImage);
const removeTeamImage = useMutateWithToken(deleteTeamImage);

const refetchSideBar = useRefetchSideBar();
const refetchTeamInfo = useRefetchTeamInfo();
Expand Down Expand Up @@ -69,6 +71,12 @@ const TeamModal = ({ teamInfo, isOpen, onClose }: TeamModalProps) => {
}
};

const handleDeleteImage = () => {
setThumbnail(null);
setThumbnailPath('');
setIsImageDeleted(true);
};

const handleEditTeamButtonClick = () => {
if (!isTeamInfoValid()) return;

Expand All @@ -85,6 +93,16 @@ const TeamModal = ({ teamInfo, isOpen, onClose }: TeamModalProps) => {
editTeamImage(teamInfo.id, teamForm).then((editTeamImageResponse) => {
if (editTeamImageResponse.ok) {
updateTeamInfo();
} else {
alert('팀 이미지 수정에 실패했습니다.');
}
});
} else if (isImageDeleted) {
removeTeamImage(teamInfo.id).then((deleteImageResponse) => {
if (deleteImageResponse.ok) {
updateTeamInfo();
} else {
alert('팀 이미지 삭제에 실패했습니다.');
}
});
} else {
Expand Down Expand Up @@ -189,12 +207,27 @@ const TeamModal = ({ teamInfo, isOpen, onClose }: TeamModalProps) => {
}
}}
/>
<IconBox
leftIcon={<BiFile />}
rightIcon={<BiEdit />}
content={thumbnail ? thumbnail.name : '파일을 추가해주세요.'}
handleClick={() => inputFileRef.current?.click()}
/>
<Flex align="center" gap={2} w="100%">
<Box w="368px">
<IconBox
leftIcon={<BiFile />}
rightIcon={<BiEdit />}
content={thumbnail ? thumbnail.name : '파일을 추가해주세요.'}
handleClick={() => inputFileRef.current?.click()}
/>
</Box>
<IconButton
flexShrink="0"
minW="40px"
h="40px"
borderRadius="2xl"
aria-label=""
icon={<BiTrash />}
onClick={handleDeleteImage}
size="icon_md"
variant="orange_light"
/>
</Flex>
{thumbnailPath ? (
<Image w="40" alt="thumbnail" src={S3_URL(thumbnailPath)} />
) : (
Expand Down

0 comments on commit 924bc2f

Please sign in to comment.