11import { BettingStatsDisplay } from "@/shared/components/BettingStatsDisplay/BettingStatsDisplay" ;
2- import { useNavigate , useParams , useRouter } from "@tanstack/react-router" ;
2+ import {
3+ useNavigate ,
4+ useRouteContext ,
5+ useRouter ,
6+ } from "@tanstack/react-router" ;
37import React , { useCallback , useEffect , useRef , useState } from "react" ;
48import { useSocketIO } from "@/shared/hooks/useSocketIo" ;
59import { BettingTimer } from "@/shared/components/BettingTimer/BettingTimer" ;
@@ -9,27 +13,16 @@ import { endBetRoom, refund } from "./model/api";
913import { useLayoutShift } from "@/shared/hooks/useLayoutShift" ;
1014import { bettingRoomSchema } from "../betting-page/model/schema" ;
1115import { DuckCoinIcon } from "@/shared/icons" ;
12- import { useSuspenseQuery } from "@tanstack/react-query" ;
13- import { bettingRoomQueryKey } from "@/shared/lib/bettingRoomInfo" ;
14- import { getBettingRoomInfo } from "../betting-page/api/getBettingRoomInfo" ;
15- import { responseBetRoomInfo } from "@betting-duck/shared" ;
16+ import BettingDetails from "./ui/BettingDetails" ;
1617
1718function BettingPageAdmin ( ) {
1819 useLayoutShift ( ) ;
19- const router = useRouter ( ) ;
20- const { roomId } = useParams ( {
21- from : "/betting_/$roomId/vote" ,
22- } ) ;
2320
24- const { data } = useSuspenseQuery ( {
25- queryKey : bettingRoomQueryKey ( roomId ) ,
26- queryFn : ( ) => getBettingRoomInfo ( roomId ) ,
27- } ) ;
28- const parsedData = responseBetRoomInfo . safeParse ( data ) ;
29- if ( ! parsedData . success ) {
30- throw new Error ( "방 정보를 불러오는데 실패했습니다." ) ;
31- }
32- const { channel } = parsedData . data ;
21+ const context = useRouteContext ( { from : "/betting_/$roomId/vote/admin" } ) ;
22+ const roomInfo = context . roomInfo ;
23+ const channel = roomInfo . channel ;
24+
25+ const router = useRouter ( ) ;
3326
3427 const [ status , setStatus ] = useState ( channel . status || "active" ) ;
3528 const [ bettingInfo , setBettingInfo ] = useState ( {
@@ -44,10 +37,12 @@ function BettingPageAdmin() {
4437 > ( null ) ;
4538
4639 // Room Information
47- const option1 = channel . options . option1 ;
48- const option2 = channel . options . option2 ;
49- const defaultBetAmount = channel . settings . defaultBetAmount ;
50- const timer = channel . settings . duration ;
40+ const {
41+ id : roomId ,
42+ title,
43+ options : { option1, option2 } ,
44+ settings : { defaultBetAmount, duration : timer } ,
45+ } = channel ;
5146
5247 const socket = useSocketIO ( {
5348 url : "/api/betting" ,
@@ -169,8 +164,8 @@ function BettingPageAdmin() {
169164
170165 const handleCancelClick = async ( ) => {
171166 refund ( roomId )
172- . then ( ( data ) => {
173- console . log ( "API 성공 결과:" , data ) ;
167+ . then ( ( ) => {
168+ sessionStorage . removeItem ( "userInfo" ) ;
174169 navigate ( {
175170 to : "/my-page" ,
176171 } ) ;
@@ -209,10 +204,6 @@ function BettingPageAdmin() {
209204 }
210205 } ;
211206
212- const getTotalParticipants = ( ) => {
213- return bettingInfo . option1 . participants + bettingInfo . option2 . participants ;
214- } ;
215-
216207 const getTotalBetAmount = ( ) => {
217208 return bettingInfo . option1 . currentBets + bettingInfo . option2 . currentBets ;
218209 } ;
@@ -275,37 +266,14 @@ function BettingPageAdmin() {
275266 return (
276267 < div className = "bg-layout-main flex h-full w-full flex-col justify-between" >
277268 < div className = "flex flex-col gap-5" >
278- < BettingTimer socket = { socket } bettingRoomInfo = { parsedData . data } />
269+ < BettingTimer socket = { socket } bettingRoomInfo = { roomInfo } />
279270 < div className = "flex flex-col gap-6 p-5" >
280- < div className = "bg-secondary mb-4 rounded-lg p-3 text-center shadow-inner" >
281- < h1 className = "text-default-disabled text-md mb-1 font-bold" >
282- 베팅 주제
283- </ h1 >
284- < h1 className = "text-primary mb-1 pt-2 text-4xl font-extrabold" >
285- { channel . title }
286- </ h1 >
287- < p >
288- { status === "active"
289- ? "투표가 진행 중입니다. 투표를 취소할 수 있습니다."
290- : "투표가 종료되었습니다. 승부를 결정하세요!" }
291- </ p >
292- < h1 className = "text-default-disabled text-md mb-1 font-bold" >
293- 베팅 정보
294- </ h1 >
295- < p >
296- ∙ 최소 베팅 금액:{ " " }
297- < span className = "font-extrabold" > { defaultBetAmount } </ span >
298- </ p >
299- < p >
300- ∙ 설정한 시간:{ " " }
301- < span className = "font-extrabold" > { timer / 60 } 분</ span >
302- </ p >
303- < p >
304- ∙ 전체 베팅 참여자:{ " " }
305- < span className = "font-extrabold" > { getTotalParticipants ( ) } </ span >
306- </ p >
307- </ div >
308-
271+ < BettingDetails
272+ title = { title }
273+ defaultBetAmount = { defaultBetAmount }
274+ timer = { timer }
275+ status = { status }
276+ />
309277 { status === "timeover" ? (
310278 < div className = "flex w-full overflow-hidden rounded-xl border" >
311279 < div className = "relative flex w-1/2" >
0 commit comments