@@ -3,6 +3,7 @@ import { Text, Button } from '@deriv/ui';
33import styles from '../api-token.form.module.scss' ;
44import useApiToken from '@site/src/hooks/useApiToken' ;
55import { FieldErrorsImpl , UseFormRegisterReturn } from 'react-hook-form' ;
6+ import CustomErrors from './CustomErrors' ;
67
78type TCreateTokenField = {
89 register : UseFormRegisterReturn ;
@@ -49,30 +50,10 @@ const CreateTokenField = ({
4950 const token_name_exists =
5051 getTokenNames . includes ( input_value . toLowerCase ( ) ) && Object . keys ( errors ) . length === 0 ;
5152 const has_custom_errors = token_name_exists || ( tokens_limit_reached && input_value !== '' ) ;
52- const has_no_errors = Object . values ( errors ) . length === 0 && ! has_custom_errors ;
5353 const disable_button =
5454 token_name_exists || Object . keys ( errors ) . length > 0 || input_value === '' || has_custom_errors ;
5555 const error_border_active = token_name_exists || errors . name || has_custom_errors ;
5656
57- const CustomErrors = ( ) => {
58- if ( token_name_exists ) {
59- return (
60- < div className = 'error-message' >
61- < p > That name is taken. Choose another.</ p >
62- </ div >
63- ) ;
64- }
65- if ( tokens_limit_reached && input_value !== '' ) {
66- return (
67- < div className = 'error-message' >
68- < p > You've reached 30 tokens creation limit.</ p >
69- </ div >
70- ) ;
71- }
72-
73- return < > </ > ;
74- } ;
75-
7657 return (
7758 < React . Fragment >
7859 < div className = { styles . step_title } >
@@ -105,30 +86,11 @@ const CreateTokenField = ({
10586 { errors . name . message }
10687 </ Text >
10788 ) }
108- < CustomErrors />
109- { has_no_errors && (
110- < div className = { styles . helperText } >
111- < ul >
112- < li >
113- < span > Only alphanumeric characters with spaces and underscores are allowed.</ span >
114- </ li >
115- < li >
116- < span > The name must be between 2 to 32 characters.</ span >
117- </ li >
118- < li >
119- < span > Duplicate token names aren't allowed.</ span >
120- </ li >
121- < li >
122- < span >
123- The name cannot contain “Binary”, “Deriv”, or similar words.
124- </ span >
125- </ li >
126- < li >
127- < span > You can create up to 30 tokens for this account.</ span >
128- </ li >
129- </ ul >
130- </ div >
131- ) }
89+ < CustomErrors
90+ token_name_exists = { token_name_exists }
91+ tokens_limit_reached = { tokens_limit_reached }
92+ input_value = { input_value }
93+ />
13294 </ React . Fragment >
13395 ) ;
13496} ;
0 commit comments