mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
♻️ Adjust “webhooks” property in Redux state
This commit is contained in:
parent
6591889079
commit
67a6d9e765
4 changed files with 26 additions and 14 deletions
|
@ -42,7 +42,6 @@ const useHooks = () => {
|
||||||
// Persistent accessors.
|
// Persistent accessors.
|
||||||
const isSandboxMode = usePersistent( 'useSandbox' );
|
const isSandboxMode = usePersistent( 'useSandbox' );
|
||||||
const isManualConnectionMode = usePersistent( 'useManualConnection' );
|
const isManualConnectionMode = usePersistent( 'useManualConnection' );
|
||||||
const webhooks = usePersistent( 'webhooks' );
|
|
||||||
const merchant = useSelect(
|
const merchant = useSelect(
|
||||||
( select ) => select( STORE_NAME ).merchant(),
|
( select ) => select( STORE_NAME ).merchant(),
|
||||||
[]
|
[]
|
||||||
|
@ -57,6 +56,10 @@ const useHooks = () => {
|
||||||
( select ) => select( STORE_NAME ).features(),
|
( select ) => select( STORE_NAME ).features(),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
const webhooks = useSelect(
|
||||||
|
( select ) => select( STORE_NAME ).webhooks(),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const savePersistent = async ( setter, value ) => {
|
const savePersistent = async ( setter, value ) => {
|
||||||
setter( value );
|
setter( value );
|
||||||
|
|
|
@ -45,12 +45,13 @@ const defaultTransient = Object.freeze( {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
} ),
|
} ),
|
||||||
|
|
||||||
|
webhooks: Object.freeze( [] ),
|
||||||
} );
|
} );
|
||||||
|
|
||||||
const defaultPersistent = Object.freeze( {
|
const defaultPersistent = Object.freeze( {
|
||||||
useSandbox: false,
|
useSandbox: false,
|
||||||
useManualConnection: false,
|
useManualConnection: false,
|
||||||
webhooks: [],
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Reducer logic.
|
// Reducer logic.
|
||||||
|
@ -105,16 +106,18 @@ const commonReducer = createReducer( defaultTransient, defaultPersistent, {
|
||||||
const newState = setPersistent( state, payload.data );
|
const newState = setPersistent( state, payload.data );
|
||||||
|
|
||||||
// Populate read-only properties.
|
// Populate read-only properties.
|
||||||
[ 'wooSettings', 'merchant', 'features' ].forEach( ( key ) => {
|
[ 'wooSettings', 'merchant', 'features', 'webhooks' ].forEach(
|
||||||
if ( ! payload[ key ] ) {
|
( key ) => {
|
||||||
return;
|
if ( ! payload[ key ] ) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
newState[ key ] = Object.freeze( {
|
newState[ key ] = Object.freeze( {
|
||||||
...newState[ key ],
|
...newState[ key ],
|
||||||
...payload[ key ],
|
...payload[ key ],
|
||||||
} );
|
} );
|
||||||
} );
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return newState;
|
return newState;
|
||||||
},
|
},
|
||||||
|
|
|
@ -16,8 +16,14 @@ export const persistentData = ( state ) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const transientData = ( state ) => {
|
export const transientData = ( state ) => {
|
||||||
const { data, merchant, features, wooSettings, ...transientState } =
|
const {
|
||||||
getState( state );
|
data,
|
||||||
|
merchant,
|
||||||
|
features,
|
||||||
|
wooSettings,
|
||||||
|
webhooks,
|
||||||
|
...transientState
|
||||||
|
} = getState( state );
|
||||||
return transientState || EMPTY_OBJ;
|
return transientState || EMPTY_OBJ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ class WebhookSettingsEndpoint extends RestEndpoint {
|
||||||
try {
|
try {
|
||||||
$webhook_list = ( $this->webhook_endpoint->list() )[0];
|
$webhook_list = ( $this->webhook_endpoint->list() )[0];
|
||||||
$webhook_events = array_map(
|
$webhook_events = array_map(
|
||||||
function ( stdClass $webhook ) {
|
static function ( stdClass $webhook ) {
|
||||||
return strtolower( $webhook->name );
|
return strtolower( $webhook->name );
|
||||||
},
|
},
|
||||||
$webhook_list->event_types()
|
$webhook_list->event_types()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue