@@ -35,23 +35,26 @@ export const defaultContext = {
35
35
action : ( ...args ) => console . log ( JSON . stringify ( args ) ) ,
36
36
state : console . log ,
37
37
appId : '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' ,
38
+ errors : { }
38
39
} ;
39
40
40
41
export const kitContext = React . createContext ( defaultContext ) ;
41
42
42
- const useBlockContext = ( { blockId, actionId, appId, initialValue } , context ) => {
43
+ export const useBlockContext = ( { blockId, actionId, appId, initialValue } , context ) => {
43
44
const [ value , setValue ] = useState ( initialValue ) ;
44
45
const [ loading , setLoading ] = useState ( false ) ;
45
- const { action, appId : appIdFromContext , state } = useContext ( kitContext ) ;
46
+ const { action, appId : appIdFromContext , state, errors } = useContext ( kitContext ) ;
47
+ const error = errors && actionId && errors [ actionId ] ;
48
+
46
49
if ( [ BLOCK_CONTEXT . SECTION , BLOCK_CONTEXT . ACTION ] . includes ( context ) ) {
47
- return [ { loading, setLoading } , async ( { target : { value } } ) => {
50
+ return [ { loading, setLoading, error } , async ( { target : { value } } ) => {
48
51
setLoading ( true ) ;
49
52
await action ( { blockId, appId : appId || appIdFromContext , actionId, value } ) ;
50
53
setLoading ( false ) ;
51
54
} ] ;
52
55
}
53
56
54
- return [ { loading, setLoading, value } , async ( { target : { value } } ) => {
57
+ return [ { loading, setLoading, value, error } , async ( { target : { value } } ) => {
55
58
setValue ( value ) ;
56
59
setLoading ( true ) ;
57
60
await state ( { blockId, appId, actionId, value } ) ;
@@ -156,11 +159,12 @@ class MessageParser extends UiKitParserMessage {
156
159
}
157
160
158
161
datePicker ( element , context , key ) {
159
- const [ { loading, value } , action ] = useBlockContext ( element , context ) ;
162
+ const [ { loading, value, error } , action ] = useBlockContext ( element , context ) ;
160
163
const { actionId, placeholder } = element ;
161
164
return (
162
165
< InputBox
163
166
key = { key }
167
+ error = { error }
164
168
value = { value }
165
169
mod-mod-loading = { loading }
166
170
id = { actionId }
@@ -244,12 +248,16 @@ class ModalParser extends UiKitParserModal {
244
248
} ) ;
245
249
}
246
250
247
- input ( { element, label, blockId, appId } , context , index ) {
251
+ input ( { element, label, blockId, appId, ...args } , context , index ) {
252
+ const [ { loading, value, error } , action ] = useBlockContext ( { ...element , appId, blockId } , context ) ;
253
+
248
254
return (
249
255
< InputLayoutBlock
256
+ error = { error }
250
257
key = { index }
251
258
index = { index }
252
259
parser = { this }
260
+ context = { context }
253
261
element = { { ...element , appId, blockId } }
254
262
label = { this . plainText ( label ) }
255
263
/>
@@ -261,7 +269,7 @@ class ModalParser extends UiKitParserModal {
261
269
}
262
270
263
271
plainInput ( element , context , index ) {
264
- const [ { loading, value } , action ] = useBlockContext ( element , context ) ;
272
+ const [ { loading, value, error } , action ] = useBlockContext ( element , context ) ;
265
273
const { multiline, actionId, placeholder } = element ;
266
274
const Component = multiline ? TextAreaInput : TextInput ;
267
275
return (
@@ -271,6 +279,7 @@ class ModalParser extends UiKitParserModal {
271
279
id = { actionId }
272
280
name = { actionId }
273
281
rows = { 6 }
282
+ error = { error }
274
283
value = { value }
275
284
onInput = { action }
276
285
placeholder = { this . plainText ( placeholder ) }
@@ -288,3 +297,5 @@ export const UiKitButtons = uiKitButtons();
288
297
export const UiKitText = uiKitText ( textParser ) ;
289
298
export const UiKitMessage = uiKitMessage ( messageParser ) ;
290
299
export const UiKitModal = uiKitModal ( modalParser ) ;
300
+
301
+ export const UiKitComponent = ( { render, blocks} ) => render ( blocks ) ;
0 commit comments