CentercodeDitto
DittoPorygonAPI

User Segments

Manage user segment assignments with permission-aware editing

Overview

The UserSegments component provides a comprehensive interface for managing user segment assignments. It supports both read-only display and interactive editing modes based on permissions.

Features

  • Permission-aware editing with read-only fallback
  • Multi-select segment assignment with taxonomy grouping
  • Visual indicators for segment sources (platform, program, project)
  • Real-time updates with optimistic UI
  • Empty states and loading skeletons

Examples

Editable Mode

When the user has edit permissions, they can add or remove segment assignments.

Selected: seg-healthcare, seg-developer

Read-Only Mode

When the user lacks edit permissions, segments are displayed in read-only mode.

Edit permission required to modify segments

Empty State

When no segments are assigned.

Edit permission required to modify segments

Loading State

Skeleton loading state.

Props Reference

PropTypeDefaultDescription
assignedSegmentIdsstring[]requiredArray of segment IDs currently assigned to the user
userIdstringrequiredThe ID of the user whose segments are being managed
membershipIdstring-The membership ID for scope-specific segment management
availableSegmentsTaxonomySelectorGroup[]requiredGrouped segments available for assignment
permissionsUserSegmentsPermissions-Permission flags controlling edit capabilities
onSegmentsChange(userId: string, segmentIds: string[]) => void-Callback fired when segment assignments change
currentProjectIdstring-Current project ID for context-aware segment display
isLoadingbooleanfalseShows loading skeleton when true
disabledbooleanfalseDisables all interactions when true
classNamestring-Additional CSS classes for the root element

Usage

import { UserSegments } from '@/ui/components';
import type { TaxonomySelectorGroup } from '@/ui/blocks';

// Define available segments grouped by type
const segmentGroups: TaxonomySelectorGroup[] = [
  {
    id: 'industry',
    name: 'Industry',
    source: 'platform',
    items: [
      { id: 'healthcare', name: 'Healthcare' },
      { id: 'finance', name: 'Finance' },
    ],
  },
  {
    id: 'role',
    name: 'Role',
    source: 'program',
    items: [
      { id: 'developer', name: 'Developer' },
      { id: 'designer', name: 'Designer' },
    ],
  },
];

// Usage in UserSheet or user management context
<UserSegments
  assignedSegmentIds={user.segments.map(s => s.segmentId)}
  userId={user.id}
  membershipId={membership.id}
  availableSegments={segmentGroups}
  permissions={{ canEditSegments: canEdit }}
  onSegmentsChange={handleSegmentsChange}
  currentProjectId={projectId}
/>