general-preset.js
49 lines
| 1 | const { |
| 2 | GlobalField, |
| 3 | AvailableMapField, |
| 4 | } = JetFBComponents; |
| 5 | |
| 6 | const { withPreset } = JetFBActions; |
| 7 | |
| 8 | const { Fragment } = wp.element; |
| 9 | |
| 10 | function GeneralPreset( { |
| 11 | value, |
| 12 | availableFields, |
| 13 | isMapFieldVisible, |
| 14 | isVisible, |
| 15 | onChange, |
| 16 | } ) { |
| 17 | const position = 'general'; |
| 18 | |
| 19 | const onChangeValue = ( newValue, name ) => { |
| 20 | onChange( { ...value, [ name ]: newValue } ); |
| 21 | } |
| 22 | |
| 23 | return <Fragment key={ 'jfb-general-preset-main-wrapper' }> |
| 24 | { window.JetFormEditorData.presetConfig.global_fields.map( ( data, index ) => <GlobalField |
| 25 | key={ data.name + index } |
| 26 | value={ value } |
| 27 | index={ index } |
| 28 | data={ data } |
| 29 | options={ data.options } |
| 30 | onChangeValue={ onChangeValue } |
| 31 | isVisible={ isVisible } |
| 32 | position={ position } |
| 33 | /> ) } |
| 34 | |
| 35 | { value.from && ( |
| 36 | availableFields.map( ( field, index ) => <AvailableMapField |
| 37 | key={ field + index } |
| 38 | fieldsMap={ value.fields_map } |
| 39 | field={ field } |
| 40 | index={ index } |
| 41 | onChangeValue={ onChangeValue } |
| 42 | isMapFieldVisible={ isMapFieldVisible } |
| 43 | value={ value } |
| 44 | /> ) |
| 45 | ) } |
| 46 | </Fragment>; |
| 47 | } |
| 48 | |
| 49 | export default withPreset( GeneralPreset ); |