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
1 change: 0 additions & 1 deletion src/app/admin/reports/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
Clock,
Flag,
Info,
Trash2,
Unlock,
X,
} from "lucide-react";
Expand Down
20 changes: 9 additions & 11 deletions src/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
import Image from "next/image";
import { useRouter, useSearchParams } from "next/navigation";

import type {
ChatMessageDto,
ChatNotiDto,
NewMessageNotiDto,
NewRoomNotiDto,
} from "@/types/domain";
import type { ChatMessageDto } from "@/types/domain";

import { getQueryKey, queryKeys } from "@/lib/query-keys";
/* ======================
Expand Down Expand Up @@ -109,8 +104,6 @@ function ChatPage() {
const setCurrentRoomId = useChatStore((state) => state.setCurrentRoomId);
const resetUnread = useChatStore((state) => state.resetUnread);
const updateRoom = useChatStore((state) => state.updateRoom);
const addRoom = useChatStore((state) => state.addRoom);

// selectedRoomId가 변경될 때 chatStore에 동기화
useEffect(() => {
setCurrentRoomId(selectedRoomId);
Expand Down Expand Up @@ -408,14 +401,19 @@ function ChatPage() {
shouldAutoScrollRef.current = true;
});

// cleanup 함수에서 사용할 ref 값 복사 (effect 내부에서)
const timerRef = markAsReadTimerByRoomRef.current;
const currentSelectedRoomId = selectedRoomId;

return () => {
console.log("🔕 STOMP UNSUB", { dest, subId });
if (markAsReadTimerByRoomRef.current[selectedRoomId]) {
clearTimeout(markAsReadTimerByRoomRef.current[selectedRoomId]);
delete markAsReadTimerByRoomRef.current[selectedRoomId];
if (timerRef[currentSelectedRoomId]) {
clearTimeout(timerRef[currentSelectedRoomId]);
delete timerRef[currentSelectedRoomId];
}
unsub();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedRoomId, isConnected, subscribe, queryClient]);

/* ======================
Expand Down
67 changes: 29 additions & 38 deletions src/app/payments/toss/[reservationId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";

import { useReservationQuery } from "@/queries/reservation";
import { usePostQuery } from "@/queries/post";
import {
calculateReservationAmount,
calculateReservationDays,
type ReservationOptionForCalculation,
} from "@/lib/utils/reservation";

const clientKey = process.env.NEXT_PUBLIC_TOSS_CLIENT_KEY ?? "";

Expand All @@ -29,25 +34,11 @@ export default function TossWidgetsPaymentPage() {
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);

// 대여 기간 계산
const startDate =
reservation?.reservationStartAt &&
new Date(
typeof reservation.reservationStartAt === "string"
? reservation.reservationStartAt
: reservation.reservationStartAt,
);
const endDate =
reservation?.reservationEndAt &&
new Date(
typeof reservation.reservationEndAt === "string"
? reservation.reservationEndAt
: reservation.reservationEndAt,
);
const daysDiff =
startDate && endDate
? Math.ceil((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24)) + 1
: 0;
// 대여 기간 계산 (공통 유틸 사용)
const daysDiff = calculateReservationDays(
reservation?.reservationStartAt,
reservation?.reservationEndAt,
);

// 옵션 목록 (예약에는 id와 이름만 있고, 가격은 post의 options에서 가져옴)
const reservationOptions =
Expand All @@ -71,25 +62,25 @@ export default function TossWidgetsPaymentPage() {
[];

// post의 options에서 가격 정보를 가져와서 매칭
const options = reservationOptions.map((resOpt) => {
const postOption = post?.options?.find((po) => po.id === resOpt.id);
return {
id: resOpt.id,
name: resOpt.name,
fee: postOption?.fee || 0,
deposit: postOption?.deposit || 0,
};
});

// 결제 금액 계산
const baseFee = post?.fee || 0;
const baseDeposit = post?.deposit || 0;
const rentalFee = baseFee * daysDiff;
const optionsFee = options.reduce((sum, opt) => sum + (opt.fee || 0) * daysDiff, 0);
const optionsDeposit = options.reduce((sum, opt) => sum + (opt.deposit || 0), 0);
const totalRentalFee = rentalFee + optionsFee;
const totalDeposit = baseDeposit + optionsDeposit;
const totalAmount = totalRentalFee + totalDeposit;
const options: ReservationOptionForCalculation[] = reservationOptions.map(
(resOpt) => {
const postOption = post?.options?.find((po) => po.id === resOpt.id);
return {
id: resOpt.id,
name: resOpt.name,
fee: postOption?.fee || 0,
deposit: postOption?.deposit || 0,
};
},
);

// 결제 금액 계산 (공통 유틸 사용)
const amountCalc = calculateReservationAmount(post, options, daysDiff);
const {
totalRentalFee,
totalDeposit,
totalAmount,
} = amountCalc;

useEffect(() => {
if (!reservation || !post) return;
Expand Down
Loading