Skip to content

Commit b289566

Browse files
authored
fix(clerk-js,ui,shared): Display enterprise connection icon on account linking dropdown (#8203)
1 parent 43d2776 commit b289566

6 files changed

Lines changed: 48 additions & 15 deletions

File tree

.changeset/cozy-lands-grow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/shared': patch
4+
---
5+
6+
Add `provider` and `logoPublicUrl` to `EnterpriseConnection` resource

.changeset/polite-camels-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/ui': patch
3+
---
4+
5+
Display enterprise connection icon on account linking dropdown within `UserProfile`

packages/clerk-js/src/core/resources/EnterpriseConnection.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export class EnterpriseConnection extends BaseResource implements EnterpriseConn
8181
id!: string;
8282
name!: string;
8383
active!: boolean;
84+
provider!: string;
85+
logoPublicUrl: string | null = null;
8486
domains: string[] = [];
8587
organizationId: string | null = null;
8688
syncUserAttributes!: boolean;
@@ -105,6 +107,8 @@ export class EnterpriseConnection extends BaseResource implements EnterpriseConn
105107
this.id = data.id;
106108
this.name = data.name;
107109
this.active = data.active;
110+
this.provider = data.provider;
111+
this.logoPublicUrl = data.logo_public_url ?? null;
108112
this.domains = data.domains ?? [];
109113
this.organizationId = data.organization_id ?? null;
110114
this.syncUserAttributes = data.sync_user_attributes;
@@ -126,6 +130,8 @@ export class EnterpriseConnection extends BaseResource implements EnterpriseConn
126130
id: this.id,
127131
name: this.name,
128132
active: this.active,
133+
provider: this.provider,
134+
logo_public_url: this.logoPublicUrl,
129135
domains: this.domains,
130136
organization_id: this.organizationId,
131137
sync_user_attributes: this.syncUserAttributes,

packages/clerk-js/src/core/resources/__tests__/User.test.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UserJSON } from '@clerk/shared/types';
1+
import type { EnterpriseConnectionJSON, UserJSON } from '@clerk/shared/types';
22
import { describe, expect, it, vi } from 'vitest';
33

44
import { BaseResource } from '../internal';
@@ -80,22 +80,37 @@ describe('User', () => {
8080
});
8181

8282
it('fetches enterprise connections', async () => {
83-
const enterpriseConnectionsJSON = [
83+
const enterpriseConnectionsJSON: EnterpriseConnectionJSON[] = [
8484
{
8585
id: 'ec_123',
86-
object: 'enterprise_account_connection',
86+
object: 'enterprise_connection',
8787
name: 'Acme Corp SSO',
8888
active: true,
8989
allow_organization_account_linking: true,
90-
domain: 'acme.com',
91-
protocol: 'saml',
9290
provider: 'saml_okta',
9391
logo_public_url: null,
92+
domains: ['acme.com'],
93+
organization_id: null,
9494
sync_user_attributes: true,
95-
allow_subdomains: false,
96-
allow_idp_initiated: false,
9795
disable_additional_identifications: false,
98-
enterprise_connection_id: 'ec_123',
96+
custom_attributes: [],
97+
oauth_config: null,
98+
saml_connection: {
99+
id: 'saml_123',
100+
name: 'Acme Corp SSO',
101+
active: true,
102+
idp_entity_id: 'https://idp.acme.com/entity',
103+
idp_sso_url: 'https://idp.acme.com/sso',
104+
idp_certificate: 'MIICertificatePlaceholder',
105+
idp_metadata_url: 'https://idp.acme.com/metadata',
106+
idp_metadata: '',
107+
acs_url: 'https://clerk.example.com/v1/saml/acs',
108+
sp_entity_id: 'https://clerk.example.com',
109+
sp_metadata_url: 'https://clerk.example.com/v1/saml/metadata',
110+
allow_subdomains: false,
111+
allow_idp_initiated: false,
112+
force_authn: false,
113+
},
99114
created_at: 1234567890,
100115
updated_at: 1234567890,
101116
},

packages/shared/src/types/enterpriseConnection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export interface EnterpriseConnectionJSON extends ClerkResourceJSON {
55
object: 'enterprise_connection';
66
name: string;
77
active: boolean;
8+
provider: string;
9+
logo_public_url?: string | null;
810
domains?: string[];
911
organization_id?: string | null;
1012
sync_user_attributes: boolean;
@@ -23,6 +25,8 @@ export interface EnterpriseConnectionResource extends ClerkResource {
2325
id: string;
2426
name: string;
2527
active: boolean;
28+
provider: string;
29+
logoPublicUrl: string | null;
2630
domains: string[];
2731
organizationId: string | null;
2832
syncUserAttributes: boolean;

packages/ui/src/components/UserProfile/EnterpriseAccountsSection.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import { ProviderIcon } from '../../common';
1414
import { useUserProfileContext } from '../../contexts';
1515
import { Badge, Box, descriptors, Flex, localizationKeys, Text } from '../../customizables';
1616
import { Action } from '../../elements/Action';
17-
18-
const GENERIC_ENTERPRISE_PROVIDER_ICON_ID = 'custom_enterprise' as OAuthProvider;
19-
2017
const EnterpriseConnectMenuButton = (props: { connection: EnterpriseConnectionResource }) => {
2118
const { connection } = props;
2219
const card = useCardState();
@@ -54,7 +51,8 @@ const EnterpriseConnectMenuButton = (props: { connection: EnterpriseConnectionRe
5451
});
5552
};
5653

57-
const providerIconUrl = connection.oauthConfig?.logoPublicUrl?.trim() ?? '';
54+
const providerIconId = connection.provider.replace(/(oauth_|saml_)/, '').trim() as OAuthProvider;
55+
const providerIconUrl = connection.logoPublicUrl?.trim() || '';
5856

5957
return (
6058
<ProfileSection.ActionMenuItem
@@ -75,15 +73,14 @@ const EnterpriseConnectMenuButton = (props: { connection: EnterpriseConnectionRe
7573
})}
7674
leftIcon={
7775
<ProviderIcon
78-
// TODO - Use `provider` and `logo_public_url` once FAPI `EnterpriseConnection` resource gets updated
79-
id={GENERIC_ENTERPRISE_PROVIDER_ICON_ID}
76+
id={providerIconId}
8077
iconUrl={providerIconUrl || undefined}
8178
name={connection.name}
8279
isLoading={card.loadingMetadata === loadingKey}
8380
isDisabled={card.isLoading}
8481
alt={`Connect ${connection.name} account`}
8582
elementDescriptor={descriptors.providerIcon}
86-
elementId={descriptors.providerIcon.setId(GENERIC_ENTERPRISE_PROVIDER_ICON_ID)}
83+
elementId={descriptors.providerIcon.setId(providerIconId)}
8784
/>
8885
}
8986
/>

0 commit comments

Comments
 (0)