PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.1
JetFormBuilder — Dynamic Blocks Form Builder v3.1.1
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / assets / src / package / actions / components / FetchApiButton.js
jetformbuilder / assets / src / package / actions / components Last commit date
ActionFetchButton.js 2 years ago ActionMessages.js 2 years ago ActionMessagesSlotFills.js 2 years ago FetchAjaxButton.js 2 years ago FetchApiButton.js 2 years ago PlaceholderMessage.js 2 years ago RequestButton.js 2 years ago RequestLoadingButton.js 2 years ago UseGlobalControl.js 2 years ago ValidateButton.js 2 years ago ValidateButtonWithStore.js 2 years ago
FetchApiButton.js
64 lines
1 import RequestButton from './RequestButton';
2 import withDispatchActionLoading
3 from '../hooks/withDispatchActionLoading';
4
5 const { compose } = wp.compose;
6
7 const {
8 withDispatch,
9 } = wp.data;
10
11 const { apiFetch } = wp;
12
13 function FetchApiButton( {
14 initialLabel = 'Valid',
15 label = 'InValid',
16 apiArgs = {},
17 loadingState,
18 setLoading,
19 id,
20 setResultSuccess,
21 setResultFail,
22 onLoading = () => {},
23 onSuccess = () => {},
24 onFail = () => {},
25 isHidden = false,
26 } ) {
27
28 const getLabel = () => {
29 if ( (
30 -1 === loadingState.id || loadingState.loading
31 ) && initialLabel ) {
32 return initialLabel;
33 }
34
35 return label;
36 };
37
38 return <RequestButton
39 disabled={ loadingState.loading }
40 hasFetched={ loadingState.id }
41 label={ getLabel() }
42 className={ loadingState.buttonClassName }
43 isHidden={ isHidden }
44 customRequest={ () => {
45 setLoading( id );
46 onLoading();
47
48 apiFetch( apiArgs ).then( response => {
49 setResultSuccess( id, response );
50 onSuccess( response );
51 } ).catch( error => {
52 setResultFail( id );
53 onFail( error );
54 } );
55 } }
56 isDestructive={ loadingState.buttonClassName.includes( 'is-invalid' ) }
57 >
58 <i className="dashicons"/>
59 </RequestButton>;
60 }
61
62 export default compose(
63 withDispatch( withDispatchActionLoading ),
64 )( FetchApiButton );