Overview
TheShareModal component provides a user interface for sharing documents with other users. It allows editors to invite collaborators via email, set their access level, and manage existing collaborators. Built with Shadcn Dialog component and integrated with Liveblocks.
Props
The Liveblocks room identifier for the document being shared.
Array of users who currently have access to the document. Each user contains:
id(string): Unique user identifiername(string): User’s display nameemail(string): User’s email addressavatar(string): Avatar image URLcolor(string): Assigned color for UIuserType(UserType): Optional access level
User ID of the document creator. Used to determine if collaborators can be removed.
Access level of the current user. Only ‘editor’ and ‘creator’ types can open and use the share modal.
Features
- Email Invitation: Invite users by email address
- Access Control: Set invitee as ‘viewer’ or ‘editor’
- Collaborator List: View all current collaborators
- Permission Management: Update or remove collaborator access
- Real-time Updates: Uses Liveblocks for instant synchronization
- Disabled State: Button disabled for viewers
Usage Example
Basic Usage
In CollaborativeRoom Context
TypeScript Interface
Component Behavior
Share Button
- Displays share icon with “Share” text on desktop
- Icon-only on mobile (sm breakpoint)
- Disabled when
currentUserTypeis ‘viewer’ - Blue gradient styling
Invitation Flow
- User enters email address
- Selects access level (viewer/editor) via UserTypeSelector
- Clicks “Invite” button
updateDocumentAccessaction called- Modal shows loading state during update
- Collaborator list updates automatically
State Management
Modal Structure
Sharing Actions
The share handler uses Liveblocks user info:Access Permissions
| User Type | Can Open Modal | Can Invite | Can Remove |
|---|---|---|---|
| Creator | ✓ | ✓ | ✓ |
| Editor | ✓ | ✓ | Limited* |
| Viewer | ✗ | ✗ | ✗ |
User Type Selector
TheUserTypeSelector component allows choosing between:
- Viewer: Read-only access, can view and comment
- Editor: Full editing access, can modify content and invite others
Collaborator Component
Each collaborator is rendered using theCollaborator component:
- Avatar and name
- Email address
- Current access level
- Remove button (if permitted)
Styling
Key CSS classes:.gradient-blue: Share button styling.shad-dialog: Modal container.share-input: Email input field.min-w-4,.md:size-5: Responsive icon sizing
Dependencies
- @liveblocks/react:
useSelf()hook for current user - Shadcn UI: Dialog, Button, Input, Label components
- UserTypeSelector: Access level picker
- Collaborator: Individual collaborator list item
Related Components
- CollaborativeRoom - Parent component
- UserTypeSelector - Access level selector
- Collaborator - List item for each collaborator
- Header - Often contains ShareModal