Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,9 @@ private function get_settings_field_by_key( $key ) {
protected function sanitize_settings_field_value( $field, $value ) {
$type = $field['type'] ?? 'text';
switch ( $type ) {
case 'hidden':
case 'oauth':
return $value; // Read-only or managed programmatically.
case 'checkbox':
return (bool) $value;
case 'number':
Expand Down
15 changes: 10 additions & 5 deletions src/reader-activation/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ const mergeStrategies = new Map();
*/
function rehydrateItem( key, serverValue ) {
const merge = mergeStrategies.get( key );
if ( merge ) {
const clientValue = _get( key );
_set( key, merge( serverValue, clientValue ) );
} else {
_set( key, serverValue );
try {
if ( merge ) {
const clientValue = _get( key );
_set( key, merge( serverValue, clientValue ) );
} else {
_set( key, serverValue );
}
} catch ( err ) {
// eslint-disable-next-line no-console
console.warn( `Unable to rehydrated ${ key }`, err );
}
}

Expand Down
30 changes: 29 additions & 1 deletion src/wizards/audience/views/integrations/settings-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CheckboxControl, ExternalLink, TextareaControl } from '@wordpress/compo
/**
* Internal dependencies.
*/
import { Grid, SelectControl, TextControl } from '../../../../../packages/components/src';
import { Button, Grid, SelectControl, TextControl } from '../../../../../packages/components/src';

/**
* Render a single settings field.
Expand All @@ -32,6 +32,34 @@ export const SettingsField = ( { field, value, onChange } ) => {
);

switch ( type ) {
case 'hidden':
return null;
case 'oauth': {
const isConnected = !! value;
const oauthUrl = field.oauth_url || '';
return (
<div key={ key } className="newspack-oauth-field">
<p>
<strong>{ label }</strong>
</p>
{ description && <p>{ description }</p> }
{ isConnected ? (
<>
<p>{ value }</p>
{ field.disconnect_url && (
<Button variant="secondary" isDestructive href={ field.disconnect_url }>
{ __( 'Disconnect', 'newspack-plugin' ) }
</Button>
) }
</>
) : (
<Button variant="primary" href={ oauthUrl } disabled={ ! oauthUrl }>
{ __( 'Connect', 'newspack-plugin' ) }
</Button>
) }
</div>
);
}
case 'metadata': {
const selectedFields = Array.isArray( value ) ? value : [];
const normalizedOptions = ( options || [] ).map( option =>
Expand Down
Loading