-
Notifications
You must be signed in to change notification settings - Fork 460
feat(ui): add OrganizationProfileDomainsSection mosaic component #9078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/swingset/src/stories/organization-profile-domains-section.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as OrganizationProfileDomainsSectionStories from './organization-profile-domains-section.stories'; | ||
|
|
||
| # Organization Profile Domains Section | ||
|
|
||
| Manages an organization's domains — lists them, adds and verifies new ones, edits a verified | ||
| domain's enrollment mode, and removes them. It owns each flow's state (three machines) and wires | ||
| the list, the add/verify wizard, the enrollment editor, and the remove confirmation together. | ||
|
|
||
| <Story | ||
| name='Default' | ||
| storyModule={OrganizationProfileDomainsSectionStories} | ||
| composition={[ | ||
| { name: 'Button', href: '/components/button', layer: 'Components' }, | ||
| { name: 'Dialog', href: '/components/dialog', layer: 'Components' }, | ||
| { name: 'Input', href: '/components/input', layer: 'Components' }, | ||
| { name: 'Text', href: '/components/text', layer: 'Components' }, | ||
| ]} | ||
| /> |
113 changes: 113 additions & 0 deletions
113
packages/swingset/src/stories/organization-profile-domains-section.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /** @jsxImportSource @emotion/react */ | ||
| import type { OrganizationDomainResource } from '@clerk/shared/types'; | ||
| import { useMachine } from '@clerk/ui/mosaic/machine/useMachine'; | ||
| import type { OrganizationProfileEnrollmentOption } from '@clerk/ui/mosaic/organization/organization-profile-domains-section.controller'; | ||
| import { OrganizationProfileDomainsSectionView } from '@clerk/ui/mosaic/organization/organization-profile-domains-section.view'; | ||
| import { organizationProfileDomainsSectionAddVerifyMachine } from '@clerk/ui/mosaic/organization/organization-profile-domains-section-add-verify.machine'; | ||
| import { organizationProfileDomainsSectionEnrollmentMachine } from '@clerk/ui/mosaic/organization/organization-profile-domains-section-enrollment.machine'; | ||
| import { organizationProfileDomainsSectionRemoveMachine } from '@clerk/ui/mosaic/organization/organization-profile-domains-section-remove.machine'; | ||
|
|
||
| import type { StoryMeta } from '@/lib/types'; | ||
|
|
||
| export const meta: StoryMeta = { | ||
| group: 'Organization', | ||
| title: 'OrganizationProfileDomainsSection', | ||
| source: 'packages/ui/src/mosaic/organization/organization-profile-domains-section.tsx', | ||
| }; | ||
|
|
||
| // Demo async deps: resolve after a short delay so the loading/saving states are visible. | ||
| const delay = () => new Promise<void>(resolve => setTimeout(resolve, 600)); | ||
|
|
||
| const ENROLLMENT_OPTIONS: OrganizationProfileEnrollmentOption[] = [ | ||
| { | ||
| value: 'manual_invitation', | ||
| label: 'No automatic enrollment', | ||
| description: 'Users can only be invited manually to the organization.', | ||
| }, | ||
| { | ||
| value: 'automatic_invitation', | ||
| label: 'Automatic invitations', | ||
| description: 'Users are automatically invited to join the organization when they sign up and can join anytime.', | ||
| }, | ||
| { | ||
| value: 'automatic_suggestion', | ||
| label: 'Automatic suggestions', | ||
| description: 'Users receive a suggestion to request to join, but must be approved by an admin.', | ||
| }, | ||
| ]; | ||
|
|
||
| // The view reads only id/name/verification/enrollmentMode/pending counts, so a partial fixture | ||
| // is enough. The cast is confined to these swingset demo fixtures. | ||
| const demoDomains = [ | ||
| { | ||
| id: 'dmn_1', | ||
| name: 'acme.com', | ||
| enrollmentMode: 'automatic_invitation', | ||
| verification: { status: 'verified' }, | ||
| totalPendingInvitations: 3, | ||
| totalPendingSuggestions: 1, | ||
| }, | ||
| { | ||
| id: 'dmn_2', | ||
| name: 'acme.dev', | ||
| enrollmentMode: 'manual_invitation', | ||
| verification: { status: 'unverified' }, | ||
| totalPendingInvitations: 0, | ||
| totalPendingSuggestions: 0, | ||
| }, | ||
| ] as unknown as OrganizationDomainResource[]; | ||
|
|
||
| export function Default() { | ||
| const [addVerifySnapshot, sendAddVerify] = useMachine(organizationProfileDomainsSectionAddVerifyMachine, { | ||
| context: { | ||
| createDomain: async (name: string) => { | ||
| await delay(); | ||
| return { id: 'dmn_new', name, verified: false }; | ||
| }, | ||
| prepareVerification: async () => { | ||
| await delay(); | ||
| }, | ||
| attemptVerification: async () => { | ||
| await delay(); | ||
| return { verified: true }; | ||
| }, | ||
| updateEnrollmentMode: async () => { | ||
| await delay(); | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const [enrollmentSnapshot, sendEnrollment, enrollmentActor] = useMachine( | ||
| organizationProfileDomainsSectionEnrollmentMachine, | ||
| { | ||
| context: { | ||
| updateEnrollmentMode: async () => { | ||
| await delay(); | ||
| }, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| const [removeSnapshot, sendRemove] = useMachine(organizationProfileDomainsSectionRemoveMachine, { | ||
| context: { | ||
| deleteDomain: async () => { | ||
| await delay(); | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| return ( | ||
| <OrganizationProfileDomainsSectionView | ||
| canManage | ||
| list={{ data: demoDomains, isLoading: false, hasNextPage: false, fetchNext: () => {} }} | ||
| enrollmentOptions={ENROLLMENT_OPTIONS} | ||
| addVerify={{ snapshot: addVerifySnapshot, send: sendAddVerify }} | ||
| enrollment={{ | ||
| snapshot: enrollmentSnapshot, | ||
| send: sendEnrollment, | ||
| canSubmit: enrollmentActor.can({ type: 'SUBMIT' }), | ||
| }} | ||
| remove={{ snapshot: removeSnapshot, send: sendRemove }} | ||
| /> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
...ic/organization/__tests__/organization-profile-domains-section-add-verify.machine.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { createActor } from '../../machine/createActor'; | ||
| import { tick } from '../../machines/__tests__/test-utils'; | ||
| import type { OrganizationProfileDomainsSectionAddVerifyContext } from '../organization-profile-domains-section-add-verify.machine'; | ||
| import { organizationProfileDomainsSectionAddVerifyMachine } from '../organization-profile-domains-section-add-verify.machine'; | ||
|
|
||
| function start(overrides: Partial<OrganizationProfileDomainsSectionAddVerifyContext> = {}) { | ||
| const createDomain = vi.fn(() => Promise.resolve({ id: 'dmn_1', name: 'clerk.com', verified: false })); | ||
| const prepareVerification = vi.fn(() => Promise.resolve()); | ||
| const attemptVerification = vi.fn(() => Promise.resolve({ verified: true })); | ||
| const updateEnrollmentMode = vi.fn(() => Promise.resolve()); | ||
| const actor = createActor(organizationProfileDomainsSectionAddVerifyMachine, { | ||
| context: { createDomain, prepareVerification, attemptVerification, updateEnrollmentMode, ...overrides }, | ||
| }); | ||
| actor.start(); | ||
| return { actor, createDomain, prepareVerification, attemptVerification, updateEnrollmentMode }; | ||
| } | ||
|
|
||
| describe('organizationProfileDomainsSectionAddVerifyMachine', () => { | ||
| it('OPEN_ADD starts at the name step', () => { | ||
| const { actor } = start(); | ||
| actor.send({ type: 'OPEN_ADD' }); | ||
| expect(actor.getSnapshot().value).toBe('enteringName'); | ||
| }); | ||
|
|
||
| it('guards the name step until a name is entered', () => { | ||
| const { actor } = start(); | ||
| actor.send({ type: 'OPEN_ADD' }); | ||
| expect(actor.can({ type: 'SUBMIT_NAME' })).toBe(false); | ||
| actor.send({ type: 'TYPE_NAME', value: 'clerk.com' }); | ||
| expect(actor.can({ type: 'SUBMIT_NAME' })).toBe(true); | ||
| }); | ||
|
|
||
| it('creates the domain, then moves to the email step when not yet verified', async () => { | ||
| const { actor, createDomain } = start(); | ||
| actor.send({ type: 'OPEN_ADD' }); | ||
| actor.send({ type: 'TYPE_NAME', value: 'clerk.com' }); | ||
| actor.send({ type: 'SUBMIT_NAME' }); | ||
|
|
||
| expect(actor.getSnapshot().value).toBe('creating'); | ||
| expect(createDomain).toHaveBeenCalledWith('clerk.com'); | ||
|
|
||
| await tick(); | ||
|
|
||
| expect(actor.getSnapshot().value).toBe('enteringEmail'); | ||
| expect(actor.getSnapshot().context.domainId).toBe('dmn_1'); | ||
| expect(actor.getSnapshot().context.domainName).toBe('clerk.com'); | ||
| }); | ||
|
|
||
| it('skips straight to enrollment when the created domain is already verified', async () => { | ||
| const createDomain = vi.fn(() => Promise.resolve({ id: 'dmn_1', name: 'clerk.com', verified: true })); | ||
| const { actor } = start({ createDomain }); | ||
| actor.send({ type: 'OPEN_ADD' }); | ||
| actor.send({ type: 'TYPE_NAME', value: 'clerk.com' }); | ||
| actor.send({ type: 'SUBMIT_NAME' }); | ||
|
|
||
| await tick(); | ||
|
|
||
| expect(actor.getSnapshot().value).toBe('selectingEnrollment'); | ||
| }); | ||
|
|
||
| it('OPEN_VERIFY enters at the email step for an existing domain', () => { | ||
| const { actor } = start(); | ||
| actor.send({ type: 'OPEN_VERIFY', domain: { id: 'dmn_9', name: 'clerk.dev' } }); | ||
| expect(actor.getSnapshot().value).toBe('enteringEmail'); | ||
| expect(actor.getSnapshot().context.domainId).toBe('dmn_9'); | ||
| expect(actor.getSnapshot().context.domainName).toBe('clerk.dev'); | ||
| }); | ||
|
|
||
| it('prepares verification with the affiliation email built from the local part and domain', async () => { | ||
| const { actor, prepareVerification } = start(); | ||
| actor.send({ type: 'OPEN_VERIFY', domain: { id: 'dmn_9', name: 'clerk.dev' } }); | ||
| actor.send({ type: 'TYPE_EMAIL', value: 'alex' }); | ||
| actor.send({ type: 'SUBMIT_EMAIL' }); | ||
|
|
||
| expect(actor.getSnapshot().value).toBe('preparing'); | ||
| expect(prepareVerification).toHaveBeenCalledWith({ domainId: 'dmn_9', affiliationEmailAddress: 'alex@clerk.dev' }); | ||
|
|
||
| await tick(); | ||
|
|
||
| expect(actor.getSnapshot().value).toBe('enteringCode'); | ||
| }); | ||
|
|
||
| it('attempts verification and moves to enrollment on success', async () => { | ||
| const { actor, attemptVerification } = start(); | ||
| actor.send({ type: 'OPEN_VERIFY', domain: { id: 'dmn_9', name: 'clerk.dev' } }); | ||
| actor.send({ type: 'TYPE_EMAIL', value: 'alex' }); | ||
| actor.send({ type: 'SUBMIT_EMAIL' }); | ||
| await tick(); | ||
| actor.send({ type: 'TYPE_CODE', value: '424242' }); | ||
| actor.send({ type: 'SUBMIT_CODE' }); | ||
|
|
||
| expect(actor.getSnapshot().value).toBe('attempting'); | ||
| expect(attemptVerification).toHaveBeenCalledWith({ domainId: 'dmn_9', code: '424242' }); | ||
|
|
||
| await tick(); | ||
|
|
||
| expect(actor.getSnapshot().value).toBe('selectingEnrollment'); | ||
| }); | ||
|
|
||
| it('surfaces an error and stays on the code step when the attempt does not verify', async () => { | ||
| const attemptVerification = vi.fn(() => Promise.resolve({ verified: false })); | ||
| const { actor } = start({ attemptVerification }); | ||
| actor.send({ type: 'OPEN_VERIFY', domain: { id: 'dmn_9', name: 'clerk.dev' } }); | ||
| actor.send({ type: 'TYPE_EMAIL', value: 'alex' }); | ||
| actor.send({ type: 'SUBMIT_EMAIL' }); | ||
| await tick(); | ||
| actor.send({ type: 'TYPE_CODE', value: '424242' }); | ||
| actor.send({ type: 'SUBMIT_CODE' }); | ||
| await tick(); | ||
|
|
||
| expect(actor.getSnapshot().value).toBe('enteringCode'); | ||
| expect(actor.getSnapshot().context.error).not.toBeNull(); | ||
| }); | ||
|
|
||
| it('resends by re-preparing verification from the code step', async () => { | ||
| const { actor, prepareVerification } = start(); | ||
| actor.send({ type: 'OPEN_VERIFY', domain: { id: 'dmn_9', name: 'clerk.dev' } }); | ||
| actor.send({ type: 'TYPE_EMAIL', value: 'alex' }); | ||
| actor.send({ type: 'SUBMIT_EMAIL' }); | ||
| await tick(); | ||
| expect(actor.getSnapshot().value).toBe('enteringCode'); | ||
|
|
||
| actor.send({ type: 'RESEND' }); | ||
| expect(actor.getSnapshot().value).toBe('preparing'); | ||
| await tick(); | ||
| expect(actor.getSnapshot().value).toBe('enteringCode'); | ||
| expect(prepareVerification).toHaveBeenCalledTimes(2); | ||
| }); | ||
|
|
||
| it('goes back to the email step from the code step', async () => { | ||
| const { actor } = start(); | ||
| actor.send({ type: 'OPEN_VERIFY', domain: { id: 'dmn_9', name: 'clerk.dev' } }); | ||
| actor.send({ type: 'TYPE_EMAIL', value: 'alex' }); | ||
| actor.send({ type: 'SUBMIT_EMAIL' }); | ||
| await tick(); | ||
|
|
||
| actor.send({ type: 'BACK' }); | ||
| expect(actor.getSnapshot().value).toBe('enteringEmail'); | ||
| }); | ||
|
|
||
| it('saves the selected enrollment mode and closes', async () => { | ||
| const { actor, updateEnrollmentMode } = start(); | ||
| actor.send({ type: 'OPEN_VERIFY', domain: { id: 'dmn_9', name: 'clerk.dev' } }); | ||
| actor.send({ type: 'TYPE_EMAIL', value: 'alex' }); | ||
| actor.send({ type: 'SUBMIT_EMAIL' }); | ||
| await tick(); | ||
| actor.send({ type: 'TYPE_CODE', value: '424242' }); | ||
| actor.send({ type: 'SUBMIT_CODE' }); | ||
| await tick(); | ||
|
|
||
| expect(actor.getSnapshot().value).toBe('selectingEnrollment'); | ||
| expect(actor.can({ type: 'SUBMIT_ENROLLMENT' })).toBe(false); | ||
|
|
||
| actor.send({ type: 'SELECT_MODE', value: 'automatic_invitation' }); | ||
| actor.send({ type: 'SUBMIT_ENROLLMENT' }); | ||
|
|
||
| expect(actor.getSnapshot().value).toBe('savingEnrollment'); | ||
| expect(updateEnrollmentMode).toHaveBeenCalledWith({ | ||
| domainId: 'dmn_9', | ||
| enrollmentMode: 'automatic_invitation', | ||
| deletePending: false, | ||
| }); | ||
|
|
||
| await tick(); | ||
| expect(actor.getSnapshot().value).toBe('closed'); | ||
| }); | ||
|
|
||
| it('surfaces an error and stays on the name step when create fails', async () => { | ||
| const createDomain = vi.fn(() => Promise.reject(new Error('taken'))); | ||
| const { actor } = start({ createDomain }); | ||
| actor.send({ type: 'OPEN_ADD' }); | ||
| actor.send({ type: 'TYPE_NAME', value: 'clerk.com' }); | ||
| actor.send({ type: 'SUBMIT_NAME' }); | ||
| await tick(); | ||
|
|
||
| expect(actor.getSnapshot().value).toBe('enteringName'); | ||
| expect(actor.getSnapshot().context.error).toBe('taken'); | ||
| }); | ||
|
|
||
| it('cancels back to closed', () => { | ||
| const { actor } = start(); | ||
| actor.send({ type: 'OPEN_ADD' }); | ||
| actor.send({ type: 'CANCEL' }); | ||
| expect(actor.getSnapshot().value).toBe('closed'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.