Overview
TheRescheduler component is a client-side button that triggers a server action to reschedule all messages. It provides user feedback via toast notifications and handles loading states.
Component Signature
This is a Client Component (“use client”) that uses React hooks and Next.js server actions.
Server Action Integration
The component uses thereschedule server action with the useActionState hook:
useActionState Return Values
Function to trigger the reschedule server action
Loading state indicator
Server Action: reschedule
The underlying server action that performs the API call:The action uses
revalidatePath("/") to refresh the page data after successful rescheduling.Toast Notifications
The component uses Sonner toast notifications to provide feedback:Toast Types
Displayed when messages are successfully rescheduled
- Message: “Messages rescheduled successfully”
- Uses rich colors
Displayed when rescheduling fails
- Message: “Messages rescheduling failed”
- Duration: 3500ms
- Uses rich colors
UI Structure
Note: There’s a typo in the button text (“Reschede” instead of “Reschedule”)
Props
This component accepts no props.Usage Example
In a Layout or Header
app/layout.tsx
With Other Components
app/page.tsx
Button States
Button is disabled when
rescheduleIsPending is trueUses the default button variant
Form submit button
Icons
Uses Lucide React Calendar icon:Environment Variables
Required in the server action:Backend API base URL for the reschedule endpoint
Basic authentication username
Basic authentication password
API Endpoint
The component calls the following backend endpoint:- Success: HTTP 200
- Failure: Non-200 status code
Error Handling
The component handles errors at multiple levels:- Network Errors: Caught in try-catch block of server action
- API Errors: Handled by checking
response.ok - User Feedback: Displayed via toast notifications
Related Components
- Messages - Component that displays messages to be rescheduled
- Server Actions - The reschedule server action