-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* FE-72✨ 글작성페이지 스키마 추가 * FE-72✨ form태그 Form컴포넌트로 변경 * FE-72✨ 태그 저장기능 추가 * FE-72✨ 에피그램 등록 api연동 * FE-72✨ 에피그램 등록시 해당 에피그램 페이지로 이동 기능 추가 * FE-72✨ 등록 중일때의 로직추가 * FE-72✨ toast-> alert-dailog로 변경 * FE-72📝 TODO주석 추가 --------- Co-authored-by: 우지석 <[email protected]>
- Loading branch information
Showing
6 changed files
with
355 additions
and
60 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,9 @@ | ||
import { AddEpigramRequestType, AddEpigramResponseType } from '@/schema/addEpigram'; | ||
import httpClient from '.'; | ||
|
||
const postEpigram = async (request: AddEpigramRequestType): Promise<AddEpigramResponseType> => { | ||
const response = await httpClient.post<AddEpigramResponseType>('/epigrams', request); | ||
return response.data; | ||
}; | ||
|
||
export default postEpigram; |
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 |
---|---|---|
@@ -1,10 +1,33 @@ | ||
import axios from 'axios'; | ||
import qs from 'qs'; | ||
|
||
const getToken = () => | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjUsInRlYW1JZCI6IjUtOSIsInNjb3BlIjoiYWNjZXNzIiwiaWF0IjoxNzIxNjE2Mjk3LCJleHAiOjE3MjE2MTgwOTcsImlzcyI6InNwLWVwaWdyYW0ifQ.kHIq9gdLbu2tE2H8VZXJ9xKQfVA95G9RY251qfXvJy8'; | ||
|
||
const httpClient = axios.create({ | ||
baseURL: process.env.NEXT_PUBLIC_BASE_URL, | ||
headers: { 'Content-Type': 'application/json' }, | ||
paramsSerializer: (parameters) => qs.stringify(parameters, { arrayFormat: 'repeat', encode: false }), | ||
}); | ||
|
||
// NOTE: 유민님 interceptor 사용! | ||
httpClient.interceptors.request.use( | ||
(config) => { | ||
const newConfig = { ...config }; | ||
const token = getToken(); | ||
if (token) { | ||
newConfig.headers.Authorization = `Bearer ${token}`; | ||
} | ||
|
||
if (newConfig.data instanceof FormData) { | ||
newConfig.headers['Content-Type'] = 'multipart/form-data'; | ||
} else { | ||
newConfig.headers['Content-Type'] = 'application/json'; | ||
} | ||
|
||
return newConfig; | ||
}, | ||
(error) => Promise.reject(error), | ||
); | ||
|
||
export default httpClient; |
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,24 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { AddEpigramFormType, AddEpigramResponseType } from '@/schema/addEpigram'; | ||
import { MutationOptions } from '@/types/query'; | ||
import postEpigram from '@/apis/add'; | ||
import { AxiosError } from 'axios'; | ||
|
||
// TODO: 에피그램 수정과 삭제에도 사용 가능하게 훅 수정 예정 | ||
|
||
const useAddEpigram = (options?: MutationOptions<AddEpigramFormType, AddEpigramResponseType>) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation<AddEpigramResponseType, AxiosError, AddEpigramFormType>({ | ||
mutationFn: (newEpigram: AddEpigramFormType) => postEpigram(newEpigram), | ||
...options, | ||
onSuccess: (...args) => { | ||
queryClient.invalidateQueries({ queryKey: ['epigrams'] }); | ||
if (options?.onSuccess) { | ||
options.onSuccess(...args); | ||
} | ||
}, | ||
}); | ||
}; | ||
|
||
export default useAddEpigram; |
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
Oops, something went wrong.