0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

fix(console): remove "change" button from link social in profile (#3341)

This commit is contained in:
Charles Zhao 2023-03-09 12:59:15 +08:00 committed by GitHub
parent 310c543f93
commit ae65feb642
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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: <ImageWithErrorFallback src={logoSrc} />,
label: <UnnamedTrans resource={name} />,
value: conditional(hasLinked && relatedUserDetails),
renderer: (user) => (user ? <UserInfoCard user={user} avatarSize="small" /> : <NotSet />),
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: <ImageWithErrorFallback src={logoSrc} />,
label: <UnnamedTrans resource={name} />,
value: conditional(hasLinked && relatedUserDetails),
renderer: (user) => (user ? <UserInfoCard user={user} avatarSize="small" /> : <NotSet />),
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();
},
},
],
};
});
}, [