diff --git a/src/app/api/auth/signin/route.ts b/src/app/api/auth/signin/route.ts index 0491ab7..cb2a658 100644 --- a/src/app/api/auth/signin/route.ts +++ b/src/app/api/auth/signin/route.ts @@ -13,7 +13,6 @@ export async function POST(request: NextRequest) { const body: RequestBody = await request.json(); const response: AuthResponse = await apiClient.post('/auth/signin', body); - console.log('response', response.data); if (response.data && response.data.success && response.data.data) { const { @@ -60,7 +59,6 @@ export async function POST(request: NextRequest) { return res; } } catch (error: any) { - console.log(error); return NextResponse.json( { message: error.response?.data?.error?.message }, { status: error?.status } diff --git a/src/app/my-page/page.tsx b/src/app/my-page/page.tsx index eacbf7c..da4ef5d 100644 --- a/src/app/my-page/page.tsx +++ b/src/app/my-page/page.tsx @@ -36,38 +36,39 @@ import { } from "@/shared/lib/api-client"; import { formatTime } from "@/shared/lib/utils"; import { usePullToRefresh } from "@/shared/hooks/use-pull-to-refresh"; -import useReservationStore from "@/shared/lib/reservation-store"; export default function MyPage() { const router = useRouter(); const { toast } = useToast(); const [isLoading, setIsLoading] = useState(true); + const [userInfo, setUserInfo] = useState(null); const [remainingTime, setRemainingTime] = useState(0); const [refreshCooldown, setRefreshCooldown] = useState(0); const [actionLoading, setActionLoading] = useState(false); const [machineCheckInterval, setMachineCheckInterval] = useState(null); const [currentMachineState, setCurrentMachineState] = useState(""); - const {currentUserInfo, fetchMyInfo} = useReservationStore(); const loadUserInfo = async () => { setIsLoading(true); try { - await fetchMyInfo(); + const response = await userApi.getMyInfo(); + + setUserInfo(response.data); // 서버에서 받은 remainingTime을 우선적으로 사용 - if (currentUserInfo?.remainingTime !== "00:00:00") { + if (response.data.remainingTime !== "00:00:00") { // 서버에서 받은 remainingTime 파싱 (HH:MM:SS 형식) const parsedTime = parseTimeStringToSeconds( - currentUserInfo?.remainingTime || "" + response.data.remainingTime || "" ); setRemainingTime(parsedTime); } else { // 서버에서 시간 정보가 없을 때만 클라이언트에서 추정 - if (currentUserInfo?.status === "WAITING") { + if (response.data.status === "WAITING") { // 대기 중: 5분 (300초) setRemainingTime(300); - } else if (currentUserInfo?.status === "CONFIRMED") { + } else if (response.data.status === "CONFIRMED") { // 확정됨: 2분 (120초) - 서버 연결 대기 시간 setRemainingTime(120); } else { @@ -148,21 +149,22 @@ export default function MyPage() { // 기기 상태 체크 (confirmed 상태일 때 20초마다) const checkMachineStatus = useCallback(async () => { - if (!currentUserInfo?.reservationId || !currentUserInfo?.machineLabel) return; + if (!userInfo?.reservationId || !userInfo?.machineLabel) return; try { const response = await machineApi.getDevices(); + console.log("Machine status response:", response); if (response.status === 200 && response.data) { const { washer, dryer } = response.data; const allMachines = [...washer, ...dryer]; // 현재 예약된 기기 찾기 const currentMachine = allMachines.find( - (machine) => machine.label === currentUserInfo.machineLabel + (machine) => machine.label === userInfo.machineLabel ); if (currentMachine) { - const machineType = currentUserInfo.machineLabel + const machineType = userInfo.machineLabel ?.toLowerCase() .includes("dryer") ? "dryer" @@ -194,9 +196,13 @@ export default function MyPage() { setRemainingTime(calculatedTime); } - fetchMyInfo(); + // 사용자 정보 새로고침하여 running 상태로 업데이트 + const updatedUserInfo = await userApi.getMyInfo(); + if (updatedUserInfo.status === 200 && updatedUserInfo.data) { + setUserInfo(updatedUserInfo.data); + } - const machineTypeName = currentUserInfo.machineLabel + const machineTypeName = userInfo.machineLabel ?.toLowerCase() .includes("dryer") ? "건조기" @@ -211,17 +217,17 @@ export default function MyPage() { } catch (error) { console.error("❌ Failed to check machine status:", error); } - }, [currentUserInfo?.reservationId, currentUserInfo?.machineLabel, machineCheckInterval]); + }, [userInfo?.reservationId, userInfo?.machineLabel, machineCheckInterval]); // confirmed 상태일 때 기기 상태 체크 시작 useEffect(() => { - if (currentUserInfo?.status === "CONFIRMED" && !machineCheckInterval) { + if (userInfo?.status === "CONFIRMED" && !machineCheckInterval) { const interval = setInterval(checkMachineStatus, 20000); // 20초마다 setMachineCheckInterval(interval); // 즉시 한 번 체크 checkMachineStatus(); - } else if (currentUserInfo?.status !== "CONFIRMED" && machineCheckInterval) { + } else if (userInfo?.status !== "CONFIRMED" && machineCheckInterval) { clearInterval(machineCheckInterval); setMachineCheckInterval(null); } @@ -232,7 +238,7 @@ export default function MyPage() { clearInterval(machineCheckInterval); } }; - }, [currentUserInfo?.status, machineCheckInterval, checkMachineStatus]); + }, [userInfo?.status, machineCheckInterval, checkMachineStatus]); const handleRefresh = async () => { if (refreshCooldown > 0) { @@ -272,12 +278,12 @@ export default function MyPage() { }); const handleCancelReservation = async () => { - if (!currentUserInfo?.reservationId) return; + if (!userInfo?.reservationId) return; setActionLoading(true); try { const response = await reservationApi.deleteReservation( - currentUserInfo.reservationId + userInfo.reservationId ); if (response.status === 200) { @@ -292,7 +298,11 @@ export default function MyPage() { description: "예약이 성공적으로 취소되었습니다.", }); - fetchMyInfo(); + // 사용자 정보 새로고침 + const updatedUserInfo = await userApi.getMyInfo(); + if (updatedUserInfo.status === 200) { + setUserInfo(updatedUserInfo.data); + } } } catch (error: any) { console.error("❌ Cancel reservation error:", error); @@ -308,27 +318,27 @@ export default function MyPage() { }; const handleConfirmReservation = async () => { - if (!currentUserInfo?.reservationId) return; + if (!userInfo?.reservationId) return; setActionLoading(true); try { const response = await reservationApi.confirmReservation( - currentUserInfo?.reservationId + userInfo?.reservationId ); if (response.status === 200) { - const machineType = currentUserInfo?.machineLabel + const machineType = userInfo?.machineLabel ?.toLowerCase() .includes("dryer") ? "건조" : "세탁"; - if (currentUserInfo?.status === "WAITING") { + if (userInfo?.status === "WAITING") { toast({ title: "예약 확정 완료", description: `예약이 확정되었습니다. ${machineType} 시작 버튼을 눌러주세요.`, }); - } else if (currentUserInfo?.status === "RESERVED") { + } else if (userInfo.status === "RESERVED") { toast({ title: `${machineType} 시작`, description: `${machineType}기에 연결 중입니다. 잠시만 기다려주세요.`, @@ -336,10 +346,12 @@ export default function MyPage() { clearInterval(machineCheckInterval!); } - fetchMyInfo(); - if (currentUserInfo) { + // 사용자 정보 새로고침 + const updatedUserInfo = await userApi.getMyInfo(); + if (updatedUserInfo.status === 200) { + setUserInfo(updatedUserInfo.data); const parsedTime = parseTimeStringToSeconds( - currentUserInfo.remainingTime || "00:00:00" + updatedUserInfo.data.remainingTime || "00:00:00" ); setRemainingTime(parsedTime); } @@ -444,8 +456,8 @@ export default function MyPage() { }; const isRestricted = - currentUserInfo?.restrictedUntil && - new Date(currentUserInfo.restrictedUntil) > new Date(); + userInfo?.restrictedUntil && + new Date(userInfo.restrictedUntil) > new Date(); if (isLoading) { return ( @@ -458,7 +470,7 @@ export default function MyPage() { ); } - if (!currentUserInfo) { + if (!userInfo) { return (
@@ -549,16 +561,16 @@ export default function MyPage() { 이름
-

{currentUserInfo.name}

+

{userInfo.name}

- {currentUserInfo.schoolNumber && ( + {userInfo.schoolNumber && (
학번
-

{currentUserInfo.schoolNumber}

+

{userInfo.schoolNumber}

)} @@ -567,7 +579,7 @@ export default function MyPage() { 호실 -

{currentUserInfo.roomNumber}호

+

{userInfo.roomNumber}호

@@ -576,7 +588,7 @@ export default function MyPage() { 성별

- {currentUserInfo.gender === "MALE" ? "남성" : "여성"} + {userInfo.gender === "MALE" ? "남성" : "여성"}

@@ -592,11 +604,11 @@ export default function MyPage() {

제한 해제:{" "} - {new Date(currentUserInfo.restrictedUntil!).toLocaleString()} + {new Date(userInfo.restrictedUntil!).toLocaleString()}

- {currentUserInfo.restrictionReason && ( + {userInfo.restrictionReason && (

- 사유: {currentUserInfo.restrictionReason} + 사유: {userInfo.restrictionReason}

)} @@ -614,35 +626,35 @@ export default function MyPage() { {!( - currentUserInfo.remainingTime === "00:00:00" || !currentUserInfo.remainingTime - ) ? ( + userInfo.remainingTime === "00:00:00" || !userInfo.remainingTime + ) ? (

- {currentUserInfo.machineLabel} + {userInfo.machineLabel}

예약 시작:{" "} - {currentUserInfo.startTime - ? new Date(currentUserInfo.startTime).toLocaleString() + {userInfo.startTime + ? new Date(userInfo.startTime).toLocaleString() : "정보 없음"}

- {currentUserInfo.status && getStatusBadge(currentUserInfo.status)} + {userInfo.status && getStatusBadge(userInfo.status)}
{/* 상태 설명 */} - {currentUserInfo.status && getStatusDescription(currentUserInfo.status) && ( + {userInfo.status && getStatusDescription(userInfo.status) && (

- {getStatusDescription(currentUserInfo.status)} + {getStatusDescription(userInfo.status)}

)} {/* 기기 상태 체크 중 표시 */} - {currentUserInfo.status === "CONFIRMED" && ( + {userInfo.status === "CONFIRMED" && (
@@ -661,7 +673,7 @@ export default function MyPage() { {remainingTime > 0 && (
- {getRemainingTimeLabel(currentUserInfo.status || "")} + {getRemainingTimeLabel(userInfo.status || "")}

{/* 대기 중일 때: 예약 확정 버튼 */} - {currentUserInfo.status === "WAITING" && ( + {userInfo.status === "WAITING" && (