From ebf3050669f0d6aeb13b67d4bacb4c0bb805af2e Mon Sep 17 00:00:00 2001
From: jhj2713
Date: Wed, 21 Aug 2024 11:11:25 +0900
Subject: [PATCH 1/8] =?UTF-8?q?chore:=20timeout=20=EC=A1=B0=EA=B1=B4=20?=
=?UTF-8?q?=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/src/utils/fetchWithTimeout.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/admin/src/utils/fetchWithTimeout.ts b/admin/src/utils/fetchWithTimeout.ts
index fd9cbd56..8b8cb870 100644
--- a/admin/src/utils/fetchWithTimeout.ts
+++ b/admin/src/utils/fetchWithTimeout.ts
@@ -1,4 +1,4 @@
-export async function fetchWithTimeout(url: string, options: RequestInit = {}, timeout = 5000) {
+export async function fetchWithTimeout(url: string, options: RequestInit = {}, timeout = 30000) {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
options.signal = controller.signal;
From 0edb72129d0cd29c46c211492daa92d481a76d7b Mon Sep 17 00:00:00 2001
From: jhj2713
Date: Wed, 21 Aug 2024 11:23:25 +0900
Subject: [PATCH 2/8] =?UTF-8?q?fix:=20=EC=B6=94=EC=B2=A8=20=EC=9D=B4?=
=?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EC=98=A4=EB=A5=98=20=EC=8B=9C=20delete=20?=
=?UTF-8?q?=ED=9B=84=20=EB=8B=A4=EC=8B=9C=20=EC=B6=94=EC=B2=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/src/apis/lotteryAPI.ts | 13 ++++
admin/src/components/Loading/index.tsx | 7 +++
admin/src/hooks/useFetch.ts | 6 +-
admin/src/pages/LotteryWinner/index.tsx | 83 ++++++++++++++++++-------
admin/src/types/lotteryApi.ts | 4 ++
5 files changed, 91 insertions(+), 22 deletions(-)
create mode 100644 admin/src/components/Loading/index.tsx
diff --git a/admin/src/apis/lotteryAPI.ts b/admin/src/apis/lotteryAPI.ts
index e54eef5e..bc1e335b 100644
--- a/admin/src/apis/lotteryAPI.ts
+++ b/admin/src/apis/lotteryAPI.ts
@@ -1,4 +1,5 @@
import {
+ DeleteLotteryWinnerResponse,
GetLotteryExpectationsParams,
GetLotteryExpectationsResponse,
GetLotteryParticipantResponse,
@@ -55,6 +56,18 @@ export const LotteryAPI = {
throw error;
}
},
+ async deleteLotteryWinner(token: string): Promise {
+ try {
+ const response = await fetchWithTimeout(`${baseURL}/winner`, {
+ method: "DELETE",
+ headers: { ...headers, Authorization: `Bearer ${token}` },
+ });
+ return response.json();
+ } catch (error) {
+ console.error("Error:", error);
+ throw error;
+ }
+ },
async getLotteryParticipant(
{ size, page, phoneNumber }: GetLotteryWinnerParams,
token: string
diff --git a/admin/src/components/Loading/index.tsx b/admin/src/components/Loading/index.tsx
new file mode 100644
index 00000000..29c9cba0
--- /dev/null
+++ b/admin/src/components/Loading/index.tsx
@@ -0,0 +1,7 @@
+export default function Loading() {
+ return (
+
+
데이터를 불러오는 중입니다...
+
+ );
+}
diff --git a/admin/src/hooks/useFetch.ts b/admin/src/hooks/useFetch.ts
index fb9b92c4..742bc848 100644
--- a/admin/src/hooks/useFetch.ts
+++ b/admin/src/hooks/useFetch.ts
@@ -10,6 +10,7 @@ export default function useFetch(
const { showBoundary } = useErrorBoundary();
const [data, setData] = useState(null);
+ const [isLoading, setIsLoading] = useState(false);
const [isSuccess, setIsSuccess] = useState(false);
const [isError, setIsError] = useState(false);
@@ -18,6 +19,7 @@ export default function useFetch(
const fetchData = async (params?: P) => {
setIsError(false);
setIsSuccess(false);
+ setIsLoading(true);
try {
const data = await fetch(params as P, cookies[COOKIE_KEY.ACCESS_TOKEN]);
@@ -29,8 +31,10 @@ export default function useFetch(
if (showError) {
showBoundary(error);
}
+ } finally {
+ setIsLoading(false);
}
};
- return { data, isSuccess, isError, fetchData };
+ return { data, isSuccess, isLoading, isError, fetchData };
}
diff --git a/admin/src/pages/LotteryWinner/index.tsx b/admin/src/pages/LotteryWinner/index.tsx
index 8b769ad2..9ea870e2 100644
--- a/admin/src/pages/LotteryWinner/index.tsx
+++ b/admin/src/pages/LotteryWinner/index.tsx
@@ -2,10 +2,15 @@ import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { LotteryAPI } from "@/apis/lotteryAPI";
import Button from "@/components/Button";
+import Loading from "@/components/Loading";
import TabHeader from "@/components/TabHeader";
import useFetch from "@/hooks/useFetch";
import { LotteryEventType } from "@/types/lottery";
-import { GetLotteryResponse, PostLotteryWinnerResponse } from "@/types/lotteryApi";
+import {
+ DeleteLotteryWinnerResponse,
+ GetLotteryResponse,
+ PostLotteryWinnerResponse,
+} from "@/types/lotteryApi";
export default function LotteryWinner() {
const navigate = useNavigate();
@@ -18,8 +23,21 @@ export default function LotteryWinner() {
fetchData: getLotteryEvent,
} = useFetch((_, token) => LotteryAPI.getLottery(token));
- const { isSuccess: isSuccessPostLottery, fetchData: postLottery } =
- useFetch((_, token) => LotteryAPI.postLotteryWinner(token));
+ const {
+ isSuccess: isSuccessPostLottery,
+ isLoading: isLoadingPostLottery,
+ isError: isErrorPostLottery,
+ fetchData: postLottery,
+ } = useFetch(
+ (_, token) => LotteryAPI.postLotteryWinner(token),
+ false
+ );
+
+ const { isSuccess: isSuccessDeleteLottery, fetchData: deleteLottery } =
+ useFetch(
+ (_, token) => LotteryAPI.deleteLotteryWinner(token),
+ false
+ );
useEffect(() => {
getLotteryEvent();
@@ -34,31 +52,54 @@ export default function LotteryWinner() {
navigate("/lottery/winner-list");
}
}, [isSuccessPostLottery]);
+ useEffect(() => {
+ if (isErrorPostLottery) {
+ const isDelete = confirm("이미 추첨한 이벤트입니다. 삭제 후 다시 추첨하시겠습니까?");
+ if (isDelete) {
+ deleteLottery();
+ }
+ }
+ }, [isErrorPostLottery]);
+ useEffect(() => {
+ if (isSuccessDeleteLottery) {
+ postLottery();
+ }
+ }, [isSuccessDeleteLottery]);
const handleLottery = () => {
postLottery();
};
return (
-
-
+ <>
+ {isLoadingPostLottery ? (
+
+ ) : (
+
+
-
-
-
전체 참여자 수
-
- {currentLottery.appliedCount}
-
-
당첨자 수
-
- {currentLottery.winnerCount}
-
-
+
+
+
+ 전체 참여자 수
+
+
+ {currentLottery.appliedCount}
+
+
+ 당첨자 수
+
+
+ {currentLottery.winnerCount}
+
+
-
-
-
+
+
+
+ )}
+ >
);
}
diff --git a/admin/src/types/lotteryApi.ts b/admin/src/types/lotteryApi.ts
index e3c221e6..85096f3e 100644
--- a/admin/src/types/lotteryApi.ts
+++ b/admin/src/types/lotteryApi.ts
@@ -22,6 +22,10 @@ export interface PostLotteryWinnerResponse {
message: string;
}
+export interface DeleteLotteryWinnerResponse {
+ message: string;
+}
+
export interface GetLotteryWinnerParams {
size: number;
page: number;
From 09d25d6e2e3fae508e805e08fe991f5f6474c6de Mon Sep 17 00:00:00 2001
From: jhj2713
Date: Wed, 21 Aug 2024 11:38:26 +0900
Subject: [PATCH 3/8] =?UTF-8?q?refactor:=20suspense=20=EC=B2=98=EB=A6=AC?=
=?UTF-8?q?=20=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/src/components/Loading/index.tsx | 7 ----
admin/src/components/Suspense/index.tsx | 21 +++++++++++
admin/src/pages/LotteryWinner/index.tsx | 50 +++++++++++--------------
3 files changed, 43 insertions(+), 35 deletions(-)
delete mode 100644 admin/src/components/Loading/index.tsx
create mode 100644 admin/src/components/Suspense/index.tsx
diff --git a/admin/src/components/Loading/index.tsx b/admin/src/components/Loading/index.tsx
deleted file mode 100644
index 29c9cba0..00000000
--- a/admin/src/components/Loading/index.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-export default function Loading() {
- return (
-
-
데이터를 불러오는 중입니다...
-
- );
-}
diff --git a/admin/src/components/Suspense/index.tsx b/admin/src/components/Suspense/index.tsx
new file mode 100644
index 00000000..d5047d97
--- /dev/null
+++ b/admin/src/components/Suspense/index.tsx
@@ -0,0 +1,21 @@
+import { PropsWithChildren } from "react";
+
+interface SuspenseProps extends PropsWithChildren {
+ isLoading?: boolean;
+}
+
+export default function Suspense({ children, isLoading = false }: SuspenseProps) {
+ return (
+ <>
+ {isLoading ? (
+
+
+ 데이터를 불러오는 중입니다...
+
+
+ ) : (
+ children
+ )}
+ >
+ );
+}
diff --git a/admin/src/pages/LotteryWinner/index.tsx b/admin/src/pages/LotteryWinner/index.tsx
index 9ea870e2..667f156c 100644
--- a/admin/src/pages/LotteryWinner/index.tsx
+++ b/admin/src/pages/LotteryWinner/index.tsx
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { LotteryAPI } from "@/apis/lotteryAPI";
import Button from "@/components/Button";
-import Loading from "@/components/Loading";
+import Suspense from "@/components/Suspense";
import TabHeader from "@/components/TabHeader";
import useFetch from "@/hooks/useFetch";
import { LotteryEventType } from "@/types/lottery";
@@ -71,35 +71,29 @@ export default function LotteryWinner() {
};
return (
- <>
- {isLoadingPostLottery ? (
-
- ) : (
-
-
+
+
+
-
-
-
- 전체 참여자 수
-
-
- {currentLottery.appliedCount}
-
-
- 당첨자 수
-
-
- {currentLottery.winnerCount}
-
-
-
-
+
+
+
+ 전체 참여자 수
+
+
+ {currentLottery.appliedCount}
+
+
당첨자 수
+
+ {currentLottery.winnerCount}
+
+
+
- )}
- >
+
+
);
}
From b0546e058b771a9ea5c0ec6779dc58725fb28eda Mon Sep 17 00:00:00 2001
From: jhj2713
Date: Wed, 21 Aug 2024 12:12:46 +0900
Subject: [PATCH 4/8] =?UTF-8?q?chore:=20time=20=EC=84=A0=ED=83=9D=20?=
=?UTF-8?q?=EC=A1=B0=EA=B1=B4=20=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/src/components/TimePicker/index.tsx | 4 +++-
admin/src/utils/getTimeDifference.ts | 11 ++++++++---
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/admin/src/components/TimePicker/index.tsx b/admin/src/components/TimePicker/index.tsx
index e5f793ae..564e5cd1 100644
--- a/admin/src/components/TimePicker/index.tsx
+++ b/admin/src/components/TimePicker/index.tsx
@@ -12,7 +12,9 @@ export default function TimePicker({ time, disabled = false, onChangeTime }: Tim
* 시간-분 까지만 선택 가능
* 초는 0초를 디폴트로 넣는다
*/
- const time = `${e.target.value}:00`;
+ const value = e.target.value;
+ const isMinuteEnd = value.split(":").length === 2;
+ const time = `${e.target.value}${isMinuteEnd ? `:00` : ""}`;
onChangeTime(time);
};
diff --git a/admin/src/utils/getTimeDifference.ts b/admin/src/utils/getTimeDifference.ts
index 377429d7..e9bbc37e 100644
--- a/admin/src/utils/getTimeDifference.ts
+++ b/admin/src/utils/getTimeDifference.ts
@@ -1,12 +1,17 @@
export function getTimeDifference(openTime: string, closeTime: string) {
const timeRegex = /^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$/;
- if (!openTime.match(timeRegex) && !closeTime.match(timeRegex)) {
+ const isMinuteEndOpenTime = openTime.split(":").length === 2;
+ const formattedOpenTime = `${openTime}${isMinuteEndOpenTime ? `:00` : ""}`;
+ const isMinuteEndCloseTime = closeTime.split(":").length === 2;
+ const formattedCloseTime = `${closeTime}${isMinuteEndCloseTime ? `:00` : ""}`;
+
+ if (!formattedOpenTime.match(timeRegex) && !formattedCloseTime.match(timeRegex)) {
return "";
}
- const [openHours, openMinutes, openSeconds] = openTime.split(":").map(Number);
- const [closeHours, closeMinutes, closeSeconds] = closeTime.split(":").map(Number);
+ const [openHours, openMinutes, openSeconds] = formattedOpenTime.split(":").map(Number);
+ const [closeHours, closeMinutes, closeSeconds] = formattedCloseTime.split(":").map(Number);
const openTimeInSeconds = openHours * 3600 + openMinutes * 60 + openSeconds;
const closeTimeInSeconds = closeHours * 3600 + closeMinutes * 60 + closeSeconds;
From 8a8678b995223e863c58affff6dffed8280184c4 Mon Sep 17 00:00:00 2001
From: jhj2713
Date: Wed, 21 Aug 2024 13:19:58 +0900
Subject: [PATCH 5/8] =?UTF-8?q?chore:=20timeout=20=EC=8B=9C=EA=B0=84=20?=
=?UTF-8?q?=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/src/utils/fetchWithTimeout.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/admin/src/utils/fetchWithTimeout.ts b/admin/src/utils/fetchWithTimeout.ts
index 8b8cb870..fd9cbd56 100644
--- a/admin/src/utils/fetchWithTimeout.ts
+++ b/admin/src/utils/fetchWithTimeout.ts
@@ -1,4 +1,4 @@
-export async function fetchWithTimeout(url: string, options: RequestInit = {}, timeout = 30000) {
+export async function fetchWithTimeout(url: string, options: RequestInit = {}, timeout = 5000) {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
options.signal = controller.signal;
From 48eb267d40c0e7ba2481415ba15de96ad0f8288e Mon Sep 17 00:00:00 2001
From: jhj2713
Date: Wed, 21 Aug 2024 14:06:26 +0900
Subject: [PATCH 6/8] =?UTF-8?q?chore:=20error=20=EC=A1=B0=EA=B1=B4=20?=
=?UTF-8?q?=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/src/constants/common.ts | 4 ++++
admin/src/hooks/useFetch.ts | 8 ++++++--
admin/src/pages/LotteryWinner/index.tsx | 6 ++++--
admin/src/utils/fetchWithTimeout.ts | 2 +-
4 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/admin/src/constants/common.ts b/admin/src/constants/common.ts
index 72066f83..26d99533 100644
--- a/admin/src/constants/common.ts
+++ b/admin/src/constants/common.ts
@@ -9,3 +9,7 @@ export const STATUS_MAP = {
[EVENT_STATUS.DURING]: "활성화",
[EVENT_STATUS.AFTER]: "종료",
};
+
+export const ERROR_MAP = {
+ CONFLICT: "409",
+} as const;
diff --git a/admin/src/hooks/useFetch.ts b/admin/src/hooks/useFetch.ts
index 742bc848..f529013a 100644
--- a/admin/src/hooks/useFetch.ts
+++ b/admin/src/hooks/useFetch.ts
@@ -13,6 +13,7 @@ export default function useFetch(
const [isLoading, setIsLoading] = useState(false);
const [isSuccess, setIsSuccess] = useState(false);
const [isError, setIsError] = useState(false);
+ const [errorStatus, setErrorStatus] = useState(null);
const [cookies] = useCookies([COOKIE_KEY.ACCESS_TOKEN]);
@@ -20,6 +21,7 @@ export default function useFetch(
setIsError(false);
setIsSuccess(false);
setIsLoading(true);
+ setErrorStatus(null);
try {
const data = await fetch(params as P, cookies[COOKIE_KEY.ACCESS_TOKEN]);
@@ -27,7 +29,9 @@ export default function useFetch(
setIsSuccess(!!data);
} catch (error) {
setIsError(true);
- console.error(error);
+ if (error instanceof Error) {
+ setErrorStatus(error.message);
+ }
if (showError) {
showBoundary(error);
}
@@ -36,5 +40,5 @@ export default function useFetch(
}
};
- return { data, isSuccess, isLoading, isError, fetchData };
+ return { data, isSuccess, isLoading, isError, errorStatus, fetchData };
}
diff --git a/admin/src/pages/LotteryWinner/index.tsx b/admin/src/pages/LotteryWinner/index.tsx
index 667f156c..9f9442b1 100644
--- a/admin/src/pages/LotteryWinner/index.tsx
+++ b/admin/src/pages/LotteryWinner/index.tsx
@@ -4,6 +4,7 @@ import { LotteryAPI } from "@/apis/lotteryAPI";
import Button from "@/components/Button";
import Suspense from "@/components/Suspense";
import TabHeader from "@/components/TabHeader";
+import { ERROR_MAP } from "@/constants/common";
import useFetch from "@/hooks/useFetch";
import { LotteryEventType } from "@/types/lottery";
import {
@@ -27,6 +28,7 @@ export default function LotteryWinner() {
isSuccess: isSuccessPostLottery,
isLoading: isLoadingPostLottery,
isError: isErrorPostLottery,
+ errorStatus: lotteryPostErrorStatus,
fetchData: postLottery,
} = useFetch(
(_, token) => LotteryAPI.postLotteryWinner(token),
@@ -53,13 +55,13 @@ export default function LotteryWinner() {
}
}, [isSuccessPostLottery]);
useEffect(() => {
- if (isErrorPostLottery) {
+ if (isErrorPostLottery && lotteryPostErrorStatus === ERROR_MAP.CONFLICT) {
const isDelete = confirm("이미 추첨한 이벤트입니다. 삭제 후 다시 추첨하시겠습니까?");
if (isDelete) {
deleteLottery();
}
}
- }, [isErrorPostLottery]);
+ }, [isErrorPostLottery, lotteryPostErrorStatus]);
useEffect(() => {
if (isSuccessDeleteLottery) {
postLottery();
diff --git a/admin/src/utils/fetchWithTimeout.ts b/admin/src/utils/fetchWithTimeout.ts
index fd9cbd56..240be34c 100644
--- a/admin/src/utils/fetchWithTimeout.ts
+++ b/admin/src/utils/fetchWithTimeout.ts
@@ -7,7 +7,7 @@ export async function fetchWithTimeout(url: string, options: RequestInit = {}, t
clearTimeout(id);
if (!response.ok) {
- throw new Error(response.statusText);
+ throw new Error(`${response.status}`);
}
return response;
From 0c3c64a9064a980752c504beba8e332dfc0cc23b Mon Sep 17 00:00:00 2001
From: jhj2713
Date: Wed, 21 Aug 2024 14:19:20 +0900
Subject: [PATCH 7/8] =?UTF-8?q?fix:=20lottery=20winner=20=EB=AA=A9?=
=?UTF-8?q?=EB=A1=9D=20fetch=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20?=
=?UTF-8?q?=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/src/constants/common.ts | 1 +
admin/src/hooks/useInfiniteFetch.ts | 14 +++++++++++++-
admin/src/pages/LotteryWinnerList/index.tsx | 10 ++++++++++
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/admin/src/constants/common.ts b/admin/src/constants/common.ts
index 26d99533..7a6d140b 100644
--- a/admin/src/constants/common.ts
+++ b/admin/src/constants/common.ts
@@ -12,4 +12,5 @@ export const STATUS_MAP = {
export const ERROR_MAP = {
CONFLICT: "409",
+ NOT_FOUND: "404",
} as const;
diff --git a/admin/src/hooks/useInfiniteFetch.ts b/admin/src/hooks/useInfiniteFetch.ts
index 692ff063..2538618e 100644
--- a/admin/src/hooks/useInfiniteFetch.ts
+++ b/admin/src/hooks/useInfiniteFetch.ts
@@ -7,6 +7,7 @@ interface UseInfiniteFetchProps {
initialPageParam?: number;
getNextPageParam: (currentPageParam: number, lastPage: R) => number | undefined;
startFetching?: boolean;
+ showError?: boolean;
}
interface InfiniteScrollData {
@@ -17,6 +18,7 @@ interface InfiniteScrollData {
hasNextPage: boolean;
isSuccess: boolean;
isError: boolean;
+ errorStatus: string | null;
}
export default function useInfiniteFetch({
@@ -24,6 +26,7 @@ export default function useInfiniteFetch({
initialPageParam = 0,
getNextPageParam,
startFetching = true,
+ showError = true,
}: UseInfiniteFetchProps): InfiniteScrollData {
const { showBoundary } = useErrorBoundary();
@@ -32,6 +35,8 @@ export default function useInfiniteFetch({
const [isLoading, setIsLoading] = useState(false);
const [isSuccess, setIsSuccess] = useState(false);
const [isError, setIsError] = useState(false);
+ const [errorStatus, setErrorStatus] = useState(null);
+
const [hasNextPage, setHasNextPage] = useState(true);
const [totalLength, setTotalLength] = useState(0);
@@ -53,6 +58,7 @@ export default function useInfiniteFetch({
setIsLoading(true);
setIsError(false);
setIsSuccess(false);
+ setErrorStatus(null);
try {
const lastPage = await fetch(currentPageParam);
const nextPageParam = getNextPageParam(currentPageParam, lastPage);
@@ -62,9 +68,14 @@ export default function useInfiniteFetch({
setHasNextPage(nextPageParam !== undefined);
setIsSuccess(true);
} catch (error) {
- showBoundary(error);
setIsError(true);
setIsSuccess(false);
+ if (error instanceof Error) {
+ setErrorStatus(error.message);
+ }
+ if (showError) {
+ showBoundary(error);
+ }
} finally {
setIsLoading(false);
}
@@ -91,5 +102,6 @@ export default function useInfiniteFetch({
hasNextPage,
isSuccess,
isError,
+ errorStatus,
};
}
diff --git a/admin/src/pages/LotteryWinnerList/index.tsx b/admin/src/pages/LotteryWinnerList/index.tsx
index b0469491..d8135d53 100644
--- a/admin/src/pages/LotteryWinnerList/index.tsx
+++ b/admin/src/pages/LotteryWinnerList/index.tsx
@@ -5,6 +5,7 @@ import { LotteryAPI } from "@/apis/lotteryAPI";
import Button from "@/components/Button";
import TabHeader from "@/components/TabHeader";
import Table from "@/components/Table";
+import { ERROR_MAP } from "@/constants/common";
import { COOKIE_KEY } from "@/constants/cookie";
import { LOTTERY_EXPECTATIONS_HEADER, LOTTERY_WINNER_HEADER } from "@/constants/lottery";
import useFetch from "@/hooks/useFetch";
@@ -30,6 +31,8 @@ export default function LotteryWinnerList() {
const {
data: winnerInfo,
isSuccess: isSuccessGetLotteryWinner,
+ isError: isErrorGetLotteryWinner,
+ errorStatus: lotteryWinnerGetErrorStatus,
fetchNextPage: getWinnerInfo,
refetch: refetchWinnerInfo,
} = useInfiniteFetch({
@@ -46,6 +49,7 @@ export default function LotteryWinnerList() {
getNextPageParam: (currentPageParam: number, lastPage: GetLotteryWinnerResponse) => {
return lastPage.isLastPage ? undefined : currentPageParam + 1;
},
+ showError: false,
});
const {
@@ -103,6 +107,12 @@ export default function LotteryWinnerList() {
refetchLotteryExpectation();
}
}, [isSuccessPatchLotteryExpectation]);
+ useEffect(() => {
+ if (isErrorGetLotteryWinner && lotteryWinnerGetErrorStatus === ERROR_MAP.NOT_FOUND) {
+ alert("아직 추첨되지 않은 이벤트입니다.");
+ navigate("/");
+ }
+ }, [isErrorGetLotteryWinner, lotteryWinnerGetErrorStatus]);
const handleRefetch = () => {
phoneNumberRef.current = phoneNumberInputRef.current?.value || "";
From 27f5f78a2aa72d5a0860d2c95e9c8dc77725f68c Mon Sep 17 00:00:00 2001
From: jhj2713
Date: Wed, 21 Aug 2024 15:27:44 +0900
Subject: [PATCH 8/8] =?UTF-8?q?chore:=20submit=20=EC=97=94=ED=84=B0=20?=
=?UTF-8?q?=EC=B2=98=EB=A6=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/src/pages/LotteryParticipantList/index.tsx | 15 ++++++++++-----
admin/src/pages/LotteryWinnerList/index.tsx | 15 ++++++++++-----
admin/src/pages/RushWinnerList/index.tsx | 14 ++++++++++----
3 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/admin/src/pages/LotteryParticipantList/index.tsx b/admin/src/pages/LotteryParticipantList/index.tsx
index 64273ccb..70c4a208 100644
--- a/admin/src/pages/LotteryParticipantList/index.tsx
+++ b/admin/src/pages/LotteryParticipantList/index.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useMemo, useRef, useState } from "react";
+import { FormEvent, useEffect, useMemo, useRef, useState } from "react";
import { useCookies } from "react-cookie";
import { useNavigate } from "react-router-dom";
import { LotteryAPI } from "@/apis/lotteryAPI";
@@ -123,6 +123,11 @@ export default function LotteryParticipantList() {
patchLotteryExpectation(id);
};
+ const handleSubmitSearch = (e: FormEvent) => {
+ e.preventDefault();
+ handleRefetch();
+ };
+
const expectations = useMemo(
() =>
expectation.map((participant) => [
@@ -176,15 +181,15 @@ export default function LotteryParticipantList() {
-
+
+
-
setIsWinnerToggle((prevToggle) => !prevToggle)}
>
당첨자 수만 보기 {isWinnerToggle ? "OFF" : "ON"}
-
+
+