Overview
TheKanban component is the core order management interface that provides a visual, interactive kanban board for tracking orders through their lifecycle. It implements drag-and-drop functionality using @dnd-kit/core, allowing users to move orders between status columns and automatically update their state.
Key Features
Drag & Drop
Intuitive drag-and-drop interface for moving orders between statuses
Real-time Updates
Automatically updates order status when dropped in valid columns
Rider View
Special rendering for picked-up orders showing rider information
Order Details
Click any order card to open a detailed modal view
Architecture
State Management
The Kanban component integrates with the Orders context to manage order data:- ordersByStatus: Object mapping each order status to an array of orders
- updateOrderStatus: Function to transition orders between statuses
Drag-and-Drop Flow
Drag Start
When a user starts dragging an order card, the
onDragStart handler stores the active order in state for rendering in the drag overlayDrop Validation
On drop, the component validates:
- The target column represents a valid status
- The transition is allowed by business rules (
canTransition) - The transition is permitted from the UI (
canTransitionFromUi)
Component Structure
Key State Variables
The order currently being dragged. Used to render the drag overlay.
ID of the order selected for detailed view. Opens the OrderDetailModal when set.
Computed Data
Riders List
The component dynamically computes a list of active riders from picked-up orders:The riders list is memoized for performance. It filters all orders with
PICKED_UP status and a courier name, transforming them into rider view models.Orders Map
AMap is maintained for efficient order lookup during drag operations:
Column Rendering
The kanban board renders columns based on theORDER_COLUMNS configuration:
The
PICKED_UP column receives special treatment, rendering DraggableRiderCard components instead of regular order cards.Drag Validation
The component implements a two-layer validation system:- Domain Rules
- UI Policy
Event Handlers
onDragStart
onDragEnd
Drag Overlay
Provides visual feedback during dragging:The overlay renders either a Riders component or an OrderCard depending on the order’s status, maintaining visual consistency.
Integration Points
Context Dependencies
- OrdersContext: Provides order data and status update functionality
- ThemeContext: (Implicit) Styling adapts to the current theme
Child Components
- Column: Container for orders in each status
- DraggableOrderCard: Draggable wrapper for OrderCard
- DraggableRiderCard: Draggable wrapper for Riders
- OrderDetailModal: Modal for viewing order details
Usage Example
Performance Optimizations
- Memoized Computations: Riders list and orders map are memoized to avoid unnecessary recalculations
- Pointer Sensor Constraint: 6px activation distance prevents accidental drags
- Efficient Lookups: Orders Map enables O(1) lookup during drag operations
Related Components
- OrderCard: Individual order card display
- Riders: Rider card for picked-up orders
- Column: Status column container (internal component)
Source Location
components/Kanban/Kanban.tsx:1