Skip to content
Merged
4 changes: 3 additions & 1 deletion src/app/estimates/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { redirect } from "next/navigation";

import { APP_ROUTES } from "@/lib/constants/appRoutes";

// 2026.07.24 정슬기 - [추가] /estimates 진입 시 받았던 견적 목록으로 이동
export default function EstimatesIndexPage() {
redirect("/estimates/received");
redirect(APP_ROUTES.ESTIMATES.RECEIVED);
}
50 changes: 50 additions & 0 deletions src/components/auth/CustomerAuthGate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use client";

import { usePathname, useRouter } from "next/navigation";
import { useEffect, type ReactNode } from "react";

import EstimatesQueryStatus from "@/components/estimate/EstimatesQueryStatus";
import { useCustomerAuthReady } from "@/hooks/useCustomerAuthReady";
import { buildLoginPath } from "@/lib/auth/redirect";

interface CustomerAuthGateProps {
children: ReactNode;
/** 세션 확인 중 표시. 기본은 공통 로딩 메시지 */
loadingMessage?: string;
}

/**
* 고객 전용 영역 가드
* - 세션 복구 중: 로딩
* - 비로그인: 로그인 페이지로 이동 (?redirect=)
* - 기사님: 받은 견적 요청 목록으로 이동
* // 2026.07.30 정슬기 - [추가]
*/
export default function CustomerAuthGate({
children,
loadingMessage = "로그인 상태를 확인하는 중입니다.",
}: CustomerAuthGateProps) {
const router = useRouter();
const pathname = usePathname();
const { isPending, isAuthenticated, isMover, canAccess } = useCustomerAuthReady();

useEffect(() => {
if (isPending) return;

if (!isAuthenticated) {
const search = typeof window !== "undefined" ? window.location.search : "";
window.location.assign(buildLoginPath(`${pathname}${search}`));
return;
}

if (isMover) {
router.replace("/estimate/received-requests");
}
Comment thread
yooseohyeon marked this conversation as resolved.
Resolved
}, [isPending, isAuthenticated, isMover, pathname, router]);

if (isPending || !canAccess) {
return <EstimatesQueryStatus message={loadingMessage} />;
}

return children;
}
8 changes: 4 additions & 4 deletions src/components/common/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import Image from "next/image";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import { useCallback, useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
import { useCallback, useEffect, useId, useRef, useState } from "react";

import NotificationPanel from "@/components/common/Header/NotificationPanel";
import { Text } from "@/components/common/Text";
import { useClickOutside } from "@/hooks/useClickOutside";
import { AlarmIcon } from "@/icons";
import { getLoginRedirectPath, hasAuthSession, subscribeAuthSession } from "@/lib/auth/session";
import { getLoginRedirectPath } from "@/lib/auth/session";
import { APP_ROUTES } from "@/lib/constants/appRoutes";
import { getUnreadNotificationCount, MOCK_NOTIFICATIONS } from "@/lib/mocks/notifications.mock";
import { cn } from "@/lib/utils/cn";
Expand All @@ -20,7 +20,7 @@ const LOGGED_OUT_LINKS = [{ label: "기사님 찾기", href: APP_ROUTES.MOVERS.R
const LOGGED_IN_LINKS = [
{ label: "견적 요청", href: APP_ROUTES.ESTIMATE_REQUEST },
{ label: "기사님 찾기", href: APP_ROUTES.MOVERS.ROOT },
{ label: "내 견적 관리", href: "/estimates" },
{ label: "내 견적 관리", href: APP_ROUTES.ESTIMATES.ROOT },
];

export interface HeaderProps {
Expand Down Expand Up @@ -96,7 +96,7 @@ const Header = ({ isLogin: initialIsLogin, initialNickname = null }: HeaderProps
try {
await logout();
router.replace(APP_ROUTES.LOGIN);
} catch (error) {
} catch {
router.replace(APP_ROUTES.LOGIN);
}
};
Expand Down
79 changes: 27 additions & 52 deletions src/components/estimate/EstimateRequestForm.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
"use client";

import { useMutation, useQueryClient } from "@tanstack/react-query";
import { usePathname } from "next/navigation";
import { useCallback, useEffect, useState } from "react";

import { Text } from "@/components/common/Text";
import Toast from "@/components/common/Toast";
import { useActiveEstimateRequest } from "@/hooks/useActiveEstimateRequest";
import { login, refreshSession } from "@/lib/api/auth";
import { useCustomerAuthReady } from "@/hooks/useCustomerAuthReady";
import {
buildCreateEstimateRequestPayload,
createEstimateRequest,
} from "@/lib/api/estimateRequest";
import { getApiError } from "@/lib/api/getApiError";
import { buildLoginPath } from "@/lib/auth/redirect";
import { getAccessToken } from "@/lib/auth/token";
import { APP_ROUTES } from "@/lib/constants/appRoutes";
import { QUERY_KEYS } from "@/lib/constants/queryKeys";
import { normalizeRoadAddress } from "@/lib/kakao/addressSearch";
import { cn } from "@/lib/utils/cn";
Expand All @@ -23,18 +26,11 @@ import Calendar from "./Calendar";
import DatePickerField from "./DatePickerField";
import MoveTypeCard from "./MoveTypeCard";

// 로컬 테스트용 고객 계정 (로그인 화면 연동 전 임시)
const TEST_CUSTOMER = {
email: "customer1@test.com",
password: "Moving123!",
} as const;

const TOAST_SUCCESS_MESSAGE = "견적 요청이 완료되었습니다.";
const TOAST_FAILURE_MESSAGE = "견적 요청이 실패하였습니다.";
const TOAST_EXISTING_REQUEST_MESSAGE =
"견적 요청에 실패하였습니다. 기존 견적이 있는지 확인해주세요.";
const TOAST_INVALID_ZIP_MESSAGE = "우편번호 정보가 올바르지 않습니다. 주소를 다시 선택해주세요.";
const TOAST_LOGIN_FAILURE_MESSAGE = "로그인에 실패하였습니다. 잠시 후 다시 시도해주세요.";
const ACTIVE_ESTIMATE_LOAD_ERROR_MESSAGE = "고객님의 견적 정보를 불러오지 못했습니다.";

const MOVE_TYPES = [
Expand Down Expand Up @@ -157,14 +153,14 @@ function RegionField({ kind, value, onSelect, onReset }: RegionFieldProps) {

export default function EstimateRequestForm() {
const queryClient = useQueryClient();
const pathname = usePathname();
const { isPending: isAuthPending, canFetch, isAuthenticated, isMover } = useCustomerAuthReady();
const [mobileStep, setMobileStep] = useState<MobileStep>(1);
const [selectedType, setSelectedType] = useState<MoveTypeId | null>(null);
const [moveDate, setMoveDate] = useState<Date>(() => new Date());
const [fromAddress, setFromAddress] = useState<AddressItem | null>(null);
const [toAddress, setToAddress] = useState<AddressItem | null>(null);
const [addressModalKind, setAddressModalKind] = useState<RegionKind | null>(null);
const [isLoggingIn, setIsLoggingIn] = useState(false);
const [authReady, setAuthReady] = useState(false);
const [toastMessage, setToastMessage] = useState<string | null>(null);

const canSubmit = Boolean(selectedType && fromAddress && toAddress);
Expand All @@ -175,41 +171,28 @@ export default function EstimateRequestForm() {
setToastMessage(null);
}, []);

// AuthProvider 세션 복구 후 비로그인·기사님은 로그인/기사 영역으로 보냄 (임시 계정 로그인 제거)
// 2026.07.30 정슬기 - [수정] TEST_CUSTOMER 제거, useCustomerAuthReady 연동
useEffect(() => {
let cancelled = false;

async function ensureLogin() {
setIsLoggingIn(true);
try {
if (!getAccessToken()) {
try {
await refreshSession();
} catch {
await login(TEST_CUSTOMER);
}
}
} catch {
if (!cancelled) setToastMessage(TOAST_LOGIN_FAILURE_MESSAGE);
} finally {
if (!cancelled) {
setIsLoggingIn(false);
setAuthReady(true);
}
}
if (isAuthPending) return;

if (!isAuthenticated) {
const search = typeof window !== "undefined" ? window.location.search : "";
window.location.assign(buildLoginPath(`${pathname}${search}`));
return;
}

void ensureLogin();
return () => {
cancelled = true;
};
}, []);
if (isMover) {
window.location.assign("/estimate/received-requests");
}
}, [isAuthPending, isAuthenticated, isMover, pathname]);

const {
data: activeRequest,
isLoading: isActiveLoading,
isError: isActiveError,
} = useActiveEstimateRequest({
enabled: authReady && Boolean(getAccessToken()),
enabled: canFetch,
});

// 2026.07.26 정슬기 - [수정] 생성 성공 시 내 견적 목록 캐시 무효화 (대기 목록이 stale하지 않도록)
Expand Down Expand Up @@ -261,20 +244,12 @@ export default function EstimateRequestForm() {
return;
}

try {
if (!getAccessToken()) {
setIsLoggingIn(true);
try {
await refreshSession();
} catch {
await login(TEST_CUSTOMER);
}
}
} catch {
setToastMessage(TOAST_LOGIN_FAILURE_MESSAGE);
// 리디렉션 직전 토스트는 렌더 전에 페이지가 바뀌어 보이지 않음 → 안내 없이 로그인으로 이동
// 2026.07.30 정슬기 - [수정] 로그인 유도 토스트 제거
if (!getAccessToken()) {
const search = typeof window !== "undefined" ? window.location.search : "";
window.location.assign(buildLoginPath(`${pathname}${search}`));
return;
} finally {
setIsLoggingIn(false);
}

const payload = buildCreateEstimateRequestPayload({
Expand All @@ -295,8 +270,8 @@ export default function EstimateRequestForm() {
void handleSubmit();
}

const isBusy = createMutation.isPending || isLoggingIn;
const isCheckingActive = !authReady || isActiveLoading;
const isBusy = createMutation.isPending;
const isCheckingActive = isAuthPending || !canFetch || isActiveLoading;

if (isCheckingActive) {
return (
Expand Down Expand Up @@ -332,7 +307,7 @@ export default function EstimateRequestForm() {
</>
}
buttonLabel="받은 견적 보러가기"
href="/estimates/pending"
href={APP_ROUTES.ESTIMATES.PENDING}
/>
</>
);
Expand Down
39 changes: 5 additions & 34 deletions src/components/estimate/EstimateRequestSummaryContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,26 @@ import type { MoveType } from "@/types/move";
export const ESTIMATE_REQUEST_DETAIL_CARD_CLASSNAME =
"border-border-subtle bg-background-surface rounded-20 flex w-full flex-col gap-24 border px-20 py-24 shadow-[0_0_10px_rgba(220,220,220,0.2)] min-[744px]:gap-32 min-[744px]:px-40 min-[744px]:py-32 lg:px-40 lg:py-32";

/** 기사님 받은 요청 목록 main과 동일한 콘텐츠 폭·여백 */
export const ESTIMATE_REQUEST_DETAIL_PAGE_CLASSNAME =
"mx-auto flex w-full max-w-[1200px] flex-col gap-24 px-24 pb-80 min-[744px]:px-[72px] lg:gap-40 lg:px-0";

export interface EstimateRequestSummaryRow {
label: string;
value: string;
}

interface EstimateRequestSummaryContentProps {
moveType: MoveType;
isDesignated: boolean;
/** 제목 (기사: 고객명 / 고객: 상태·이사유형 등) */
/** 제목 (기사: 고객명) */
title: ReactNode;
/** 우측 메타 (기사: N분 전 / 고객: 요청일 등) */
/** 우측 메타 (기사: N분 전) */
headerMeta?: ReactNode;
fromLabel: string;
toLabel: string;
moveDate: string;
/** 출발·도착·이사일 외 추가 행 (고객 상세용) */
extraRows?: EstimateRequestSummaryRow[];
className?: string;
/** 모달 요약은 타이포·간격이 약간 다름 */
density?: "card" | "modal";
}

/**
* EstimateRequest 요약 블록 — 기사님 받은 요청 카드/모달과 고객 보낸 요청 상세 공통
* EstimateRequest 요약 블록 — 기사님 받은 요청 카드·모달 전용
* (고객 보낸 요청 상세는 EstimateDetail 셸 + EstimateRequestDetailSummary 사용)
* // 2026.07.29 정슬기 - [추가]
* // 2026.07.30 정슬기 - [수정] 미사용 PAGE_CLASSNAME·extraRows 제거
*/
export default function EstimateRequestSummaryContent({
moveType,
Expand All @@ -48,7 +39,6 @@ export default function EstimateRequestSummaryContent({
fromLabel,
toLabel,
moveDate,
extraRows,
className,
density = "card",
}: EstimateRequestSummaryContentProps) {
Expand Down Expand Up @@ -135,25 +125,6 @@ export default function EstimateRequestSummaryContent({
</dl>

{isModal ? <div className="bg-border-subtle h-px" /> : null}

{extraRows && extraRows.length > 0 ? (
<dl className="flex flex-col gap-12">
{extraRows.map((row) => (
<div key={row.label} className="flex w-full items-start justify-between gap-12">
<Text as="dt" variant="md-regular" className="text-text-muted shrink-0">
{row.label}
</Text>
<Text
as="dd"
variant="lg-semibold"
className="text-text-primary m-0 min-w-0 text-right wrap-break-word"
>
{row.value}
</Text>
</div>
))}
</dl>
) : null}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import { Text } from "@/components/common/Text";

interface ReceivedEstimatesStatusProps {
interface EstimatesQueryStatusProps {
message: string;
actionLabel?: string;
onAction?: () => void;
}

// 2026.07.24 정슬기 - [추가] 받은 견적 도메인 전용 로딩·빈·에러 상태 UI
export default function ReceivedEstimatesStatus({
/**
* 견적·리뷰 목록/상세 공통 로딩·에러 상태 UI
* // 2026.07.30 정슬기 - [수정] ReceivedEstimatesStatus → EstimatesQueryStatus (도메인 중립화)
*/
export default function EstimatesQueryStatus({
message,
actionLabel,
onAction,
}: ReceivedEstimatesStatusProps) {
}: EstimatesQueryStatusProps) {
return (
<div className="px-margin-mobile flex w-full flex-col items-center justify-center gap-16 py-64 md:px-0 md:py-80">
<div
className="px-margin-mobile flex w-full flex-col items-center justify-center gap-16 py-64 md:px-0 md:py-80"
role={actionLabel ? "alert" : "status"}
{...(actionLabel ? {} : { "aria-live": "polite" as const })}
>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
<Text as="p" variant="lg-regular" className="text-text-muted text-center">
{message}
</Text>
Expand Down
6 changes: 4 additions & 2 deletions src/components/estimate/EstimatesShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { usePathname } from "next/navigation";
import type { ReactNode } from "react";

import CustomerAuthGate from "@/components/auth/CustomerAuthGate";
import MyEstimateTabs from "@/components/estimate/MyEstimateTabs";

interface EstimatesShellProps {
Expand All @@ -12,6 +13,7 @@ interface EstimatesShellProps {
// 2026.07.24 정슬기 - [수정] /estimates/[estimateId] 상세에서는 목록 탭을 숨김
// 2026.07.25 정슬기 - [수정] /estimates/pending/[estimateId] 상세에서도 탭 숨김
// 2026.07.29 정슬기 - [수정] 보낸 견적 요청 목록에서도 탭 표시
// 2026.07.30 정슬기 - [수정] CustomerAuthGate로 로그인·고객 권한 연동
function shouldShowTabs(pathname: string): boolean {
return (
pathname === "/estimates/pending" ||
Expand All @@ -24,9 +26,9 @@ export default function EstimatesShell({ children }: EstimatesShellProps) {
const pathname = usePathname();

return (
<>
<CustomerAuthGate loadingMessage="견적 관리를 불러오는 중입니다.">
{shouldShowTabs(pathname) ? <MyEstimateTabs /> : null}
{children}
</>
</CustomerAuthGate>
);
}
Loading