1- import PropTypes from 'prop-types' ;
2- import { useState } from 'react' ;
3- import '../../../styles/CreateRoomModal.css' ;
4- import { useWalletBalances } from '../../../hooks/useWalletBalances' ;
5- // import { // analyticsService } from '../../../services/// analyticsService';
1+
2+ import PropTypes from 'prop-types' ;
3+ import { useState } from 'react'
4+ import '../../../styles/CreateRoomModal.css'
65
76// Модальное окно для создания комнаты
87const CreateRoomModal = ( { isOpen, onClose } ) => {
9- const [ betAmount , setBetAmount ] = useState ( '' ) ;
10- const [ currency , setCurrency ] = useState ( 'TON' ) ;
11- const { balanceTon, balanceRuble } = useWalletBalances ( ) ;
8+ const [ betAmount , setBetAmount ] = useState ( '' )
9+ const [ currency , setCurrency ] = useState ( 'TON' )
1210
1311 // Проверка валидности суммы ставки
1412 const isValidBetAmount = ( ) => {
15- if ( ! betAmount || betAmount === '' ) return false ;
16- const amount = parseFloat ( betAmount ) ;
17- if ( isNaN ( amount ) || amount <= 0 ) return false ;
18-
19- const selectedBalance = currency === 'TON' ? balanceTon : balanceRuble ;
20- if ( amount > selectedBalance ) {
21- return false ; // Ставка не может превышать баланс
22- }
23-
13+ if ( ! betAmount || betAmount === '' ) return false
14+ const amount = parseFloat ( betAmount )
15+ if ( isNaN ( amount ) || amount <= 0 ) return false
16+
2417 if ( currency === 'TON' ) {
25- return amount >= 1.0 ;
18+ return amount >= 1.0
2619 } else {
27- return amount >= 100 ;
20+ return amount >= 100
2821 }
29- } ;
22+ }
3023
3124 const handleSubmit = ( e ) => {
32- e . preventDefault ( ) ;
25+ e . preventDefault ( )
3326 if ( isValidBetAmount ( ) ) {
34- console . log ( 'Creating a room:' , { betAmount, currency } ) ;
35- // analyticsService.trackRoomCreated('public', 2);
36- // analyticsService.trackEvent('room_creation_attempt', {
37- // bet_amount: parseFloat(betAmount),
38- // currency: currency
39- // });
27+ console . log ( 'Creating a room:' , { betAmount, currency } )
4028 // Здесь будет логика создания комнаты
41- onClose ( ) ;
42- setBetAmount ( '' ) ;
43- setCurrency ( 'TON' ) ;
44- } else {
45- // analyticsService.trackError('validation', 'invalid_bet_amount', 'create_room_modal');
29+ onClose ( )
30+ setBetAmount ( '' )
31+ setCurrency ( 'TON' )
4632 }
47- } ;
33+ }
4834
4935 const handleClose = ( ) => {
50- // analyticsService.trackButtonClick('cancel', 'create_room_modal');
51- onClose ( ) ;
52- setBetAmount ( '' ) ;
53- setCurrency ( 'TON' ) ;
54- } ;
36+ onClose ( )
37+ setBetAmount ( '' )
38+ setCurrency ( 'TON' )
39+ }
5540
56- if ( ! isOpen ) return null ;
57-
58- const selectedBalance = currency === 'TON' ? balanceTon : balanceRuble ;
41+ if ( ! isOpen ) return null
5942
6043 return (
6144 < div className = "modal-overlay" onClick = { handleClose } >
6245 < div className = "create-room-modal" onClick = { ( e ) => e . stopPropagation ( ) } >
46+
6347 < form onSubmit = { handleSubmit } className = "modal-form" >
6448 < div className = "form-group" >
49+
6550 < div className = "radio-group" >
6651 < label className = { `radio-option ${ currency === 'TON' ? 'selected' : '' } ` } >
6752 < input
6853 type = "radio"
6954 name = "currency"
7055 value = "TON"
7156 checked = { currency === 'TON' }
72- onChange = { ( e ) => {
73- setCurrency ( e . target . value ) ;
74- // analyticsService.trackEvent('currency_selected', { currency: 'TON' });
75- } }
57+ onChange = { ( e ) => setCurrency ( e . target . value ) }
7658 />
7759 < span className = "radio-label" > TON</ span >
7860 </ label >
@@ -82,16 +64,13 @@ const CreateRoomModal = ({ isOpen, onClose }) => {
8264 name = "currency"
8365 value = "RUBLE"
8466 checked = { currency === 'RUBLE' }
85- onChange = { ( e ) => {
86- setCurrency ( e . target . value ) ;
87- // analyticsService.trackEvent('currency_selected', { currency: 'RUBLE' });
88- } }
67+ onChange = { ( e ) => setCurrency ( e . target . value ) }
8968 />
9069 < span className = "radio-label" > RUBLE</ span >
9170 </ label >
9271 </ div >
9372 </ div >
94-
73+
9574 < div className = "form-group" >
9675 < input
9776 type = "number"
@@ -102,17 +81,14 @@ const CreateRoomModal = ({ isOpen, onClose }) => {
10281 onChange = { ( e ) => setBetAmount ( e . target . value ) }
10382 placeholder = { currency === 'TON' ? 'Enter amount (min 1.0)' : 'Enter amount (min 100)' }
10483 />
105- < div className = "balance-info" >
106- Available: { selectedBalance . toFixed ( 2 ) } { currency }
107- </ div >
10884 </ div >
109-
85+
11086 < div className = "modal-actions" >
11187 < button type = "button" onClick = { handleClose } className = "cancel-button" >
11288 Cancel
11389 </ button >
114- < button
115- type = "submit"
90+ < button
91+ type = "submit"
11692 className = { `create-button ${ ! isValidBetAmount ( ) ? 'disabled' : '' } ` }
11793 disabled = { ! isValidBetAmount ( ) }
11894 >
@@ -122,8 +98,8 @@ const CreateRoomModal = ({ isOpen, onClose }) => {
12298 </ form >
12399 </ div >
124100 </ div >
125- ) ;
126- } ;
101+ )
102+ }
127103
128104CreateRoomModal . propTypes = {
129105 isOpen : PropTypes . bool . isRequired ,
@@ -132,4 +108,4 @@ CreateRoomModal.propTypes = {
132108 // Добавьте другие пропсы, если они есть
133109} ;
134110
135- export default CreateRoomModal ;
111+ export default CreateRoomModal
0 commit comments