-
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.
Merge branch 'develop' into feat/#29-work-qa
- Loading branch information
Showing
13 changed files
with
506 additions
and
171 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
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,40 @@ | ||
import { MutationCache, QueryCache, QueryClient } from '@tanstack/react-query'; | ||
import { AxiosError } from 'axios'; | ||
import { ResponseType } from '../types/types'; | ||
|
||
// [TODO] 체크 필요 | ||
const queryClient = new QueryClient({ | ||
queryCache: new QueryCache({ | ||
onError: (error, query) => { | ||
console.log('🔯 Query onError'); | ||
console.log(error, query.meta); | ||
|
||
handleAxiosError(error); | ||
}, | ||
}), | ||
mutationCache: new MutationCache({ | ||
onError: (error, _variables, _context) => { | ||
console.log('🔯 Mutation onError'); | ||
console.log(error); | ||
|
||
handleAxiosError(error); | ||
}, | ||
}), | ||
}); | ||
|
||
function isAxiosError(error: any): error is AxiosError { | ||
return (error as AxiosError).isAxiosError !== undefined; | ||
} | ||
|
||
function handleAxiosError(error: any) { | ||
if (isAxiosError(error) && error.response) { | ||
const errorCode = error.response.data as ResponseType<string>; | ||
const errorMessage = (error.response.data as ResponseType<string>).message; | ||
|
||
if (errorCode) { | ||
error.message = `[${errorCode}] ${errorMessage}`; | ||
} | ||
} | ||
} | ||
|
||
export default queryClient; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,24 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { post } from '../../../api/api'; | ||
|
||
export interface IGuestBookData { | ||
nickname: string; | ||
content: string; | ||
} | ||
|
||
/** | ||
* 방명록 전송 | ||
*/ | ||
|
||
export const postGuestBook = async (data: IGuestBookData) => { | ||
const res = await post(`guestbook`, data); | ||
return res; | ||
}; | ||
|
||
export const usePostGuestBook = () => { | ||
const GuestBookMutation = useMutation({ | ||
mutationFn: (data: IGuestBookData) => postGuestBook(data), | ||
}); | ||
|
||
return { GuestBookMutation }; | ||
}; |
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,25 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { get } from '../../../api/api'; | ||
import { GUEST_KEYS } from '../../../constants/QueryKey'; | ||
import { GuestBookListResponseType } from '../../../types/types'; | ||
|
||
/** | ||
* 방명록 리스트 조회 | ||
*/ | ||
|
||
export const getGuestBook = async () => { | ||
const data = await get<GuestBookListResponseType>(`guestbook`); | ||
console.log('=====방명록 조회 성공=====', data.result.guestbooks); | ||
return data.result; | ||
}; | ||
|
||
export const useGetGuestBookList = () => { | ||
const QUERY_KEY = GUEST_KEYS.all; | ||
|
||
const { data, isPending, isError, refetch } = useQuery({ | ||
queryKey: QUERY_KEY, | ||
queryFn: () => getGuestBook().then((res) => res), | ||
}); | ||
|
||
return { data, isPending, isError, refetch }; | ||
}; |
Oops, something went wrong.