From ed729858702d7de46ab968316352c4f6dc19a2e6 Mon Sep 17 00:00:00 2001 From: chaeyeon LEE <98521882+colorkite10@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:02:15 +0900 Subject: [PATCH] =?UTF-8?q?SKRF-450=20refactor:=20=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=8B=9C=20=EB=B9=84=EC=86=8D=EC=96=B4,?= =?UTF-8?q?=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C=EC=9D=BC=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=B2=98=EB=A6=AC,=20=EC=98=88=EC=99=B8=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=86=A0=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=A9=94=EC=8B=9C=EC=A7=80=20(#208)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 클럽 생성 시 비속어, 이미지파일 예외처리, 예외코드에 따른 토스트 메시지 * fix: 파일 확장자 사이 빠진 쉼표 다시 너흠 --- src/components/common/Avatar/Avatar.tsx | 2 +- src/hooks/query/club/useClub.ts | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components/common/Avatar/Avatar.tsx b/src/components/common/Avatar/Avatar.tsx index 4500646b..7afd8c1f 100644 --- a/src/components/common/Avatar/Avatar.tsx +++ b/src/components/common/Avatar/Avatar.tsx @@ -72,7 +72,7 @@ const Avatar = ({ onChange={handleInputChange} ref={inputRef} type="file" - accept=".jpg, .jpeg, .png .heic" + accept=".jpg, .jpeg, .png, .heic" /> diff --git a/src/hooks/query/club/useClub.ts b/src/hooks/query/club/useClub.ts index 9c363fad..4657bae9 100644 --- a/src/hooks/query/club/useClub.ts +++ b/src/hooks/query/club/useClub.ts @@ -1,18 +1,26 @@ import postCreateClub from '@/apis/club/postCreateClub'; import { ERROR_MESSAGE } from '@/constants/errorMessage'; +import { EXCEPTION_CODE } from '@/constants/exceptionCode'; import { PATH } from '@/constants/path'; import { SUCCESS_MESSAGE } from '@/constants/successMessage'; +import useImageException from '@/hooks/useImageException'; +import useTextException from '@/hooks/useTextException'; import useToast from '@/hooks/useToast'; +import { HttpException } from '@/types/common'; import { useNavigate } from 'react-router-dom'; import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { AxiosError } from 'axios'; + import { QUERY_KEY } from './useClubs'; const useClub = () => { const navigate = useNavigate(); const queryClient = useQueryClient(); + const { handleTextException } = useTextException(); + const { handleImageException } = useImageException(); const { createToast } = useToast(); const { mutate: createClub, isLoading } = useMutation(postCreateClub, { @@ -22,8 +30,14 @@ const useClub = () => { const clubId = data.split('/').pop(); clubId && navigate(PATH.CLUB.HOME(clubId)); }, - onError: () => { - createToast({ message: ERROR_MESSAGE.CLUB.CREATE_FAILED, toastType: 'error' }); + onError: (error: AxiosError) => { + handleTextException(error); + handleImageException(error); + if ( + !Object.entries(EXCEPTION_CODE).find(([, value]) => value === error.response?.data.code) + ) { + createToast({ message: ERROR_MESSAGE.CLUB.CREATE_FAILED, toastType: 'error' }); + } }, });