From 457cb2822426094195f82ad4c6094a0e039b91b9 Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Sat, 15 Apr 2023 08:10:42 +0800 Subject: [PATCH] fix(console): adding social connector should mark related get-started action item as completed (#3693) * fix(console): adding social connector should mark related get-started action item as completed * chore: add changeset --- .changeset/little-carpets-change.md | 6 ++++ .../Connectors/components/Guide/index.tsx | 4 +-- ...285-fix-get-started-passwordless-status.ts | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 .changeset/little-carpets-change.md create mode 100644 packages/schemas/alterations/next-1681267285-fix-get-started-passwordless-status.ts diff --git a/.changeset/little-carpets-change.md b/.changeset/little-carpets-change.md new file mode 100644 index 000000000..2b78321bf --- /dev/null +++ b/.changeset/little-carpets-change.md @@ -0,0 +1,6 @@ +--- +"@logto/console": patch +"@logto/schemas": patch +--- + +Adding social connectors will now mark the related get-started action item as completed. diff --git a/packages/console/src/pages/Connectors/components/Guide/index.tsx b/packages/console/src/pages/Connectors/components/Guide/index.tsx index c18656eed..0a7bec87b 100644 --- a/packages/console/src/pages/Connectors/components/Guide/index.tsx +++ b/packages/console/src/pages/Connectors/components/Guide/index.tsx @@ -125,9 +125,7 @@ function Guide({ connector, onClose }: Props) { }) .json(); - await updateConfigs({ - ...conditional(!isSocialConnector && { passwordlessConfigured: true }), - }); + await updateConfigs({ passwordlessConfigured: true }); onClose(); toast.success(t('general.saved')); diff --git a/packages/schemas/alterations/next-1681267285-fix-get-started-passwordless-status.ts b/packages/schemas/alterations/next-1681267285-fix-get-started-passwordless-status.ts new file mode 100644 index 000000000..4ee3556ef --- /dev/null +++ b/packages/schemas/alterations/next-1681267285-fix-get-started-passwordless-status.ts @@ -0,0 +1,32 @@ +import { sql } from 'slonik'; + +import type { AlterationScript } from '../lib/types/alteration.js'; + +const adminConsoleConfigKey = 'adminConsole'; + +const alteration: AlterationScript = { + up: async (pool) => { + const tenantIds = await pool.many<{ id: string }>(sql`select id from tenants`); + + await Promise.all( + tenantIds.map(async ({ id }) => { + const { count } = await pool.one<{ count: number }>(sql` + select count(*) from connectors + where tenant_id = ${id} and connector_id <> 'logto-sms' and connector_id <> 'logto-email' and connector_id <> 'logto-social-demo'; + `); + + if (count > 0) { + await pool.query(sql` + update logto_configs set value = jsonb_set(value, '{passwordlessConfigured}', 'true') + where tenant_id = ${id} and key = ${adminConsoleConfigKey}; + `); + } + }) + ); + }, + down: async () => { + // Do nothing as there is no alteration made to the DB schemas, only fixing data. + }, +}; + +export default alteration;