main.js
105 lines
| 1 | const { compose } = wp.compose; |
| 2 | |
| 3 | const { |
| 4 | withSelect, |
| 5 | withDispatch, |
| 6 | } = wp.data; |
| 7 | const { |
| 8 | __, |
| 9 | } = wp.i18n; |
| 10 | |
| 11 | const { |
| 12 | TextControl, |
| 13 | SelectControl, |
| 14 | withNotices, |
| 15 | } = wp.components; |
| 16 | |
| 17 | const { |
| 18 | useEffect, |
| 19 | } = wp.element; |
| 20 | |
| 21 | const { |
| 22 | renderGateway, |
| 23 | } = JetFBActions; |
| 24 | |
| 25 | const { |
| 26 | withSelectGateways, |
| 27 | withDispatchGateways, |
| 28 | } = JetFBHooks; |
| 29 | |
| 30 | const { |
| 31 | ToggleControl, |
| 32 | } = JetFBComponents; |
| 33 | |
| 34 | function PaypalMain( { |
| 35 | setGatewayRequest, |
| 36 | gatewaySpecific, |
| 37 | setGatewaySpecific, |
| 38 | gatewayScenario, |
| 39 | setGatewayScenario, |
| 40 | getSpecificOrGlobal, |
| 41 | additionalSourceGateway, |
| 42 | specificGatewayLabel, |
| 43 | noticeOperations, |
| 44 | noticeUI, |
| 45 | } ) { |
| 46 | |
| 47 | const { |
| 48 | id: scenario = 'PAY_NOW', |
| 49 | } = gatewayScenario; |
| 50 | |
| 51 | useEffect( () => { |
| 52 | setGatewayRequest( { id: scenario } ); |
| 53 | }, [ scenario ] ); |
| 54 | |
| 55 | useEffect( () => { |
| 56 | setGatewayRequest( { id: scenario } ); |
| 57 | }, [] ); |
| 58 | |
| 59 | return <> |
| 60 | { noticeUI } |
| 61 | <ToggleControl |
| 62 | checked={ gatewaySpecific.use_global } |
| 63 | onChange={ use_global => setGatewaySpecific( { use_global } ) } |
| 64 | > |
| 65 | { __( 'Use', 'jet-form-builder' ) + ' ' } |
| 66 | <a href={ JetFormEditorData.global_settings_url + |
| 67 | '#payments-gateways__paypal' }> |
| 68 | { __( 'Global Settings', 'jet-form-builder' ) } |
| 69 | </a> |
| 70 | </ToggleControl> |
| 71 | <TextControl |
| 72 | label={ specificGatewayLabel( 'client_id' ) } |
| 73 | key="paypal_client_id_setting" |
| 74 | value={ getSpecificOrGlobal( 'client_id' ) } |
| 75 | onChange={ client_id => setGatewaySpecific( { client_id } ) } |
| 76 | disabled={ gatewaySpecific.use_global } |
| 77 | /> |
| 78 | <TextControl |
| 79 | label={ specificGatewayLabel( 'secret' ) } |
| 80 | key="paypal_secret_setting" |
| 81 | value={ getSpecificOrGlobal( 'secret' ) } |
| 82 | onChange={ secret => setGatewaySpecific( { secret } ) } |
| 83 | disabled={ gatewaySpecific.use_global } |
| 84 | /> |
| 85 | <SelectControl |
| 86 | labelPosition="side" |
| 87 | label={ specificGatewayLabel( 'gateway_type' ) } |
| 88 | value={ scenario } |
| 89 | onChange={ id => { |
| 90 | setGatewayScenario( { id } ); |
| 91 | } } |
| 92 | options={ additionalSourceGateway.scenarios } |
| 93 | /> |
| 94 | { renderGateway( 'paypal', { noticeOperations }, scenario ) } |
| 95 | </>; |
| 96 | } |
| 97 | |
| 98 | export default compose( |
| 99 | withSelect( withSelectGateways ), |
| 100 | withDispatch( withDispatchGateways ), |
| 101 | withNotices, |
| 102 | )( PaypalMain ); |
| 103 | |
| 104 | |
| 105 |