Skip to content

Commit

Permalink
Merge pull request #306 from Hain-tain/fix/category_post
Browse files Browse the repository at this point in the history
카테고리 생성 hotfix
  • Loading branch information
Jaymyong66 authored Aug 6, 2024
2 parents 0ce4fe8 + 0ac379f commit 0729557
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 0 additions & 1 deletion frontend/src/api/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const QUERY_KEY = {
CATEGORY: 'category',
CATEGORY_LIST: 'categoryList',
CHECK_EMAIL: 'checkEmail',
CHECK_USERNAME: 'userName',
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/hooks/authentication/useCheckLoginState.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { useCallback, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

import { ToastContext } from '@/context/ToastContext';
import { useLoginStateQuery } from '@/queries/authentication/useLoginStateQuery';
import useCustomContext from '../utils/useCustomContext';
import { useAuth } from './useAuth';

export const useCheckLoginState = () => {
const { error, isError, isSuccess } = useLoginStateQuery();
const { error, isError, status } = useLoginStateQuery();
const navigate = useNavigate();
const { handleLoginState } = useAuth();
const { infoAlert } = useCustomContext(ToastContext);

const handleLoginNavigate = useCallback(() => {
navigate('/login');
}, [navigate]);

useEffect(() => {
if (isError) {
alert(error.message);
infoAlert('로그인을 해주세요');
handleLoginNavigate();
handleLoginState(false);
}

if (isSuccess) {
if (status === 'success') {
handleLoginState(true);
}
}, [error, isError, isSuccess, handleLoginNavigate, handleLoginState]);
}, [error, isError, status, handleLoginNavigate, handleLoginState, infoAlert]);
};
5 changes: 5 additions & 0 deletions frontend/src/hooks/authentication/useLoginForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { FormEvent } from 'react';
import { useNavigate } from 'react-router-dom';

import { postLogin } from '@/api/authentication';
import { ToastContext } from '@/context/ToastContext';
import { useInputWithValidate } from '../useInputWithValidate';
import useCustomContext from '../utils/useCustomContext';
import { validateEmail, validatePassword } from './validates';

export const useLoginForm = () => {
const navigate = useNavigate();
const { failAlert, successAlert } = useCustomContext(ToastContext);

const {
value: email,
Expand All @@ -30,11 +33,13 @@ export const useLoginForm = () => {

if (!response.ok) {
console.error(response);
failAlert('로그인에 실패하였습니다.');

return;
}

navigate('/');
successAlert('로그인 성공!');
}
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/queries/category/useCategoryUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const useCategoryUpload = () => {
return useMutation({
mutationFn: postCategory,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEY.CATEGORY] });
queryClient.invalidateQueries({ queryKey: [QUERY_KEY.CATEGORY_LIST] });
},
});
};

0 comments on commit 0729557

Please sign in to comment.