Skip to content

Commit d55f699

Browse files
refactor(ui): wire mosaic organization sections to real Clerk hooks (#9017)
1 parent 533f0b1 commit d55f699

15 files changed

Lines changed: 349 additions & 151 deletions

.changeset/wise-mosaic-sections.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/swingset/src/stories/delete-organization.stories.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** @jsxImportSource @emotion/react */
2-
import { DeleteOrganization } from '@clerk/ui/mosaic/sections/delete-organization';
2+
import { useMachine } from '@clerk/ui/mosaic/machine/useMachine';
3+
import { deleteOrgMachine } from '@clerk/ui/mosaic/sections/delete-organization-machine';
4+
import { DeleteOrganizationView } from '@clerk/ui/mosaic/sections/delete-organization-view';
35

46
import type { StoryMeta } from '@/lib/types';
57

@@ -11,5 +13,18 @@ export const meta: StoryMeta = {
1113
};
1214

1315
export function Default() {
14-
return <DeleteOrganization />;
16+
const [snapshot, send, actor] = useMachine(deleteOrgMachine, {
17+
context: {
18+
organizationName: 'Acme Inc',
19+
destroyOrganization: () => new Promise<void>(resolve => setTimeout(resolve, 800)),
20+
},
21+
});
22+
23+
return (
24+
<DeleteOrganizationView
25+
snapshot={snapshot}
26+
send={send}
27+
canSubmit={actor.can({ type: 'CONFIRM' })}
28+
/>
29+
);
1530
}

packages/swingset/src/stories/leave-organization.stories.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** @jsxImportSource @emotion/react */
2-
import { LeaveOrganization } from '@clerk/ui/mosaic/sections/leave-organization';
2+
import { useMachine } from '@clerk/ui/mosaic/machine/useMachine';
3+
import { leaveOrgMachine } from '@clerk/ui/mosaic/sections/leave-organization-machine';
4+
import { LeaveOrganizationView } from '@clerk/ui/mosaic/sections/leave-organization-view';
35

46
import type { StoryMeta } from '@/lib/types';
57

@@ -11,5 +13,18 @@ export const meta: StoryMeta = {
1113
};
1214

1315
export function Default() {
14-
return <LeaveOrganization />;
16+
const [snapshot, send, actor] = useMachine(leaveOrgMachine, {
17+
context: {
18+
organizationName: 'Acme Inc',
19+
leaveOrganization: () => new Promise<void>(resolve => setTimeout(resolve, 800)),
20+
},
21+
});
22+
23+
return (
24+
<LeaveOrganizationView
25+
snapshot={snapshot}
26+
send={send}
27+
canSubmit={actor.can({ type: 'CONFIRM' })}
28+
/>
29+
);
1530
}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/** @jsxImportSource @emotion/react */
2-
import { OrganizationProfileGeneral } from '@clerk/ui/mosaic/panels/organization-profile-general';
2+
import { OrganizationProfileGeneralView } from '@clerk/ui/mosaic/panels/organization-profile-general-view';
33

44
import type { StoryMeta } from '@/lib/types';
55

6+
import { Default as DeleteOrganizationDemo } from './delete-organization.stories';
7+
import { Default as LeaveOrganizationDemo } from './leave-organization.stories';
8+
69
export const meta: StoryMeta = {
710
group: 'Panels',
811
title: 'OrganizationProfileGeneral',
@@ -11,5 +14,10 @@ export const meta: StoryMeta = {
1114
};
1215

1316
export function Default() {
14-
return <OrganizationProfileGeneral />;
17+
return (
18+
<OrganizationProfileGeneralView
19+
leaveOrganization={<LeaveOrganizationDemo />}
20+
deleteOrganization={<DeleteOrganizationDemo />}
21+
/>
22+
);
1523
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/** @jsxImportSource @emotion/react */
2-
import { OrganizationProfile } from '@clerk/ui/mosaic/aio/organization-profile';
2+
import { OrganizationProfileView } from '@clerk/ui/mosaic/aio/organization-profile-view';
33

44
import type { StoryMeta } from '@/lib/types';
55

6+
import { Default as OrganizationProfileGeneralDemo } from './organization-profile-general.stories';
7+
68
export const meta: StoryMeta = {
79
group: 'AIO',
810
title: 'OrganizationProfile',
@@ -11,5 +13,5 @@ export const meta: StoryMeta = {
1113
};
1214

1315
export function Default() {
14-
return <OrganizationProfile />;
16+
return <OrganizationProfileView general={<OrganizationProfileGeneralDemo />} />;
1517
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import type { ReactNode } from 'react';
2+
3+
import { Box } from '../components/box';
4+
import { Tabs } from '../components/tabs';
5+
6+
interface OrganizationProfileViewProps {
7+
/** The General tab's panel content. */
8+
general: ReactNode;
9+
}
10+
11+
export function OrganizationProfileView({ general }: OrganizationProfileViewProps) {
12+
return (
13+
<Box
14+
sx={{
15+
width: '100%',
16+
}}
17+
>
18+
<Box
19+
render={p => <h1 {...p} />}
20+
sx={t => ({
21+
...t.text('lg'),
22+
fontWeight: t.font.semibold,
23+
marginBlockEnd: t.spacing(8),
24+
})}
25+
>
26+
Organization Profile
27+
</Box>
28+
<Tabs.Root defaultValue='general'>
29+
<Tabs.List>
30+
<Tabs.Tab value='general'>General</Tabs.Tab>
31+
<Tabs.Tab value='members'>Members</Tabs.Tab>
32+
</Tabs.List>
33+
<Tabs.Panel value='general'>{general}</Tabs.Panel>
34+
<Tabs.Panel value='members'>
35+
<Box
36+
render={p => <h1 {...p} />}
37+
sx={t => ({
38+
...t.text('base'),
39+
fontWeight: t.font.medium,
40+
textAlign: 'center',
41+
})}
42+
>
43+
Members content
44+
</Box>
45+
</Tabs.Panel>
46+
</Tabs.Root>
47+
</Box>
48+
);
49+
}
Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,6 @@
1-
import { Box } from '../components/box';
2-
import { Tabs } from '../components/tabs';
31
import { OrganizationProfileGeneral } from '../panels/organization-profile-general';
2+
import { OrganizationProfileView } from './organization-profile-view';
43

54
export function OrganizationProfile() {
6-
return (
7-
<Box
8-
sx={t => ({
9-
width: '100%',
10-
})}
11-
>
12-
<Box
13-
render={p => <h1 {...p} />}
14-
sx={t => ({
15-
...t.text('lg'),
16-
fontWeight: t.font.semibold,
17-
marginBlockEnd: t.spacing(8),
18-
})}
19-
>
20-
Organization Profile
21-
</Box>
22-
<Tabs.Root defaultValue='general'>
23-
<Tabs.List>
24-
<Tabs.Tab value='general'>General</Tabs.Tab>
25-
<Tabs.Tab value='members'>Members</Tabs.Tab>
26-
</Tabs.List>
27-
<Tabs.Panel value='general'>
28-
<OrganizationProfileGeneral />
29-
</Tabs.Panel>
30-
<Tabs.Panel value='members'>
31-
<Box
32-
render={p => <h1 {...p} />}
33-
sx={t => ({
34-
...t.text('base'),
35-
fontWeight: t.font.medium,
36-
textAlign: 'center',
37-
})}
38-
>
39-
Members content
40-
</Box>
41-
</Tabs.Panel>
42-
</Tabs.Root>
43-
</Box>
44-
);
5+
return <OrganizationProfileView general={<OrganizationProfileGeneral />} />;
456
}

packages/ui/src/mosaic/mock/organization-store.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/ui/src/mosaic/mock/use-organization.tsx

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { ReactNode } from 'react';
2+
3+
import { Box } from '../components/box';
4+
import { alpha } from '../utils';
5+
6+
interface OrganizationProfileGeneralViewProps {
7+
/** The leave-organization section, rendered above the divider. */
8+
leaveOrganization: ReactNode;
9+
/** The delete-organization section, rendered below the divider. */
10+
deleteOrganization: ReactNode;
11+
}
12+
13+
export function OrganizationProfileGeneralView({
14+
leaveOrganization,
15+
deleteOrganization,
16+
}: OrganizationProfileGeneralViewProps) {
17+
return (
18+
<Box
19+
sx={{
20+
width: '100%',
21+
containerType: 'inline-size',
22+
}}
23+
>
24+
{leaveOrganization}
25+
<Box
26+
sx={t => ({
27+
height: '1px',
28+
background: `light-dark(${alpha('#000', 10)},${alpha('#fff', 10)})`,
29+
marginBlock: t.spacing(4),
30+
})}
31+
/>
32+
{deleteOrganization}
33+
</Box>
34+
);
35+
}

0 commit comments

Comments
 (0)