From 343c2974b23514c286fd4cb2d0c4c9085abbd15e Mon Sep 17 00:00:00 2001 From: sangrae Date: Tue, 17 Nov 2026 15:32:28 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=82=AC=EB=AC=BC=ED=95=A8=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=20=EC=A7=81=ED=9B=84=20=ED=99=88=C2=B7=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=EB=82=B4=EC=97=AD=EC=9D=B4=20=EB=B0=94=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=B4=EC=9D=B4=EA=B2=8C=20=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ui/ResultScreen.tsx | 5 +++ .../lockers/LockersApplyCompleteScreen.tsx | 40 +++++++++++++++++-- src/shared/entities/lockers/lockersQueries.ts | 5 ++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/components/ui/ResultScreen.tsx b/src/components/ui/ResultScreen.tsx index 92795b07..f1d7201b 100644 --- a/src/components/ui/ResultScreen.tsx +++ b/src/components/ui/ResultScreen.tsx @@ -13,6 +13,8 @@ import { useScreenHeader } from "@/components/ui/useScreenHeader"; interface ResultScreenAction { label: string; onClick: () => void; + // 누른 뒤 기다리는 동안 버튼에 로딩을 보이고 다시 누르지 못하게 한다 + loading?: boolean; } // 그림과 문구 사이 간격. Figma가 마감·오류 화면은 16px, 완료 화면(체크 모션)은 8px로 잡아뒀다. @@ -116,6 +118,7 @@ function ResultScreen({ @@ -132,6 +136,7 @@ function ResultScreen({ ) : ( diff --git a/src/features/lockers/LockersApplyCompleteScreen.tsx b/src/features/lockers/LockersApplyCompleteScreen.tsx index 043444e2..93e203e9 100644 --- a/src/features/lockers/LockersApplyCompleteScreen.tsx +++ b/src/features/lockers/LockersApplyCompleteScreen.tsx @@ -1,4 +1,6 @@ +import { useQueryClient } from "@tanstack/react-query"; import { Typography } from "@wanteddev/wds"; +import { useEffect, useState } from "react"; import { Navigate, useLocation, useNavigate } from "react-router-dom"; import CompleteCheck from "@/components/ui/CompleteCheck"; @@ -7,12 +9,42 @@ import { HOME_PATH } from "@/features/home/constants/home"; import { LOCKER_ASSIGNMENT_PATH } from "@/features/lockers/constants/lockers"; import type { LockersApplyCompleteState } from "@/features/lockers/hooks/useLockersApplySubmit"; import { formatDate } from "@/lib/date"; +import { homeQueries } from "@/shared/entities/home/homeQueries"; +import { lockersQueries } from "@/shared/entities/lockers/lockersQueries"; // Figma: 사물함 신청 완료 페이지 (nodeId 1737:218058) function LockersApplyCompleteScreen() { const navigate = useNavigate(); + const queryClient = useQueryClient(); const state = useLocation().state as LockersApplyCompleteState | null; + // 받기를 기다리는 이동. 그동안 다른 버튼을 눌러도 무시해서 늦게 끝난 쪽으로 끌려가지 않게 한다 + const [pending, setPending] = useState<"home" | "history" | null>(null); + + // 신청이 무효화한 홈·내 신청 내역을 이 화면에 있는 동안 받아 둔다 + useEffect(() => { + queryClient.prefetchQuery(homeQueries.home()); + queryClient.prefetchQuery(lockersQueries.myApplications()); + }, [queryClient]); + + // 다음 화면이 예전 값(신청 전 홈·"신청내역이 없어요")을 보이지 않게, 받기를 마친 뒤에 넘어간다. 받는 중이면 + // 그 요청을 같이 기다린다. 실패해도 넘어가서 다음 화면이 다시 받는다 + const openAfterFetch = async (target: "home" | "history") => { + if (pending) { + return; + } + setPending(target); + if (target === "home") { + await queryClient.fetchQuery(homeQueries.home()).catch(() => undefined); + navigate(HOME_PATH); + return; + } + await queryClient + .fetchQuery(lockersQueries.myApplications()) + .catch(() => undefined); + navigate(LOCKER_ASSIGNMENT_PATH); + }; + // 신청 직후에만 오는 화면이라, 주소로 바로 들어와 신청 결과가 없으면 홈으로 보낸다 if (!state?.application) { return ; @@ -24,15 +56,17 @@ function LockersApplyCompleteScreen() { description="신청 정보를 확인해 보세요" illustration={} illustrationGap={8} - onClose={() => navigate(HOME_PATH)} + onClose={() => openAfterFetch("home")} primaryAction={{ label: "홈으로 가기", - onClick: () => navigate(HOME_PATH), + loading: pending === "home", + onClick: () => openAfterFetch("home"), }} secondaryAction={{ label: "신청내역 보기", + loading: pending === "history", // 사물함 신청내역은 사물함 배정 상태 화면이다 - onClick: () => navigate(LOCKER_ASSIGNMENT_PATH), + onClick: () => openAfterFetch("history"), }} title="신청이 완료됐어요" > diff --git a/src/shared/entities/lockers/lockersQueries.ts b/src/shared/entities/lockers/lockersQueries.ts index 587af933..0aab3c26 100644 --- a/src/shared/entities/lockers/lockersQueries.ts +++ b/src/shared/entities/lockers/lockersQueries.ts @@ -262,7 +262,8 @@ export interface ApplyLockerVariables { // POST /lockers/applications. 응답 형식이 달라도 서버에는 이미 배정이 생겼으니 실패로 바꾸지 않고 null을 돌려준다. // 실패(남이 먼저 신청·이미 배정됨)도 남은 수·내 배정이 낡았다는 뜻이라 결과와 상관없이 캐시를 갱신한다. // 홈의 사물함 신청 안내 카드(신청 여부)와 내 정보(배정 상태)도 바뀌어서 홈도 무효화한다. -// 결과 화면이 이 갱신을 기다리지 않게 Promise를 돌려주지 않는다. +// 결과 화면이 이 갱신을 기다리지 않게 Promise를 돌려주지 않는다. 다시 받는 중에 칸 선택 화면이 닫히면 요청이 +// 취소돼 예전 값으로 돌아가서, 내 신청 내역도 무효화로 표시를 남겨 다음 화면이 들어올 때 다시 받게 한다. export function useApplyLockerMutation() { const queryClient = useQueryClient(); @@ -280,7 +281,7 @@ export function useApplyLockerMutation() { onSettled: () => { queryClient.invalidateQueries({ queryKey: lockersKeys.sections() }); queryClient.invalidateQueries({ queryKey: homeKeys.root() }); - queryClient.refetchQueries({ + queryClient.invalidateQueries({ exact: true, queryKey: lockersKeys.myApplications(), });