Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type {
OrganizationCreationDefaultsJSON,
OrganizationCreationDefaultsJSONSnapshot,
OrganizationCreationDefaultsResource,
} from '@clerk/shared/types';

import { BaseResource } from './internal';

export class OrganizationCreationDefaults extends BaseResource implements OrganizationCreationDefaultsResource {
creationAdvisory: {
type: 'existing_org_with_domain';
severity: 'warning';
} | null = null;

public constructor(data: OrganizationCreationDefaultsJSON | OrganizationCreationDefaultsJSONSnapshot | null = null) {
super();
this.fromJSON(data);
}

protected fromJSON(data: OrganizationCreationDefaultsJSON | OrganizationCreationDefaultsJSONSnapshot | null): this {
if (!data) {
return this;
}

if (data.creation_advisory) {
this.creationAdvisory = this.withDefault(data.creation_advisory, this.creationAdvisory ?? null);
}

return this;
}

public __internal_toSnapshot(): OrganizationCreationDefaultsJSONSnapshot {
return {
creation_advisory: this.creationAdvisory
? {
type: this.creationAdvisory.type,
severity: this.creationAdvisory.severity,
}
: null,
} as unknown as OrganizationCreationDefaultsJSONSnapshot;
}
}
3 changes: 2 additions & 1 deletion packages/shared/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type * from './customPages';
export type * from './deletedObject';
export type * from './devtools';
export type * from './displayConfig';
export type * from './elementIds';
export type * from './emailAddress';
export type * from './enterpriseAccount';
export type * from './environment';
Expand All @@ -32,6 +33,7 @@ export type * from './localization';
export type * from './multiDomain';
export type * from './oauth';
export type * from './organization';
export type * from './organizationCreationDefaults';
export type * from './organizationDomain';
export type * from './organizationInvitation';
export type * from './organizationMembership';
Expand All @@ -49,7 +51,6 @@ export type * from './protectConfig';
export type * from './redirects';
export type * from './resource';
export type * from './role';
export type * from './elementIds';
export type * from './router';
/**
* TODO @revamp-hooks: Drop this in the next major release.
Expand Down
20 changes: 20 additions & 0 deletions packages/shared/src/types/organizationCreationDefaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { ClerkResourceJSON } from './json';
import type { ClerkResource } from './resource';

export type OrganizationCreationAdvisoryType = 'existing_org_with_domain';

export type OrganizationCreationAdvisorySeverity = 'warning';

export interface OrganizationCreationDefaultsJSON extends ClerkResourceJSON {
creation_advisory: {
type: OrganizationCreationAdvisoryType;
severity: OrganizationCreationAdvisorySeverity;
} | null;
}

export interface OrganizationCreationDefaultsResource extends ClerkResource {
creationAdvisory: {
type: OrganizationCreationAdvisoryType;
severity: OrganizationCreationAdvisorySeverity;
} | null;
}
3 changes: 3 additions & 0 deletions packages/shared/src/types/snapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {
VerificationJSON,
Web3WalletJSON,
} from './json';
import type { OrganizationCreationDefaultsJSON } from './organizationCreationDefaults';
import type { OrganizationSettingsJSON } from './organizationSettings';
import type { ProtectConfigJSON } from './protectConfig';
import type { SignInJSON } from './signIn';
Expand Down Expand Up @@ -143,6 +144,8 @@ export type OrganizationMembershipJSONSnapshot = OrganizationMembershipJSON;

export type OrganizationSettingsJSONSnapshot = OrganizationSettingsJSON;

export type OrganizationCreationDefaultsJSONSnapshot = OrganizationCreationDefaultsJSON;

export type PasskeyJSONSnapshot = Override<PasskeyJSON, { verification: VerificationJSONSnapshot | null }>;

export type PhoneNumberJSONSnapshot = Override<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,10 @@ describe('TaskChooseOrganization', () => {
expect(queryByLabelText(/Slug/i)).toBeInTheDocument();
});
});

describe('with organization creation defaults', () => {
it.todo('displays warning when organization already exists for user email domain');

it.todo('prefills create organization form with defaults');
});
});