Remove success modal for Discourse connect

Also show error modals on failed reconnect
This commit is contained in:
raucao committed 2026-10-08 20:45:55 +02:00
1 parent cbd070ed61
commit d837a1ffaa
9 files changed
+135 -79

No files matched your search

@@ -6,7 +6,6 @@ import { on } from '@ember/modifier';
export default class SettingsIntegrationsDiscourseForm extends Component {
@service authorization;
@service integrationResult;
@service sites;
@tracked discourseUrl = '';
@@ -24,7 +23,7 @@ export default class SettingsIntegrationsDiscourseForm extends Component {
this.error = null;
try {
const { transport, integration } = await this.authorization.start(
const { transport } = await this.authorization.start(
'discourse',
this.discourseUrl
);
@@ -33,9 +32,7 @@ export default class SettingsIntegrationsDiscourseForm extends Component {
// away to the forum and returns through the callback route instead.
if (transport === 'extension') {
await this.sites.reload();
// The result replaces this form inside the same modal; closing here
// would dismiss it immediately.
this.integrationResult.show({ success: true, integration });
this.args.close?.();
}
} catch (err) {
if (err?.message === 'Please enter a Discourse URL') {
@@ -35,18 +35,17 @@ export default class SettingsIntegrationsManageList extends Component {
@action
async reconnect(row) {
try {
const { transport, integration } = await this.authorization.start(
row.type,
row.url
);
const { transport } = await this.authorization.start(row.type, row.url);
if (transport === 'extension') {
await this.sites.reload();
await this.sites.refreshIcon(row.url);
this.integrationResult.show({ success: true, integration });
}
} catch (err) {
console.error(`Error reconnecting ${row.type} integration:`, err);
this.integrationResult.show({
error: err?.message ?? 'Unable to reconnect this forum',
});
}
}
+18 -50
View File
@@ -2,14 +2,6 @@ import Component from '@glimmer/component';
import { on } from '@ember/modifier';
export default class IntegrationResult extends Component {
get isSuccess() {
return this.args.props?.result?.success;
}
get isError() {
return this.args.props?.result?.error;
}
get error() {
return this.args.props?.result?.error;
}
@@ -17,55 +9,31 @@ export default class IntegrationResult extends Component {
<template>
<div class="px-4 pt-5 pb-4 sm:p-6">
<div
class="mx-auto flex size-12 items-center justify-center rounded-full
{{if this.isSuccess 'bg-green-100' 'bg-red-100'}}"
class="mx-auto flex size-12 items-center justify-center rounded-full bg-red-100"
>
{{#if this.isSuccess}}
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
data-slot="icon"
aria-hidden="true"
class="size-6 text-green-600"
>
<path
d="m4.5 12.75 6 6 9-13.5"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
{{else}}
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
data-slot="icon"
aria-hidden="true"
class="size-6 text-red-600"
>
<path
d="M6 18L18 6M6 6l12 12"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
{{/if}}
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
data-slot="icon"
aria-hidden="true"
class="size-6 text-red-600"
>
<path
d="M6 18L18 6M6 6l12 12"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div>
<div class="mt-3 text-center sm:mt-5">
<h3 id="modal-title" class="text-base font-semibold text-gray-900">
{{if this.isSuccess "Integration Successful!" "Integration Failed"}}
Integration Failed
</h3>
<div class="mt-2">
<p class="text-sm text-gray-500">
{{#if this.isSuccess}}
Your Discourse forum has been connected successfully. You can now
receive notifications from your forum.
{{else}}
{{this.error}}
{{/if}}
{{this.error}}
</p>
</div>
</div>
-1
View File
@@ -17,7 +17,6 @@ export default class AuthDiscourseCallbackRoute extends Route {
// rebuild it and re-resolve this forum's icon from the network.
await this.sites.reload();
await this.sites.refreshIcon(integration.url);
this.integrationResult.show({ success: true, integration });
} catch (error) {
console.error('Error processing Discourse callback:', error);
this.integrationResult.show({ error: error.message });
+2 -2
View File
@@ -1,8 +1,8 @@
import Service, { service } from '@ember/service';
import IntegrationResult from '../components/settings/integrations/result.gjs';
// Shows the outcome of the most recent integration authorization as a modal,
// both after an in-place extension flow and after the web redirect round-trip.
// Reports a failed integration authorization as a modal, used where there is
// no form to show an inline error (the web redirect callback and reconnects).
export default class IntegrationResultService extends Service {
@service modal;
+1 -1
View File
@@ -19,7 +19,7 @@
border-radius: inherit;
box-shadow:
inset 0 1px 0 var(--icon-edge-top, rgb(255 255 255 / 40%)),
inset 0 -1px 0 rgb(0 0 0 / 30%),
inset 0 -1px 0 rgb(0 0 0 / 20%),
inset 0 0 0 1px rgb(255 255 255 / 10%);
content: '';
pointer-events: none;
@@ -1,14 +1,29 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render } from '@ember/test-helpers';
import { render, fillIn, triggerEvent } from '@ember/test-helpers';
import Discourse from 'dashtab/components/settings/integrations/discourse-form';
function registerServices(owner, overrides = {}) {
const authorization = overrides.authorization ?? {
async start() {
return { transport: 'extension' };
},
};
const sites = overrides.sites ?? { reload: async () => {} };
owner.register('service:authorization', authorization, {
instantiate: false,
});
owner.register('service:sites', sites, { instantiate: false });
}
module(
'Integration | Component | settings/integrations/discourse-form',
function (hooks) {
setupRenderingTest(hooks);
test('it renders', async function (assert) {
registerServices(this.owner);
const noop = () => {};
await render(<template><Discourse @close={{noop}} /></template>);
@@ -18,5 +33,53 @@ module(
assert.dom('form').exists();
assert.dom('#discourse-url').hasNoValue();
});
test('a successful extension connection closes the dialog', async function (assert) {
let reloaded = false;
let closed = false;
registerServices(this.owner, {
sites: {
reload: async () => {
reloaded = true;
},
},
});
const closeDialog = () => {
closed = true;
};
await render(<template><Discourse @close={{closeDialog}} /></template>);
await fillIn('#discourse-url', 'forum.example.com');
await triggerEvent('form', 'submit');
assert.true(reloaded);
assert.true(closed);
});
test('a failed connection shows an inline error', async function (assert) {
let closed = false;
registerServices(this.owner, {
authorization: {
async start() {
throw new Error('Unable to connect to the forum');
},
},
});
const closeDialog = () => {
closed = true;
};
await render(<template><Discourse @close={{closeDialog}} /></template>);
await fillIn('#discourse-url', 'forum.example.com');
await triggerEvent('form', 'submit');
assert.dom().containsText('Unable to connect to the forum');
assert.dom('form').exists();
assert.false(closed);
});
}
);
@@ -311,7 +311,50 @@ module(
]);
assert.strictEqual(sites.reloaded, 1);
assert.deepEqual(sites.refreshed, ['https://bad.example.com']);
assert.strictEqual(integrationResult.shown.length, 1);
assert.strictEqual(integrationResult.shown.length, 0);
});
test('a failed reconnect surfaces the error', async function (assert) {
const sites = new FakeSitesService();
sites.all = [
{
id: 'discourse-bad',
type: 'discourse',
label: 'bad.example.com',
url: 'https://bad.example.com',
},
];
const notifications = new FakeNotificationsService();
notifications.states['discourse-bad'] = {
errorType: 'unauthorized',
error: 'Reconnect this forum',
};
const authorization = {
calls: [],
async start(type, url) {
this.calls.push({ type, url });
throw new Error('Authorization was cancelled');
},
};
const { integrationResult } = register(this.owner, {
sites,
notifications,
authorization,
});
await render(<template><List /></template>);
await click('[data-instance="discourse-bad"] [data-test-reconnect]');
assert.deepEqual(authorization.calls, [
{ type: 'discourse', url: 'https://bad.example.com' },
]);
assert.strictEqual(sites.reloaded, 0);
assert.deepEqual(integrationResult.shown, [
{ error: 'Authorization was cancelled' },
]);
});
test('removing an instance removes the source', async function (assert) {
@@ -8,19 +8,6 @@ module(
function (hooks) {
setupRenderingTest(hooks);
test('it renders a success result', async function (assert) {
const noop = () => {};
await render(
<template>
<Result @props={{hash result=(hash success=true)}} @close={{noop}} />
</template>
);
assert.dom().containsText('Integration Successful!');
assert.dom('button').hasText('Close');
});
test('it renders an error result', async function (assert) {
const noop = () => {};