From 76f00b24535b4a90133f4f09ced635a34dc838da Mon Sep 17 00:00:00 2001 From: Jungu Lee <100949102+jobkaeHenry@users.noreply.github.com> Date: Sat, 9 Dec 2023 10:44:57 +0900 Subject: [PATCH] =?UTF-8?q?FIX-=ED=8C=8C=EC=9D=BC=EC=B2=A8=EB=B6=80-url-?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20(#79)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix : 새로운 Axios 인스턴스 사용 * Refactor : 쿼리 enable 옵션 추가 * Refactor : 쿼리 enable 옵션 추가 * Minor : 스타일 변경 --- client/src/components/newpost/SearchAlcoholInput.tsx | 6 +++--- client/src/components/wiki/AlcoholPagination.tsx | 2 +- client/src/components/wiki/WikiAlcoholSelectorBtn.tsx | 2 +- client/src/queries/alcohol/useGetAlcoholListQuery.tsx | 6 ++---- client/src/queries/attach/useNewAttachMutation.ts | 7 ++++--- client/src/queries/auth/useMyInfoQuery.tsx | 6 +----- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/client/src/components/newpost/SearchAlcoholInput.tsx b/client/src/components/newpost/SearchAlcoholInput.tsx index e7fecdd..1d2ceb1 100644 --- a/client/src/components/newpost/SearchAlcoholInput.tsx +++ b/client/src/components/newpost/SearchAlcoholInput.tsx @@ -24,7 +24,7 @@ interface SearchAlcoholInputInterface { } const SearchAlcoholInput = ({ setAlcoholNo }: SearchAlcoholInputInterface) => { // 유저가 검색한 키워드 - const [searchKeyword, setSearchKeyword] = useState(""); + const [searchKeyword, setSearchKeyword] = useState(); // 검색한 키워드의 Debounced 값 const debouncedValue = useDebounce(searchKeyword, 300); const [isSearchingAlcohol, setIsSearchingAlCohol] = useState(false); @@ -36,7 +36,7 @@ const SearchAlcoholInput = ({ setAlcoholNo }: SearchAlcoholInputInterface) => { useState(); useEffect(() => { - setSearchKeyword(selectedAlcohol?.alcoholName ?? ""); + setSearchKeyword(selectedAlcohol?.alcoholName); setAlcoholNo(selectedAlcohol?.alcoholNo); }, [selectedAlcohol]); @@ -68,7 +68,7 @@ const SearchAlcoholInput = ({ setAlcoholNo }: SearchAlcoholInputInterface) => { autoComplete="off" /> {/* FIXME List 컴포넌트로 분리 */} - {isSearchingAlcohol && ( + {isSearchingAlcohol && data && ( {isSuccess && diff --git a/client/src/components/wiki/AlcoholPagination.tsx b/client/src/components/wiki/AlcoholPagination.tsx index 967e9f3..885a65b 100644 --- a/client/src/components/wiki/AlcoholPagination.tsx +++ b/client/src/components/wiki/AlcoholPagination.tsx @@ -5,7 +5,7 @@ import { Pagination, Stack } from "@mui/material"; import usePushToWikiDetail from "@/hooks/wiki/usePushToWikiDetail"; const AlcoholPagenation = () => { - const { data: alcohols } = useGetAlcoholListQuery(); + const { data: alcohols } = useGetAlcoholListQuery(""); const onClickElementHandler = usePushToWikiDetail(); return ( diff --git a/client/src/components/wiki/WikiAlcoholSelectorBtn.tsx b/client/src/components/wiki/WikiAlcoholSelectorBtn.tsx index 482d6cb..458d589 100644 --- a/client/src/components/wiki/WikiAlcoholSelectorBtn.tsx +++ b/client/src/components/wiki/WikiAlcoholSelectorBtn.tsx @@ -31,7 +31,7 @@ const WikiAlcoholSelectorBtn = ({ > {iconComponent} - {title} + {title} ); diff --git a/client/src/queries/alcohol/useGetAlcoholListQuery.tsx b/client/src/queries/alcohol/useGetAlcoholListQuery.tsx index b2556e5..d5d8a94 100644 --- a/client/src/queries/alcohol/useGetAlcoholListQuery.tsx +++ b/client/src/queries/alcohol/useGetAlcoholListQuery.tsx @@ -7,13 +7,11 @@ const useGetAlcoholListQuery = (keyword?: string) => { return useQuery({ queryKey: AlcohilListQueryKey.byKeyword(keyword), queryFn: async () => await getAlcoholListByKeyword(keyword), + enabled: keyword!=undefined, }); }; export const getAlcoholListByKeyword = async (keyword?: string) => { - if (keyword === "") { - return { list: [], totalCount: 0 }; - } const { data } = await axios.get<{ list: AlcoholDetailInterface[]; totalCount: number; @@ -23,7 +21,7 @@ export const getAlcoholListByKeyword = async (keyword?: string) => { size: 5, searchKeyword: keyword, }, - }); + }); return data; }; diff --git a/client/src/queries/attach/useNewAttachMutation.ts b/client/src/queries/attach/useNewAttachMutation.ts index 56c526f..8023490 100644 --- a/client/src/queries/attach/useNewAttachMutation.ts +++ b/client/src/queries/attach/useNewAttachMutation.ts @@ -5,8 +5,9 @@ import { getPostListInfiniteQueryKey } from "./../post/useGetPostListInfiniteQue import { postDetailQueryKey } from "../post/useGetPostDetailQuery"; import { MyInfoQueryKeys } from "../auth/useMyInfoQuery"; import { UserInfoQueryKey } from "../user/useUserInfoQuery"; -import useAxiosPrivate from "@/hooks/useAxiosPrivate"; import { ImageSize } from "@/types/attach/attachInterface"; +import axios from "axios"; +import getTokenFromLocalStorage from "@/utils/getTokenFromLocalStorage"; export const useNewAttachMutation = () => { const errorHandler = useErrorHandler(); @@ -64,17 +65,17 @@ export const postImageFn = async ( { type, pk }: NewAttatchRequestUrl, size?: ImageSize ) => { - const axiosPrivate = useAxiosPrivate(); const formData = new FormData(); formData.append("image", file); - const { data } = await axiosPrivate.post<{ attachNo: number }>( + const { data } = await axios.post<{ attachNo: number }>( ATTACH_FILE(type, pk), formData, { params: size, headers: { "Content-Type": "multipart/form-data", + Authorization: getTokenFromLocalStorage(), }, transformRequest: [ function () { diff --git a/client/src/queries/auth/useMyInfoQuery.tsx b/client/src/queries/auth/useMyInfoQuery.tsx index 4630e86..a12697d 100644 --- a/client/src/queries/auth/useMyInfoQuery.tsx +++ b/client/src/queries/auth/useMyInfoQuery.tsx @@ -27,15 +27,11 @@ export const useMyInfoQuery = () => { throw Error(); } }, + enabled: !!getTokenFromLocalStorage(), }); }; export const getMyInfoByLocalStorage = async () => { - const accessToken = getTokenFromLocalStorage(); - - if (!accessToken) { - return null; - } const axiosPrivate = useAxiosPrivate(); const { data } = await axiosPrivate.get(MY_INFO); return data;