From ae65feb64208cba5ff1b22d9fa220420d255fd02 Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Thu, 9 Mar 2023 12:59:15 +0800 Subject: [PATCH] fix(console): remove "change" button from link social in profile (#3341) --- .../components/LinkAccountSection/index.tsx | 76 +++++++++---------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx b/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx index 098b21787..817379810 100644 --- a/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx +++ b/packages/console/src/pages/Profile/components/LinkAccountSection/index.tsx @@ -21,7 +21,7 @@ import type { SocialUserInfo } from '@/types/profile'; import { socialUserInfoGuard } from '@/types/profile'; import { popupWindow } from '../../utils'; -import type { Action, Row } from '../CardContent'; +import type { Row } from '../CardContent'; import CardContent from '../CardContent'; import NotSet from '../NotSet'; import * as styles from './index.module.scss'; @@ -64,9 +64,15 @@ const LinkAccountSection = ({ user, connectors, onUpdate }: Props) => { const logoSrc = theme === AppearanceMode.DarkMode && logoDark ? logoDark : logo; const relatedUserDetails = user.identities?.[target]?.details; const hasLinked = is(relatedUserDetails, socialUserInfoGuard); - const conditionalUnlinkAction: Action[] = hasLinked - ? [ - { + + return { + key: target, + icon: , + label: , + value: conditional(hasLinked && relatedUserDetails), + renderer: (user) => (user ? : ), + action: hasLinked + ? { name: 'profile.unlink', handler: async () => { const [result] = await showConfirm({ @@ -83,44 +89,32 @@ const LinkAccountSection = ({ user, connectors, onUpdate }: Props) => { onUpdate(); } }, + } + : { + name: 'profile.link', + handler: async () => { + const authUri = await getSocialAuthorizationUri(id); + const callback = new URL( + `${getBasename()}/handle-social`, + window.location.origin + ).toString(); + + const queries = new URLSearchParams({ + redirectTo: authUri, + connectorId: id, + callback, + }); + + const newWindow = popupWindow( + appendPath(adminTenantEndpoint, `/springboard?${queries.toString()}`).href, + 'Link social account with Logto', + 600, + 640 + ); + + newWindow?.focus(); + }, }, - ] - : []; - - return { - key: target, - icon: , - label: , - value: conditional(hasLinked && relatedUserDetails), - renderer: (user) => (user ? : ), - action: [ - ...conditionalUnlinkAction, - { - name: hasLinked ? 'profile.change' : 'profile.link', - handler: async () => { - const authUri = await getSocialAuthorizationUri(id); - const callback = new URL( - `${getBasename()}/handle-social`, - window.location.origin - ).toString(); - - const queries = new URLSearchParams({ - redirectTo: authUri, - connectorId: id, - callback, - }); - - const newWindow = popupWindow( - appendPath(adminTenantEndpoint, `/springboard?${queries.toString()}`).href, - 'Link social account with Logto', - 600, - 640 - ); - - newWindow?.focus(); - }, - }, - ], }; }); }, [