Overview
TheMessages component is an async server component that fetches and displays scheduled messages. It includes a scrollable list of message cards, each with dialog-based editing, and a dialog for creating new messages.
Component Signature
This is a React Server Component (RSC) that performs data fetching at render time.
Data Fetching
The component fetches two types of data from the backend:Messages Endpoint
People Endpoint
Both endpoints use Basic Authentication with credentials from environment variables. If either fetch fails, the component calls
notFound() from Next.js navigation.TypeScript Interfaces
Message
Unique identifier for the message
The message content/text body
Phone number to send the message to
Number of days to wait before sending the message
Recipient information object
Name of the message recipient
Timestamp when the message was created
People
Unique identifier for the person
Person’s name
Person’s phone number
Sub-Components
Message (Internal)
A client-interactive function component that renders individual message cards with dialog-based editing.Props
The message object to display
Array of people for the update form dropdown
Features
- Displays truncated message content (first 100 characters)
- Shows recipient name and phone number
- Displays “send after” days
- Wrapped in a Dialog trigger for editing
- Opens
MessageUpdateFormon click
UI Structure
Usage Example
In a Next.js Page
app/page.tsx
Ensure the following environment variables are set:
BACKEND_URL: The backend API base URLUSERNAME: Basic auth usernamePASSWORD: Basic auth password
Integration with Forms
The Messages component integrates with two form components:CreateMessageForm
MessageUpdateForm
Styling & Layout
- Grid Layout: Spans 2 columns on medium+ screens (
md:col-span-2) - Scrollable: Max height of
calc(100vh-180px)with overflow handling - Card Style: Dashed border with drop shadow
- Responsive: Full width on mobile, grid column span on desktop
Error Handling
notFound().
Related Components
- CreateMessageForm - Form for creating new messages
- MessageUpdateForm - Form for editing messages
- People - Component for managing contacts