Repository navigation
[FEAT] 채팅 알림 작업 #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[FEAT] 채팅 알림 작업 #118
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
513d67d
feat: 채팅 알람 라우트 추가
Obebe-creator a4b24d8
Merge branch 'dev' of https://github.com/4roro-moving/moving-frontend…
Obebe-creator 5dd97bc
feat: 채팅 모달 알림 - 연결 페이지, 모달 오픈, 알림 라우트
Obebe-creator 33515a8
feat: 풀백 설정, 문구 변경
Obebe-creator b3e1ef1
Merge branch 'dev' of https://github.com/4roro-moving/moving-frontend…
Obebe-creator 6d802eb
fix: 문구 변경, 타입 맞춤
Obebe-creator cbbc527
Merge branch 'dev' of https://github.com/4roro-moving/moving-frontend…
Obebe-creator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { Metadata } from "next"; | ||
| import { notFound } from "next/navigation"; | ||
|
|
||
| import ChatRoomPageClient from "@/components/chat/ChatRoomPageClient"; | ||
| import { parsePositiveIntId } from "@/lib/utils/parsePositiveIntId"; | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: "채팅방", | ||
| description: "이사 견적 채팅방입니다.", | ||
| }; | ||
|
|
||
| interface ChatRoomPageProps { | ||
| params: Promise<{ roomId: string }>; | ||
| } | ||
|
|
||
| /** | ||
| * 채팅 알림 클릭 시 roomId로 진입하는 페이지 | ||
| * // 2026.08.12 김성현 - [추가] 채팅방 상세 라우트 | ||
| */ | ||
| export default async function ChatRoomPage({ params }: ChatRoomPageProps) { | ||
| const { roomId } = await params; | ||
| const id = parsePositiveIntId(roomId); | ||
|
|
||
| if (id === null) { | ||
| notFound(); | ||
| } | ||
|
|
||
| return <ChatRoomPageClient roomId={id} />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| "use client"; | ||
|
|
||
| import { useRouter } from "next/navigation"; | ||
|
|
||
| import { ConnectedChatRoomModal } from "@/components/chat/ChatRoomModalContainer"; | ||
| import { Text } from "@/components/common/Text"; | ||
| import { useChatRoom } from "@/hooks/useChatRoom"; | ||
| import { getAccessTokenPayload } from "@/lib/auth/accessTokenPayload"; | ||
| import { getAccessToken } from "@/lib/auth/token"; | ||
| import { APP_ROUTES } from "@/lib/constants/appRoutes"; | ||
| import { cn } from "@/lib/utils/cn"; | ||
| import { useAuthStore } from "@/stores/useAuthStore"; | ||
| import type { ChatParticipantRole } from "@/components/chat/ChatActionSheet"; | ||
| import type { ChatRoom } from "@/types/chat"; | ||
|
|
||
| interface ChatRoomPageClientProps { | ||
| roomId: number; | ||
| } | ||
|
|
||
| interface ChatRoomViewMeta { | ||
| participantRole: ChatParticipantRole; | ||
| participantName: string; | ||
| } | ||
|
|
||
| function resolveCurrentUserId(isAuthenticated: boolean, storeUserId?: string): string | null { | ||
| if (storeUserId) { | ||
| return storeUserId; | ||
| } | ||
|
|
||
| if (!isAuthenticated) { | ||
| return null; | ||
| } | ||
|
|
||
| return getAccessTokenPayload(getAccessToken() ?? "").userId ?? null; | ||
| } | ||
|
|
||
| function resolveChatRoomViewMeta(room: ChatRoom, currentUserId: string): ChatRoomViewMeta | null { | ||
| if (room.customer.id === currentUserId) { | ||
| return { | ||
| participantRole: "CUSTOMER", | ||
| participantName: room.mover.name, | ||
| }; | ||
| } | ||
|
|
||
| if (room.mover.id === currentUserId) { | ||
| return { | ||
| participantRole: "MOVER", | ||
| participantName: room.customer.name, | ||
| }; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| function ChatRoomPageState({ | ||
| message, | ||
| actionLabel, | ||
| onAction, | ||
| }: { | ||
| message: string; | ||
| actionLabel?: string; | ||
| onAction?: () => void; | ||
| }) { | ||
| return ( | ||
| <main className="bg-background-surface flex min-h-[calc(100dvh-88px)] items-center justify-center px-24"> | ||
| <div className="flex flex-col items-center gap-16 text-center"> | ||
| <Text as="h1" variant="lg-semibold" className="text-text-primary"> | ||
| {message} | ||
| </Text> | ||
|
|
||
| {actionLabel && onAction ? ( | ||
| <button | ||
| type="button" | ||
| className={cn( | ||
| "border-border-brand text-text-brand rounded-12 border px-20 py-12", | ||
| "hover:bg-background-brand-muted focus-visible:ring-border-brand focus-visible:ring-2 focus-visible:outline-none", | ||
| )} | ||
| onClick={onAction} | ||
| > | ||
| <Text variant="md-semibold">{actionLabel}</Text> | ||
| </button> | ||
| ) : null} | ||
| </div> | ||
| </main> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * 알림 linkUrl(/chats/:roomId)로 진입하는 채팅방 페이지 | ||
| * // 2026.08.12 김성현 - [추가] roomId 기반 채팅방 알림 진입 화면 | ||
| */ | ||
| export default function ChatRoomPageClient({ roomId }: ChatRoomPageClientProps) { | ||
| const router = useRouter(); | ||
| const hasHydrated = useAuthStore((state) => state.hasHydrated); | ||
| const isCheckingAuth = useAuthStore((state) => state.isCheckingAuth); | ||
| const isAuthenticated = useAuthStore((state) => state.isAuthenticated); | ||
| const storeUserId = useAuthStore((state) => state.user?.id); | ||
| const currentUserId = resolveCurrentUserId(isAuthenticated, storeUserId); | ||
| const canLoadRoom = roomId > 0 && hasHydrated && isAuthenticated; | ||
| const chatRoom = useChatRoom(roomId, canLoadRoom); | ||
| const room = chatRoom.data; | ||
|
|
||
| const handleClose = () => { | ||
| if (window.history.length > 1) { | ||
| router.back(); | ||
| return; | ||
| } | ||
|
|
||
| router.push(APP_ROUTES.HOME); | ||
| }; | ||
|
|
||
| if (!hasHydrated || isCheckingAuth) { | ||
| return <ChatRoomPageState message="채팅방을 불러오는 중입니다." />; | ||
| } | ||
|
|
||
| if (!isAuthenticated) { | ||
| return <ChatRoomPageState message="로그인이 필요한 채팅방입니다." />; | ||
| } | ||
|
|
||
| if (chatRoom.isPending) { | ||
| return <ChatRoomPageState message="채팅방을 불러오는 중입니다." />; | ||
| } | ||
|
|
||
| if (chatRoom.isError || !room) { | ||
| return ( | ||
| <ChatRoomPageState | ||
| message="채팅방을 불러오지 못했습니다." | ||
| actionLabel="다시 시도" | ||
| onAction={() => void chatRoom.refetch()} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| if (!currentUserId) { | ||
| return <ChatRoomPageState message="사용자 정보를 확인하는 중입니다." />; | ||
| } | ||
|
|
||
| const viewMeta = resolveChatRoomViewMeta(room, currentUserId); | ||
|
|
||
| if (!viewMeta) { | ||
| return <ChatRoomPageState message="이 채팅방에 접근할 수 없습니다." />; | ||
| } | ||
|
|
||
| return ( | ||
| <ConnectedChatRoomModal | ||
| open | ||
| room={room} | ||
| participantRole={viewMeta.participantRole} | ||
| participantName={viewMeta.participantName} | ||
| estimateSummary={`견적 #${room.estimateId}`} | ||
| onClose={handleClose} | ||
| /> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import EstimateDetailLayout, { | |
| import EstimateDetailPrice from "@/components/estimate/detail/EstimateDetailPrice"; | ||
| import EstimateRequestCancelConfirmModal from "@/components/estimate/requests/EstimateRequestCancelConfirmModal"; | ||
| import { useConfirmEstimate } from "@/hooks/useConfirmEstimate"; | ||
| import { useChatModalSearchParam } from "@/hooks/useChatModalSearchParam"; | ||
| import { useEstimateDetail } from "@/hooks/useEstimateDetail"; | ||
| import { useEstimateRequestCancelFlow } from "@/hooks/useEstimateRequestCancelFlow"; | ||
| import { getApiErrorMessage } from "@/lib/api/getApiErrorMessage"; | ||
|
|
@@ -44,11 +45,18 @@ function PendingEstimateDetailContent({ | |
| }: PendingEstimateDetailContentProps) { | ||
| const [confirmToastMessage, setConfirmToastMessage] = useState<string | null>(null); | ||
| const [isChatModalOpen, setIsChatModalOpen] = useState(false); | ||
| const { isChatOpenRequested, clearChatOpenSearchParam } = useChatModalSearchParam(); | ||
|
|
||
| const estimateRequestId = data.estimateRequest.id; | ||
| const canCancelRequest = isCancelableEstimateRequestStatus(data.estimateRequest.status); | ||
| const displayName = data.mover.nickname || data.mover.name; | ||
| const showChatAction = data.status === "SENT"; | ||
| const isChatOpen = isChatModalOpen || (showChatAction && isChatOpenRequested); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 견적 status가 SENT가 아니면 showChatAction이 false라 모달이 안 열리는데, 파라미터를 지우는 코드가 모달의 onClose 안에만 있어서 chat=open이 URL에 그대로 남아서 견적이 이미 확정으로 바뀐 뒤에 알림을 누른 경우처럼, 알림을 눌러 들어왔는데 아무 반응도 안내도 없는 상태가 될 수 있을 것 같습니다. |
||
|
|
||
| const handleCloseChatModal = () => { | ||
| setIsChatModalOpen(false); | ||
| clearChatOpenSearchParam(); | ||
| }; | ||
|
|
||
| const confirmMutation = useConfirmEstimate(estimateId, { | ||
| onSuccess: () => setConfirmToastMessage("견적이 확정되었어요."), | ||
|
|
@@ -111,12 +119,12 @@ function PendingEstimateDetailContent({ | |
| /> | ||
|
|
||
| <ChatRoomModalContainer | ||
| open={isChatModalOpen} | ||
| open={isChatOpen} | ||
| estimateId={estimateId} | ||
| participantRole="CUSTOMER" | ||
| participantName={displayName} | ||
| estimateSummary={`견적가 - ${data.price.toLocaleString("ko-KR")}원`} | ||
| onClose={() => setIsChatModalOpen(false)} | ||
| onClose={handleCloseChatModal} | ||
| /> | ||
|
|
||
| <EstimateRequestCancelConfirmModal | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| "use client"; | ||
|
|
||
| import { useCallback } from "react"; | ||
| import { usePathname, useRouter, useSearchParams } from "next/navigation"; | ||
|
|
||
| const CHAT_MODAL_SEARCH_PARAM = "chat"; | ||
| const CHAT_MODAL_SEARCH_VALUE = "open"; | ||
|
|
||
| /** | ||
| * 견적 상세 페이지 진입 시 채팅 모달 자동 open query를 처리합니다. | ||
| * // 2026.08.13 김성현 - [추가] 알림 클릭 후 견적 상세에서 채팅 모달 자동 열림 처리 | ||
| */ | ||
| export function useChatModalSearchParam() { | ||
| const router = useRouter(); | ||
| const pathname = usePathname(); | ||
| const searchParams = useSearchParams(); | ||
| const isChatOpenRequested = searchParams.get(CHAT_MODAL_SEARCH_PARAM) === CHAT_MODAL_SEARCH_VALUE; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| const clearChatOpenSearchParam = useCallback(() => { | ||
| if (!searchParams.has(CHAT_MODAL_SEARCH_PARAM)) { | ||
| return; | ||
| } | ||
|
|
||
| const nextSearchParams = new URLSearchParams(searchParams.toString()); | ||
| nextSearchParams.delete(CHAT_MODAL_SEARCH_PARAM); | ||
| const nextSearch = nextSearchParams.toString(); | ||
|
|
||
| router.replace(nextSearch ? `${pathname}?${nextSearch}` : pathname, { scroll: false }); | ||
| }, [pathname, router, searchParams]); | ||
|
|
||
| return { | ||
| isChatOpenRequested, | ||
| clearChatOpenSearchParam, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.