actions.js
2 years ago
constants.js
2 years ago
dispatchers.js
2 years ago
index.js
2 years ago
reducer.js
2 years ago
selectors.js
2 years ago
reducer.js
54 lines
| 1 | import dispatchers from './dispatchers'; |
| 2 | import humanReadablePreset from '../../preset/helpers/humanReadablePreset'; |
| 3 | |
| 4 | const { |
| 5 | select, |
| 6 | } = wp.data; |
| 7 | const { |
| 8 | __, |
| 9 | } = wp.i18n; |
| 10 | |
| 11 | const DEFAULT_STATE = { |
| 12 | messages: [], |
| 13 | ssrCallbacks: [], |
| 14 | formats: [], |
| 15 | ruleTypes: [], |
| 16 | ruleReaders: { |
| 17 | default: function ( rule ) { |
| 18 | const ruleOptions = select( 'jet-forms/validation' ).getRule( |
| 19 | rule.type, |
| 20 | ); |
| 21 | |
| 22 | if ( !ruleOptions ) { |
| 23 | return ''; |
| 24 | } |
| 25 | |
| 26 | let value = rule?.field || rule?.value || ''; |
| 27 | |
| 28 | value = ( |
| 29 | humanReadablePreset( value, 'b' ) || '(no value)' |
| 30 | ); |
| 31 | |
| 32 | return [ |
| 33 | ruleOptions.label, |
| 34 | `<code>${ value }</code>`, |
| 35 | ].join( ' ' ); |
| 36 | }, |
| 37 | ssr: function ( rule ) { |
| 38 | return [ |
| 39 | __( 'Function:', 'jet-form-builder' ), |
| 40 | rule?.value, |
| 41 | ].join( ' ' ); |
| 42 | }, |
| 43 | }, |
| 44 | }; |
| 45 | |
| 46 | export default function ( state = DEFAULT_STATE, action ) { |
| 47 | const callback = dispatchers[ action?.type ]; |
| 48 | |
| 49 | if ( callback ) { |
| 50 | return callback( state, action ); |
| 51 | } |
| 52 | |
| 53 | return state; |
| 54 | } |