Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 22 additions & 5 deletions routes/connectors-home/ai-plugin-callout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* WordPress dependencies
*/
import { speak } from '@wordpress/a11y';
import { Button, ExternalLink } from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect, useDispatch } from '@wordpress/data';
Expand All @@ -12,6 +11,7 @@ import {
useState,
} from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
import { addQueryArgs } from '@wordpress/url';

/**
Expand Down Expand Up @@ -123,6 +123,8 @@ export function AiPluginCallout() {
}, [] );

const { saveEntityRecord } = useDispatch( coreStore );
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );

const installPlugin = async () => {
setIsBusy( true );
Expand All @@ -134,9 +136,18 @@ export function AiPluginCallout() {
{ throwOnError: true }
);
setJustActivated( true );
speak( __( 'AI plugin installed and activated successfully.' ) );
createSuccessNotice(
__( 'AI plugin installed and activated successfully.' ),
{
id: 'ai-plugin-install-success',
type: 'snackbar',
}
);
} catch {
speak( __( 'Failed to install the AI plugin.' ), 'assertive' );
createErrorNotice( __( 'Failed to install the AI plugin.' ), {
id: 'ai-plugin-install-error',
type: 'snackbar',
} );
} finally {
setIsBusy( false );
}
Expand All @@ -152,9 +163,15 @@ export function AiPluginCallout() {
{ throwOnError: true }
);
setJustActivated( true );
speak( __( 'AI plugin activated successfully.' ) );
createSuccessNotice( __( 'AI plugin activated successfully.' ), {
id: 'ai-plugin-activate-success',
type: 'snackbar',
} );
} catch {
speak( __( 'Failed to activate the AI plugin.' ), 'assertive' );
createErrorNotice( __( 'Failed to activate the AI plugin.' ), {
id: 'ai-plugin-activate-error',
type: 'snackbar',
} );
} finally {
setIsBusy( false );
}
Expand Down
1 change: 1 addition & 0 deletions routes/connectors-home/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@wordpress/components": "file:../../packages/components",
"@wordpress/connectors": "file:../../packages/connectors",
"@wordpress/core-data": "file:../../packages/core-data",
"@wordpress/notices": "file:../../packages/notices",
"@wordpress/data": "file:../../packages/data",
"@wordpress/element": "file:../../packages/element",
"@wordpress/i18n": "file:../../packages/i18n",
Expand Down
57 changes: 42 additions & 15 deletions routes/connectors-home/use-connector-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* WordPress dependencies
*/
import { speak } from '@wordpress/a11y';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect, useDispatch } from '@wordpress/data';
import { useState } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';

import type { __experimentalApiKeySource as ApiKeySource } from '@wordpress/connectors';

Expand Down Expand Up @@ -155,6 +155,8 @@ export function useConnectorPlugin( {
( pluginStatusOverride === 'active' && !! currentApiKey );

const { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );

const installPlugin = async () => {
if ( ! pluginSlug ) {
Expand All @@ -172,21 +174,28 @@ export function useConnectorPlugin( {
// Re-fetch settings since the new plugin may register new settings.
invalidateResolution( 'getEntityRecord', [ 'root', 'site' ] );
setIsExpanded( true );
speak(
createSuccessNotice(
sprintf(
/* translators: %s: Name of the connector (e.g. "OpenAI"). */
__( 'Plugin for %s installed and activated successfully.' ),
connectorName
)
),
{
id: 'connector-plugin-install-success',
type: 'snackbar',
}
);
} catch {
speak(
createErrorNotice(
sprintf(
/* translators: %s: Name of the connector (e.g. "OpenAI"). */
__( 'Failed to install plugin for %s.' ),
connectorName
),
'assertive'
{
id: 'connector-plugin-install-error',
type: 'snackbar',
}
);
} finally {
setIsBusy( false );
Expand All @@ -212,21 +221,28 @@ export function useConnectorPlugin( {
// Re-fetch settings since the activated plugin may register new settings.
invalidateResolution( 'getEntityRecord', [ 'root', 'site' ] );
setIsExpanded( true );
speak(
createSuccessNotice(
sprintf(
/* translators: %s: Name of the connector (e.g. "OpenAI"). */
__( 'Plugin for %s activated successfully.' ),
connectorName
)
),
{
id: 'connector-plugin-activate-success',
type: 'snackbar',
}
);
} catch {
speak(
createErrorNotice(
sprintf(
/* translators: %s: Name of the connector (e.g. "OpenAI"). */
__( 'Failed to activate plugin for %s.' ),
connectorName
),
'assertive'
{
id: 'connector-plugin-activate-error',
type: 'snackbar',
}
);
} finally {
setIsBusy( false );
Expand Down Expand Up @@ -301,12 +317,16 @@ export function useConnectorPlugin( {
}

setConnectedState( true );
speak(
createSuccessNotice(
sprintf(
/* translators: %s: Name of the connector (e.g. "OpenAI"). */
__( '%s connected successfully.' ),
connectorName
)
),
{
id: 'connector-connect-success',
type: 'snackbar',
}
);
} catch ( error ) {
// eslint-disable-next-line no-console
Expand All @@ -327,23 +347,30 @@ export function useConnectorPlugin( {
);
// Store auto-updates; currentApiKey reactively becomes ''.
setConnectedState( false );
speak(
createSuccessNotice(
sprintf(
/* translators: %s: Name of the connector (e.g. "OpenAI"). */
__( '%s disconnected.' ),
connectorName
)
),
{
id: 'connector-disconnect-success',
type: 'snackbar',
}
);
} catch ( error ) {
// eslint-disable-next-line no-console
console.error( 'Failed to remove API key:', error );
speak(
createErrorNotice(
sprintf(
/* translators: %s: Name of the connector (e.g. "OpenAI"). */
__( 'Failed to disconnect %s.' ),
connectorName
),
'assertive'
{
id: 'connector-disconnect-error',
type: 'snackbar',
}
);
throw error;
}
Expand Down
Loading