Workspace members, their roles and pending invitations.
Pending invitations
2
- [email protected]Sent Nov 28 by BenMember
- [email protected]Link expiredGuest
234 members
- ALAna Lopez[email protected]Owner
- BOBen Okafor (you)[email protected]Admin
- MPMira Patel[email protected]
- TLTomás Lopez[email protected]
- YLYuki Lopez[email protected]
- PLPriya Lopez[email protected]
- OLOwen Lopez[email protected]
- LLLeila Lopez[email protected]
- JLJonas Lopez[email protected]
- ALAmara Lopez[email protected]
- DLDiego Lopez[email protected]
- HLHana Lopez[email protected]
- FLFelix Lopez[email protected]
- SLSana Lopez[email protected]
- NLNoor Lopez[email protected]
- RLRavi Lopez[email protected]
- AOAna Okafor[email protected]
- BOBen Okafor[email protected]
- MOMira Okafor[email protected]
- TOTomás Okafor[email protected]
- YOYuki Okafor[email protected]
- POPriya Okafor[email protected]
- OOOwen Okafor[email protected]
- LOLeila Okafor[email protected]
- JOJonas Okafor[email protected]
- AOAmara Okafor[email protected]
- DODiego Okafor[email protected]
- HOHana Okafor[email protected]
- FOFelix Okafor[email protected]
- SOSana Okafor[email protected]
- NONoor Okafor[email protected]
- RORavi Okafor[email protected]
- APAna Patel[email protected]
- BPBen Patel[email protected]
- MPMira Patel[email protected]
- TPTomás Patel[email protected]
- YPYuki Patel[email protected]
- PPPriya Patel[email protected]DeactivatedMember
- OPOwen Patel[email protected]
- LPLeila Patel[email protected]
- JPJonas Patel[email protected]
- APAmara Patel[email protected]
- DPDiego Patel[email protected]
- HPHana Patel[email protected]
- FPFelix Patel[email protected]
- SPSana Patel[email protected]
- NPNoor Patel[email protected]
- RPRavi Patel[email protected]
- ANAna Novak[email protected]
- BNBen Novak[email protected]
import { Command, UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import { Effect, Redacted, Schema } from "effect"import { Outcome, pending } from "./ui/uicontext/components/domain/Outcome.ts"import { Member, Members, PendingInvitation } from "./ui/uicontext/components/kit/Members.ts"import { people, roles } from "./workspace.ts"// Northwind Freight's 240 people, seen by Ben, an admin. Every change waits on a pretend server// for half a second: a role change, a removal, an invitation, a resend or a revoke. Admins can't// make owners, so the owner's row is read-only, and removing the only owner isn't offered.const start = people(240)const Change = Schema.Union([ Schema.TaggedStruct("Role", { person: Schema.String, role: Schema.String }), Schema.TaggedStruct("Remove", { person: Schema.String }), Schema.TaggedStruct("Invite", { email: Schema.String, role: Schema.String }), Schema.TaggedStruct("Resend", { invitation: Schema.String }), Schema.TaggedStruct("Revoke", { invitation: Schema.String }),])const Message = UiSchema.TaggedEnum({ RequestedMembersChange: { request: Schema.String, change: Change }, CompletedServer: { request: Schema.String, change: Change },})// Stands in for the server: waits, then answers.const AskServer = Command.make("AskServer", { args: { request: Schema.String, change: Change } }, ({ request, change }) => Effect.sleep("500 millis").pipe(Effect.as(Message.CompletedServer({ request, change }))),)const inviteCode = (n: number) => `https://northwind.example/join/${(n * 7919).toString(36)}k${(n * 104729).toString(36)}`export const MembersDemo = Html.component({ name: "MembersDemo", model: Schema.Struct({ people: Schema.Array(Member), invitations: Schema.Array(PendingInvitation), invitation: Schema.NullOr(Schema.Redacted(Schema.String)), outcome: Schema.NullOr(Outcome), made: Schema.Number, }), message: Message,}).make({ init: () => ({ people: start, invitations: [ { id: "inv-1", email: "[email protected]", role: "member", sent: "Sent Nov 28 by Ben" }, { id: "inv-2", email: "[email protected]", role: "guest", expired: true }, ], invitation: null, outcome: null, made: 0, }), update: { RequestedMembersChange: ($, { request, change }) => $.evolve({ outcome: pending(request) }).run(AskServer.make({ request, change })), CompletedServer: ($, { change }) => { switch (change._tag) { case "Role": return $.evolve({ outcome: null, people: (all) => all.map((p) => (p.id === change.person ? { ...p, role: change.role } : p)) }) case "Remove": return $.evolve({ outcome: null, people: (all) => all.filter((p) => p.id !== change.person) }) case "Invite": { const id = `inv-new-${$.model.made}` return $.evolve({ outcome: null, made: (n) => n + 1, invitation: Redacted.make(inviteCode($.model.made + 3)), invitations: (all) => [{ id, role: change.role, sent: "Sent just now by you", ...(change.email === "" ? {} : { email: change.email }) }, ...all], }) } case "Resend": return $.evolve({ outcome: null, invitations: (all) => all.map((i) => (i.id === change.invitation ? { id: i.id, role: i.role, sent: "Sent again just now", ...(i.email === undefined ? {} : { email: i.email }) } : i)), }) case "Revoke": return $.evolve({ outcome: null, invitations: (all) => all.filter((i) => i.id !== change.invitation) }) } }, }, view: (h, model) => Members(h, { props: { agentId: "members-demo", people: model.people, roles, me: "ben", // an admin changes anyone but the owner, and can't remove the owner editable: model.people.filter((p) => p.role !== "owner" && p.id !== "ben").map((p) => p.id), removable: model.people.filter((p) => p.role !== "owner").map((p) => p.id), removeNote: "Their automations and connections go to you.", invitations: model.invitations, invite: { roles: ["member", "admin", "guest"], note: "An invitation link works once, for 7 days." }, invitation: model.invitation, outcome: model.outcome, }, onEmit: { RequestedRole: ({ person, role }) => Message.RequestedMembersChange({ request: person, change: { _tag: "Role", person, role } }), RequestedRemove: ({ person }) => Message.RequestedMembersChange({ request: person, change: { _tag: "Remove", person } }), RequestedInvite: ({ email, role }) => Message.RequestedMembersChange({ request: "invite", change: { _tag: "Invite", email, role } }), RequestedResend: ({ invitation }) => Message.RequestedMembersChange({ request: invitation, change: { _tag: "Resend", invitation } }), RequestedRevoke: ({ invitation }) => Message.RequestedMembersChange({ request: invitation, change: { _tag: "Revoke", invitation } }), }, }),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/membersUsage
import type { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"import { type Member, Members } from "./ui/uicontext/components/kit/Members.ts"const Message = UiSchema.TaggedEnum({ RequestedMemberRole: { person: Schema.String, role: Schema.String }, RequestedRemoveMember: { person: Schema.String }, RequestedInviteMember: { email: Schema.String, role: Schema.String },})export const TeamMembers = (h: Html.H<typeof Message.Type>, people: ReadonlyArray<Member> | null, outcome: Outcome | null) => Members(h, { props: { people, roles: [ { value: "admin", label: "Admin" }, { value: "member", label: "Member" }, ], me: "ana", editable: people?.filter((p) => p.id !== "ana").map((p) => p.id) ?? [], removable: people?.filter((p) => p.id !== "ana").map((p) => p.id) ?? [], invite: { roles: ["member", "admin"] }, outcome, }, onEmit: { RequestedRole: ({ person, role }) => Message.RequestedMemberRole({ person, role }), RequestedRemove: ({ person }) => Message.RequestedRemoveMember({ person }), RequestedInvite: ({ email, role }) => Message.RequestedInviteMember({ email, role }), RequestedResend: () => undefined, RequestedRevoke: () => undefined, }, })Examples
As a member
Without editable, removable or invite, roles read as badges and nothing can change.
6 members
- ALAna Lopez[email protected]Owner
- BOBen Okafor[email protected]Admin
- MPMira Patel (you)[email protected]Member
- TLTomás Lopez[email protected]Member
- YLYuki Lopez[email protected]Member
- PLPriya Lopez[email protected]Member
import type { Html } from "@effect/ui/html"import { Members } from "./ui/uicontext/components/kit/Members.ts"import { people, roles } from "./workspace.ts"// Mira is a member: she sees who's here and their roles, and nothing she can change.export const AsAMember = <M>(h: Html.H<M>) => Members(h, { props: { agentId: "members-read-only", people: people(6), roles, me: "mira" }, onEmit: { RequestedRole: () => undefined, RequestedRemove: () => undefined, RequestedInvite: () => undefined, RequestedResend: () => undefined, RequestedRevoke: () => undefined, }, })A refused change
A refusal shows under the row it is about, in the app's own words.
4 members
- ALAna Lopez (you)[email protected]Owner
- BOBen Okafor[email protected]
Ben is the last admin with billing access. Make someone else an admin first.
- MPMira Patel[email protected]
- TLTomás Lopez[email protected]
import type { Html } from "@effect/ui/html"import { refused } from "./ui/uicontext/components/domain/Outcome.ts"import { Members } from "./ui/uicontext/components/kit/Members.ts"import { people, roles } from "./workspace.ts"// The server refused the last change, and says why.export const Refused = <M>(h: Html.H<M>) => Members(h, { props: { agentId: "members-refused", people: people(4), roles, me: "ana", editable: ["ben", "mira", "p3"], removable: ["ben", "mira", "p3"], outcome: refused("ben", "Ben is the last admin with billing access. Make someone else an admin first."), }, onEmit: { RequestedRole: () => undefined, RequestedRemove: () => undefined, RequestedInvite: () => undefined, RequestedResend: () => undefined, RequestedRevoke: () => undefined, }, })API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
peoplerequired | Member[] | null | — | Null while loading |
rolesrequired | MemberRole[] | — | Every role code people may have, with its label |
me | string | — | The signed-in person's id: "(you)", and never removable from here |
editable | string[] | — | People whose role the viewer may change |
removable | string[] | — | People the viewer may remove |
removeNote | string | — | Said in the remove confirm: "Their automations and connections go to you." |
invitations | PendingInvitation[] | — | Invitations nobody has accepted yet; Resend and Revoke show when invite is given |
invite | { roles, note } | — | The invite form; absent when the viewer can't invite |
invitation | Redacted | null | — | The link the app made for the last invitation, shown once |
outcome | Outcome | null | — | The app's answer to the last request: its id is "invite" for RequestedInvite, the person's id for RequestedRole and RequestedRemove, and the invitation's id for RequestedResend and RequestedRevoke. Pending marks that row busy; a refusal shows its reason. |
agentId | string | members | The id agents know this list by; members by default |
Events
| Event | Payload | Description |
|---|---|---|
RequestedInvite | { email: string; role: string } | Invite someone by email with a role |
RequestedRole | { person: string; role: string } | Change a member's role |
RequestedRemove | { person: string } | Remove a member from the workspace, after the person confirmed |
RequestedResend | { invitation: string } | Send a pending invitation again, with a fresh link |
RequestedRevoke | { invitation: string } | Cancel a pending invitation: its link stops working |
Agent actions
| Action | Description |
|---|---|
UpdatedQuery | Search people by name, email or role; the snapshot lists who matches |
ChangedEmail | Type the email an invitation is for (optional) |
ChoseInviteRole | Choose the role an invitation gives (see inviteRoles) |
SubmittedInviteasks first | Make an invitation link with the chosen email and role. Target: { email, role } |
ChangedRoleasks first | Change a person's role, by id. Target: { person, role } as it is now |
ConfirmedRemoveasks first | Remove a person, by id. Target: { person, name } |
ClickedResend | Send a pending invitation again, by id |
ClickedRevokeasks first | Revoke a pending invitation, by id; its link stops working. Target: { invitation, email } |
Accessibility
- Roles are native selects named for the person they change.
- Removing someone asks first, inline; the invite link is copied with a button that says whether it worked.
- Refusals are announced, and agents must name the person they remove.