-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SKRR-24 feat: 클럽 게시물 작성하기 api 연결 (#246)
* feat: 클럽 게시물 작성 api 연결 * feat: 클럽 게시글 조회 api 연결 * feat: 클럽 게시물 작성 시 앞뒤 공백 예외처리 * refactor: 클럽 게시물 매직넘버 상수화 * feat: 클럽 게시글 작성 완료 시 해당 게시글 상세페이지로 이동 * remove: 안 쓰는 util함수 제거 * fix: 클럽 게시물 api endpoint 수정
- Loading branch information
1 parent
61ae73e
commit aaf836c
Showing
11 changed files
with
146 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { END_POINTS } from '@/constants/api'; | ||
import { PostCreateClubPostRequest } from '@/types/api/postCreateClubPost'; | ||
|
||
import { axiosClientWithAuth } from '../axiosClient'; | ||
|
||
const postCreateClubPost = async ({ clubId, title, content, image }: PostCreateClubPostRequest) => { | ||
const dataTransform = { | ||
title, | ||
content, | ||
}; | ||
const formData = new FormData(); | ||
if (title || content) { | ||
const blobRequest = new Blob([JSON.stringify(dataTransform)], { type: 'application/json' }); | ||
formData.append('postRequest', blobRequest); | ||
} | ||
|
||
if (image) { | ||
formData.append('image', image); | ||
} | ||
|
||
const { headers } = await axiosClientWithAuth.post( | ||
END_POINTS.CREATE_CLUB_POST(clubId), | ||
formData, | ||
{ | ||
headers: { | ||
'Content-Type': 'multipart/form-data', | ||
}, | ||
}, | ||
); | ||
|
||
return headers.location; | ||
}; | ||
|
||
export default postCreateClubPost; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import postCreateClubPost from '@/apis/club/postCreateClubPost'; | ||
import { PATH } from '@/constants/path'; | ||
import useToast from '@/hooks/useToast'; | ||
|
||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { QUERY_KEY } from './useGetClubPostsQuery'; | ||
|
||
const usePostCreateClubPost = () => { | ||
const navigate = useNavigate(); | ||
const queryClient = useQueryClient(); | ||
const { createToast } = useToast(); | ||
|
||
const { mutate: createPost } = useMutation(postCreateClubPost, { | ||
onSuccess: (data: string) => { | ||
queryClient.invalidateQueries([QUERY_KEY.CLUB_POSTS]); | ||
createToast({ message: '작성 완료되었습니다.', toastType: 'success' }); | ||
const [, , , , , clubId, postId] = data.split('/'); | ||
navigate(PATH.CLUB.POST(clubId, postId)); | ||
}, | ||
onError: () => { | ||
createToast({ message: '글 작성 실패', toastType: 'error' }); | ||
}, | ||
}); | ||
|
||
return { createPost }; | ||
}; | ||
|
||
export default usePostCreateClubPost; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
interface PostCreateClubPostRequest { | ||
clubId: string; | ||
title: string; | ||
content: string; | ||
image: File; | ||
} | ||
|
||
export { PostCreateClubPostRequest }; |
This file was deleted.
Oops, something went wrong.