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 / block-conditions / components / EditCustomRenderStates.js
jetformbuilder / assets / src / package / block-conditions / components Last commit date
BeforeConditionOptions.js 2 years ago ConditionItem.js 2 years ago ConditionOptions.js 2 years ago ConditionsRepeaterContextProvider.js 2 years ago EditCustomRenderStates.js 2 years ago HumanReadableConditions.js 2 years ago RenderStateOptions.js 2 years ago
EditCustomRenderStates.js
155 lines
1 import ActionModal from '../../action-modal/components/ActionModal';
2
3 const {
4 Button,
5 TextControl,
6 } = wp.components;
7 const {
8 __,
9 } = wp.i18n;
10 const {
11 useState,
12 } = wp.element;
13
14 const {
15 useSelect,
16 useDispatch,
17 } = wp.data;
18
19 const { apiFetch } = wp;
20
21 const {
22 rest_add_state,
23 rest_delete_state,
24 } = window.jetFormBlockConditions;
25
26 const NoticeInfo = ( { ...props } ) => {
27 return <div className="jet-fb-notice" { ...props }>
28 <a href="#" target="_blank">
29 <span className="dashicons"/>
30 { __( 'What is it?', 'jet-form-builder' ) }
31 </a>
32 </div>;
33 };
34
35 const EditCustomRenderStates = ( {
36 setShowModal,
37 changeCurrentItem,
38 currentItem,
39 } ) => {
40
41 const [ isLoading, setButtonLoading ] = useState( false );
42 const [ isLoadingItem, setItemLoading ] = useState( {} );
43 const [ value, setValue ] = useState( '' );
44 let current = [
45 ...currentItem.render_state ?? [],
46 ];
47
48 const {
49 addRenderState,
50 deleteRenderStates,
51 } = useDispatch( 'jet-forms/block-conditions', [] );
52
53 const customStates = useSelect(
54 select => select( 'jet-forms/block-conditions' ).
55 getCustomRenderStates(),
56 [ isLoading, isLoadingItem ],
57 );
58
59 const addState = () => {
60 setButtonLoading( true );
61 rest_add_state.data = { value };
62
63 apiFetch( rest_add_state ).then( response => {
64 onSuccessAdd( response.state );
65 setButtonLoading( false );
66 setShowModal( false );
67
68 } ).catch( error => {
69 console.error( error );
70 setButtonLoading( false );
71 } );
72 };
73
74 const removeState = name => {
75 rest_delete_state.data = { list: [ name ] };
76 setItemLoading( prev => (
77 { ...prev, [ name ]: true }
78 ) );
79
80 apiFetch( rest_delete_state ).then( () => {
81 onDelete( name );
82 } ).catch( console.error ).finally( () => {
83 setItemLoading( prev => (
84 { ...prev, [ name ]: false }
85 ) );
86 } );
87 };
88
89 const onSuccessAdd = state => {
90 addRenderState( state );
91 current.push( state.value );
92
93 changeCurrentItem( {
94 render_state: current,
95 } );
96 };
97
98 const onDelete = name => {
99 deleteRenderStates( name );
100 current = current.filter( item => item !== name );
101
102 changeCurrentItem( {
103 render_state: current,
104 } );
105 };
106
107 return <ActionModal
108 title={ __( 'Register custom render state' ) }
109 onRequestClose={ () => setShowModal( false ) }
110 isUseActions={ false }
111 classNames={ [ 'width-45' ] }
112 >
113 {/*<NoticeInfo style={ { marginBottom: '1em' } }/>*/ }
114 <div className={ 'jet-fb with-button' }>
115 <TextControl
116 value={ value }
117 onChange={ newValue => setValue( newValue ) }
118 placeholder={ __(
119 'Set your custom state name',
120 'jet-form-builder',
121 ) }
122 />
123 <Button
124 variant={ 'secondary' }
125 onClick={ addState }
126 disabled={ isLoading }
127 isBusy={ isLoading }
128 style={ {
129 padding: '7px 12px',
130 height: 'unset',
131 } }
132 >
133 { __( 'Add', 'jet-form-builder' ) }
134 </Button>
135 </div>
136 { Boolean( customStates?.length ) && <>
137 <b className={ 'jet-fb flex mb-05-em' }>
138 { __( 'Manage your custom states:', 'jet-form-builder' ) }
139 </b>
140 <div className={ 'jet-fb-buttons-flex' }>
141 { customStates.map( state => <Button
142 key={ state.value }
143 icon={ 'no-alt' }
144 iconPosition={ 'right' }
145 onClick={ () => removeState( state.value ) }
146 isBusy={ isLoadingItem[ state.value ] ?? false }
147 >
148 { state.label }
149 </Button> ) }
150 </div>
151 </> }
152 </ActionModal>;
153 };
154
155 export default EditCustomRenderStates;