@@ -36,8 +36,7 @@ const TermsAndConditions: React.FC<TTermsAndConditionsProps> = ({ register }) =>
36
36
className = 'app-register-container__tnc__link'
37
37
>
38
38
< Translate > terms and conditions</ Translate >
39
- </ Link >
40
- { ' ' }
39
+ </ Link > { ' ' }
41
40
{ translate ( { message : 'and General Business Partners' } ) } { ' ' }
42
41
< Link
43
42
href = 'https://docs.deriv.com/tnc/business-partners-general-terms.pdf'
@@ -76,16 +75,23 @@ const AppRegister: React.FC = () => {
76
75
const {
77
76
register,
78
77
handleSubmit,
78
+ watch,
79
79
formState : { errors } ,
80
80
} = useForm < IBaseRegisterAppForm > ( {
81
81
mode : 'all' ,
82
+ reValidateMode : 'onChange' ,
82
83
resolver : yupResolver ( baseAppRegisterSchema ) ,
83
84
} ) ;
84
85
85
86
const has_error = Object . entries ( errors ) . length !== 0 ;
87
+ const watchedValues = watch ( ) ;
88
+ const name_value = watchedValues . name || '' ;
89
+ const tnc_approval = watchedValues . tnc_approval || false ;
90
+ const is_button_disabled = has_error || ! name_value || ! tnc_approval ;
91
+
86
92
const { deviceType } = useDeviceType ( ) ;
87
93
const is_desktop = deviceType === 'desktop' ;
88
- const { setAppRegisterModalOpen, updateCurrentTab, getApps, handleCurrentUpdatingItem } =
94
+ const { setAppRegisterModalOpen, updateCurrentTab, getApps, handleCurrentUpdatingItem, apps } =
89
95
useAppManager ( ) ;
90
96
const { send : registerApp , data, error, clear, is_loading } = useWS ( 'app_register' ) ;
91
97
const [ created_app_data , setCreatedAppData ] = useState ( { } ) ;
@@ -135,26 +141,43 @@ const AppRegister: React.FC = () => {
135
141
< div className = { `${ has_error && 'error-border' } app-register-container__fields` } >
136
142
< div className = 'app-register-container__fields__input' >
137
143
< input
138
- { ...register ( 'name' ) }
139
- onChange = { handleErrorOnChange }
144
+ { ...register ( 'name' , {
145
+ onChange : ( e ) => {
146
+ handleErrorOnChange ( ) ;
147
+ } ,
148
+ } ) }
140
149
placeholder = { translate ( { message : `Enter your app's name` } ) }
141
150
className = 'app-register-container__input'
142
151
/>
143
152
</ div >
144
- < div className = 'app-register-container__fields__button' >
145
- < Button
146
- color = 'coral'
147
- size = { is_desktop ? 'lg' : 'md' }
148
- variant = 'primary'
149
- role = 'submit'
150
- disabled = { has_error }
151
- label = { translate ( { message : 'Register now' } ) }
152
- > </ Button >
153
- </ div >
154
153
</ div >
155
154
< span className = 'error' > { errors ?. tnc_approval ?. message || error ?. error ?. message } </ span >
155
+
156
156
< Restrictions error = { errors ?. name ?. message } />
157
157
< TermsAndConditions register = { register ( 'tnc_approval' ) } />
158
+ < div className = 'app-register-container__wrap-button' >
159
+ < Button
160
+ variant = 'secondary'
161
+ size = { is_desktop ? 'lg' : 'md' }
162
+ color = 'black'
163
+ type = 'button'
164
+ disabled = { ! apps ?. length }
165
+ onClick = { ( ) => {
166
+ updateCurrentTab ( TDashboardTab . MANAGE_APPS ) ;
167
+ } }
168
+ >
169
+ < Translate > Cancel</ Translate >
170
+ </ Button >
171
+
172
+ < Button
173
+ color = 'coral'
174
+ size = { is_desktop ? 'lg' : 'md' }
175
+ variant = 'primary'
176
+ role = 'submit'
177
+ disabled = { is_button_disabled }
178
+ label = { translate ( { message : 'Register now' } ) }
179
+ > </ Button >
180
+ </ div >
158
181
</ div >
159
182
</ form >
160
183
< AppRegisterSuccessModal onCancel = { handleConfigureLater } onConfigure = { handleAppConfigure } />
0 commit comments