11import React , { useState } from "react" ;
22import styled from "styled-components" ;
3- import { useNavigate , useParams } from 'react-router-dom' ;
3+ import { useLocation , useNavigate , useParams } from 'react-router-dom' ;
44
55
66// const token = import.meta.env.VITE_APP_ACCESS_TOKEN;
@@ -10,10 +10,10 @@ const Step4 = () => {
1010 const navigate = useNavigate ( ) ;
1111 const { amateurId } = useParams ( ) ;
1212 const [ accountName , setAccountName ] = useState ( "" ) ;
13- const [ quantity ] = useState ( 1 ) ;
1413 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
15-
16- const isButtonActive = accountName . trim ( ) . length > 0 ;
14+ const isButtonActive = accountName . trim ( ) . length > 0 ;
15+ const location = useLocation ( ) ;
16+ const { peopleCount, selectedTicketId, ticketInfo } = location . state || { } ;
1717
1818 const handleSubmit = async ( ) => {
1919 if ( ! isButtonActive || isSubmitting ) return ;
@@ -31,7 +31,7 @@ const Step4 = () => {
3131 } ,
3232 body : JSON . stringify ( {
3333 accountName,
34- quantity : 1 ,
34+ quantity : peopleCount ,
3535 } ) ,
3636 } ) ;
3737
@@ -50,6 +50,13 @@ const Step4 = () => {
5050 setIsSubmitting ( false ) ;
5151 }
5252 } ;
53+ // 선택된 티켓 정보 찾기
54+ const selectedTicket = ticketInfo . tickets . find (
55+ ( ticket ) => ticket . amateurTicketId === selectedTicketId
56+ ) ;
57+ const ticketPrice = selectedTicket ? selectedTicket . price : 0 ;
58+ // 총 결제 금액 계산
59+ const totalAmount = ticketPrice * peopleCount ;
5360
5461 return (
5562 < Container >
@@ -61,9 +68,8 @@ const Step4 = () => {
6168 </ Sidebar >
6269 < Content >
6370 < LeftContent >
64- < Title > 실종</ Title >
65- < Subtitle > 홍익대학교 학생회관 3층 소극장</ Subtitle >
66- < DateRange > 2024.10.03~2024.10.05</ DateRange >
71+ < Title > { ticketInfo . name } </ Title >
72+ < Subtitle > { ticketInfo . place } </ Subtitle >
6773 < DiscountBox >
6874 < DiscountTitle > 결제수단</ DiscountTitle >
6975 < Options >
@@ -84,29 +90,26 @@ const Step4 = () => {
8490 < Summary >
8591 < Row >
8692 < Label > 일시</ Label >
87- < Value > 2024.10.03 (목) 19:00 </ Value >
93+ < Value > { ticketInfo . schedule } </ Value >
8894 </ Row >
8995 < Row >
9096 < Label > 인원</ Label >
91- < Value > 1 </ Value >
97+ < Value > { peopleCount } </ Value >
9298 </ Row >
9399 < Row >
94100 < Label > 티켓 금액</ Label >
95- < Value > 10,000원</ Value >
96- </ Row >
97- < Row >
98- < Label > 할인</ Label >
99- < Value $active > -3000원</ Value >
101+ < Value > { ticketPrice . toLocaleString ( ) } 원</ Value >
100102 </ Row >
101103 < Row >
102104 < Label > 배송료</ Label >
103105 < Value > 0원 (현장수령)</ Value >
104106 </ Row >
105107 < TotalRow >
106108 < TotalLabel > 총 결제 금액</ TotalLabel >
107- < TotalValue > 7,000원 </ TotalValue >
109+ < TotalValue > { totalAmount . toLocaleString ( ) } 원 </ TotalValue >
108110 </ TotalRow >
109- < Button onClick = { handleSubmit } $active = { isButtonActive && ! isSubmitting } disabled = { isSubmitting } >
111+ < Button
112+ onClick = { handleSubmit } >
110113 { isSubmitting ? '결제 처리 중...' : '다음' }
111114 </ Button >
112115 < PreButton onClick = { ( ) => navigate ( '../step3' ) } > 이전</ PreButton >
@@ -196,18 +199,6 @@ line-height: 25px; /* 156.25% */
196199 margin-bottom: 3px;
197200` ;
198201
199- const DateRange = styled . div `
200- color: #919191;
201-
202- /* Body-tiny-md */
203- font-family: Inter;
204- font-size: 14px;
205- font-style: normal;
206- font-weight: 500;
207- line-height: 18px; /* 128.571% */
208- margin-bottom: 20px;
209- ` ;
210-
211202const DiscountBox = styled . div `
212203display: flex;
213204width: 376px;
@@ -378,8 +369,8 @@ line-height: normal;
378369
379370const Button = styled . button `
380371border-radius: 3px;
381- border: 1px solid ${ ( { active } ) => ( active ? "#A00000" : "#919191" ) } ;
382- background: ${ ( { active } ) => ( active ? " #A00000" : "#919191" ) } ;
372+ border: 1px solid ;
373+ background: #A00000;
383374display: flex;
384375width: 400px;
385376height: 40px;
0 commit comments