Skip to content

Commit

Permalink
Fix: eslint 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JYN523 committed Oct 17, 2024
1 parent 9b7262e commit 150f0da
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
13 changes: 11 additions & 2 deletions src/pages/sinitto/call-back/detail/CallBackDetailPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useParams, Outlet } from 'react-router-dom';
import { useEffect } from 'react';
import { useParams, Outlet, useNavigate } from 'react-router-dom';

import { useGetAccepted } from './api/hooks';
import { CallbackMenu } from './components';
Expand All @@ -15,14 +16,22 @@ export type CallBackDetailParams = {

export const CallBackDetailPage = () => {
const { callBackId = '' } = useParams<CallBackDetailParams>();
const navigate = useNavigate();

const {
data: callbackData,
isLoading: isCallBackLoading,
isError: isCallBackError,
error: callBackError,
} = useGetCallback(callBackId);
handleCallbackError(isCallBackError, callBackError);

useEffect(() => {
if (isCallBackError) {
const errorMessage = handleCallbackError(callBackError);
alert(errorMessage);
navigate('/call-back');
}
}, [isCallBackError, callBackError, navigate]);

const {
data: currentReq,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export const RequestRow = forwardRef<HTMLButtonElement, Props>(
}
);

RequestRow.displayName = 'RequestRow';

const Wrapper = styled.button`
width: 100%;
height: 60px;
Expand Down
15 changes: 11 additions & 4 deletions src/pages/sinitto/guide-line/SinittoGuideLinePage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useParams } from 'react-router-dom';
import { useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom';

import { useGetGuideline } from './api/hooks';
import { GuidelineResponse } from './api/types';
import { CATEGORIES } from './data';
import { Category } from './types';
import { useGetCallback } from '@/shared/api/hooks';
import { handleCallbackError } from '@/shared/utils';
import { Container } from '@chakra-ui/react';
import { Spinner } from '@chakra-ui/react';
import { Container, Spinner } from '@chakra-ui/react';
import styled from '@emotion/styled';

type GuideLineParams = {
Expand All @@ -17,6 +17,7 @@ type GuideLineParams = {

export const SinittoGuideLinePage = () => {
const { callBackId = '', guideLineId = '' } = useParams<GuideLineParams>();
const navigate = useNavigate();
const guideLineInfo =
CATEGORIES.find((item: Category) => item.id === guideLineId)?.name || null;

Expand All @@ -35,7 +36,13 @@ export const SinittoGuideLinePage = () => {
isError: isGuideLineError,
} = useGetGuideline(Number(seniorId), guideLineId);

handleCallbackError(isCallBackError, callBackError);
useEffect(() => {
if (isCallBackError) {
const errorMessage = handleCallbackError(callBackError);
alert(errorMessage);
navigate('/call-back');
}
}, [isCallBackError, callBackError, navigate]);

return (
<Wrapper>
Expand Down
34 changes: 9 additions & 25 deletions src/shared/utils/handle-callback-error.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

import { AxiosError } from 'axios';

export const handleCallbackError = (isError: boolean, error: unknown) => {
const navigate = useNavigate();

useEffect(() => {
if (isError) {
let errorMessage = '';

if (error instanceof AxiosError) {
switch (error.response?.status) {
case 409:
errorMessage = '이미 진행 중인 콜백 요청이 있습니다.';
break;
default:
errorMessage = '데이터를 불러오는 중 오류가 발생했습니다.';
}
} else {
errorMessage = '데이터를 불러오는 중 오류가 발생했습니다.';
}

alert(errorMessage);
navigate('/call-back');
export const handleCallbackError = (error: unknown): string => {
if (error instanceof AxiosError) {
switch (error.response?.status) {
case 409:
return '이미 진행 중인 콜백 요청이 있습니다.';
default:
return '데이터를 불러오는 중 오류가 발생했습니다.';
}
}, [isError, error, navigate]);
}
return '데이터를 불러오는 중 오류가 발생했습니다.';
};

0 comments on commit 150f0da

Please sign in to comment.