Skip to content

Commit

Permalink
refactor: useLoginModal 훅 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
cruelladevil committed May 12, 2024
1 parent 39d1b71 commit d5ac744
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useOverlay } from '@/shared/hooks/useOverlay';
import LoginModal from '../components/LoginModal';

export const useLoginModal = () => {
export const useLoginModalByError = () => {
const overlay = useOverlay();

const openLoginModal = (errorCode: number) => {
const openLoginModalByError = (errorCode: number) => {
overlay.open(({ isOpen, close }) => (
<LoginModal
isOpen={isOpen}
Expand All @@ -20,5 +20,5 @@ export const useLoginModal = () => {
));
};

return { openLoginModal };
return { openLoginModalByError };
};
6 changes: 3 additions & 3 deletions frontend/src/shared/hooks/useFetch.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useCallback, useEffect, useState } from 'react';
import { useAuthContext } from '@/features/auth/components/AuthProvider';
import { useLoginModal } from '@/features/auth/hooks/useLoginModal';
import { useLoginModalByError } from '@/features/auth/hooks/useLoginModalByError';
import AuthError from '@/shared/remotes/AuthError';
import type { ErrorResponse } from '../types/errorResponse';

const useFetch = <T>(fetcher: () => Promise<T>, defaultFetch: boolean = true) => {
const [data, setData] = useState<T | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<ErrorResponse | null>(null);
const { openLoginModal } = useLoginModal();
const { openLoginModalByError } = useLoginModalByError();
const { logout } = useAuthContext();

// TODO: Error Boudary 적용 시에 주석을 사용해주세요.
Expand All @@ -26,7 +26,7 @@ const useFetch = <T>(fetcher: () => Promise<T>, defaultFetch: boolean = true) =>
} catch (error) {
if (error instanceof AuthError) {
logout();
openLoginModal(error.code);
openLoginModalByError(error.code);
return;
}
setError(error as ErrorResponse);
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/shared/hooks/useMutation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useState } from 'react';
import { useAuthContext } from '@/features/auth/components/AuthProvider';
import { useLoginModal } from '@/features/auth/hooks/useLoginModal';
import { useLoginModalByError } from '@/features/auth/hooks/useLoginModalByError';
import AuthError from '@/shared/remotes/AuthError';
import type { ErrorResponse } from '../types/errorResponse';

Expand All @@ -9,7 +9,7 @@ export const useMutation = <T, P extends any[]>(mutateFn: (...params: P) => Prom
const [data, setData] = useState<T | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<ErrorResponse | null>(null);
const { openLoginModal } = useLoginModal();
const { openLoginModalByError } = useLoginModalByError();
const { logout } = useAuthContext();

// TODO: Error Boudary 적용 시에 주석을 사용해주세요.
Expand All @@ -28,7 +28,7 @@ export const useMutation = <T, P extends any[]>(mutateFn: (...params: P) => Prom
} catch (error) {
if (error instanceof AuthError) {
logout();
openLoginModal(error.code);
openLoginModalByError(error.code);
return;
}
setError(error as ErrorResponse);
Expand Down

0 comments on commit d5ac744

Please sign in to comment.