Skip to content

Commit

Permalink
SKRF-450 refactor: 클럽 생성 시 비속어, 이미지파일 예외처리, 예외코드에 따른 토스트 메시지 (#208)
Browse files Browse the repository at this point in the history
* refactor: 클럽 생성 시 비속어, 이미지파일 예외처리, 예외코드에 따른 토스트 메시지

* fix: 파일 확장자 사이 빠진 쉼표 다시 너흠
  • Loading branch information
colorkite10 authored Dec 1, 2023
1 parent 1eb3ffa commit ed72985
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/common/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const Avatar = ({
onChange={handleInputChange}
ref={inputRef}
type="file"
accept=".jpg, .jpeg, .png .heic"
accept=".jpg, .jpeg, .png, .heic"
/>
<EditButtonStyled onClick={handleEditButtonClick} avatarSize={avatarSize}>
<AiFillEdit size={editIconSize} />
Expand Down
18 changes: 16 additions & 2 deletions src/hooks/query/club/useClub.ts
Original file line number Diff line number Diff line change
@@ -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, {
Expand All @@ -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<HttpException>) => {
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' });
}
},
});

Expand Down

0 comments on commit ed72985

Please sign in to comment.