Overview
ThePeople component is an async server component that fetches and displays a list of contact persons. It provides a scrollable list of person cards with dialog-based editing and creation functionality.
Component Signature
This is a React Server Component (RSC) that performs server-side data fetching.
Data Fetching
The component fetches people data from the backend API:Uses Basic Authentication with environment variables. Returns 404 via
notFound() if the fetch fails.TypeScript Interface
People
Unique identifier for the person
Person’s full name
Person’s phone number (format: 8801XXXXXXXXX)
Sub-Components
Person (Internal)
A client-interactive function component that renders individual person cards.Props
The person object to display
Features
- Displays person’s name as card header
- Shows phone number in card content
- Wrapped in Dialog for editing on click
- Opens
PersonUpdateform in dialog - Hover effect with background change
UI Structure
Usage Example
In a Next.js Page
app/page.tsx
With Messages Component
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 People component integrates with two form components:PersonCreate
- Name input field
- Phone input field (validated as 8801XXXXXXXXX)
- Submit button with pending state
- Toast notifications for success/error
PersonUpdate
Styling & Layout
- Responsive Margin:
mt-6on mobile,mt-0on medium+ screens - Scrollable: Max height of
calc(100vh-180px) - Card Style: Dashed border with drop shadow
- Hover Effect: Background changes on hover (
hover:bg-ring-offset) - Full Width Button: “Add Person” button spans full container width
Icons
Uses Lucide React icons:Error Handling
Component Hierarchy
API Integration
The People component expects the backend API to return an array of person objects:Related Components
- CreatePersonForm - Form for adding new contacts
- UpdatePerson - Form for editing contacts
- Messages - Component for managing messages