@@ -75,6 +75,14 @@ const StatePropsPanel = ({ isThemeLight, data}): JSX.Element => {
75
75
let currKey ;
76
76
const submitNewState = ( e ) => {
77
77
e . preventDefault ( ) ;
78
+
79
+ // don't allow them to submit state without all fields
80
+ if ( ! inputKey || ! inputType || ! inputValue ) {
81
+ setErrorStatus ( true ) ;
82
+ setErrorMsg ( 'All fields are required' ) ;
83
+ return ;
84
+ }
85
+
78
86
const statesArray = currentComponent . stateProps ;
79
87
//loop though array, access each obj at key property
80
88
let keyToInt = parseInt ( inputKey [ 0 ] ) ;
@@ -83,6 +91,24 @@ const StatePropsPanel = ({ isThemeLight, data}): JSX.Element => {
83
91
setErrorMsg ( 'Key name can not start with int.' ) ;
84
92
return ;
85
93
}
94
+
95
+ // carly LegacyPD
96
+ // check here to see if state has already been created with the submitted key
97
+ // iterate through all the state keys in all of the components in the app
98
+ // outer for loop: iterating through all of the components in the app
99
+ for ( let i = 0 ; i < state . components . length ; i ++ ) {
100
+ // inner for loop iterating through the stateProps array for each component
101
+ for ( let j = 0 ; j < state . components [ i ] . stateProps . length ; j ++ ) {
102
+
103
+ // if find piece of state with the same key as inputKey, create an error
104
+ if ( inputKey === state . components [ i ] . stateProps [ j ] [ "key" ] ) {
105
+ setErrorStatus ( true ) ;
106
+ setErrorMsg ( 'Key name already in use.' ) ;
107
+ return ;
108
+ }
109
+ }
110
+ }
111
+
86
112
const newState = {
87
113
// check if array is not empty => true find last elem in array. get id and increment by 1 || else 1
88
114
id : statesArray . length > 0 ? statesArray [ statesArray . length - 1 ] . id + 1 : 1 ,
@@ -161,6 +187,7 @@ const StatePropsPanel = ({ isThemeLight, data}): JSX.Element => {
161
187
value = { inputKey }
162
188
error = { errorStatus }
163
189
onChange = { ( e ) => setInputKey ( e . target . value ) }
190
+ helperText = { errorStatus ? errorMsg : '' }
164
191
className = { isThemeLight ? `${ classes . rootLight } ${ classes . inputTextLight } ` : `${ classes . rootDark } ${ classes . inputTextDark } ` }
165
192
/>
166
193
< TextField
0 commit comments