Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/components/ui/ResultScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { useScreenHeader } from "@/components/ui/useScreenHeader";
interface ResultScreenAction {
label: string;
onClick: () => void;
// 누른 뒤 기다리는 동안 버튼에 로딩을 보이고 다시 누르지 못하게 한다
loading?: boolean;
}

// 그림과 문구 사이 간격. Figma가 마감·오류 화면은 16px, 완료 화면(체크 모션)은 8px로 잡아뒀다.
Expand Down Expand Up @@ -116,13 +118,15 @@ function ResultScreen({
<ActionAreaButton
buttonColor="assistive"
buttonVariant="solid"
loading={secondaryAction.loading}
onClick={secondaryAction.onClick}
sx={{ padding: "16px 28px" }}
variant="alternative"
>
{secondaryAction.label}
</ActionAreaButton>
<ActionAreaButton
loading={primaryAction.loading}
onClick={primaryAction.onClick}
sx={{ padding: "16px 28px" }}
>
Expand All @@ -132,6 +136,7 @@ function ResultScreen({
) : (
<ActionArea>
<ActionAreaButton
loading={primaryAction.loading}
onClick={primaryAction.onClick}
sx={{ paddingBlock: "16px" }}
>
Expand Down
40 changes: 37 additions & 3 deletions src/features/lockers/LockersApplyCompleteScreen.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 <Navigate replace to={HOME_PATH} />;
Expand All @@ -24,15 +56,17 @@ function LockersApplyCompleteScreen() {
description="신청 정보를 확인해 보세요"
illustration={<CompleteCheck />}
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="신청이 완료됐어요"
>
Expand Down
5 changes: 3 additions & 2 deletions src/shared/entities/lockers/lockersQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ export interface ApplyLockerVariables {
// POST /lockers/applications. 응답 형식이 달라도 서버에는 이미 배정이 생겼으니 실패로 바꾸지 않고 null을 돌려준다.
// 실패(남이 먼저 신청·이미 배정됨)도 남은 수·내 배정이 낡았다는 뜻이라 결과와 상관없이 캐시를 갱신한다.
// 홈의 사물함 신청 안내 카드(신청 여부)와 내 정보(배정 상태)도 바뀌어서 홈도 무효화한다.
// 결과 화면이 이 갱신을 기다리지 않게 Promise를 돌려주지 않는다.
// 결과 화면이 이 갱신을 기다리지 않게 Promise를 돌려주지 않는다. 다시 받는 중에 칸 선택 화면이 닫히면 요청이
// 취소돼 예전 값으로 돌아가서, 내 신청 내역도 무효화로 표시를 남겨 다음 화면이 들어올 때 다시 받게 한다.
export function useApplyLockerMutation() {
const queryClient = useQueryClient();

Expand All @@ -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(),
});
Expand Down
Loading