Function Signature
src/lib/actions/message/updateMessage.ts:21
Parameters
Previous state object returned from the last invocation. Used by React’s
useActionState hook.Form data containing the message details to update
Return Value
Validation Schema
The function uses Zod for validation:Behavior
- Validation: Form data is validated against the Zod schema
- API Call: Makes a POST request to
{BACKEND_URL}/messages/update-one/{id} - Authentication: Uses Basic Auth with environment credentials
- Revalidation: Calls
revalidatePath("/")on success to refresh the home page - Error Handling: Returns structured error messages for validation, backend, or network errors
Usage Example
Backend Endpoint
POST/messages/update-one/:id
Headers:
Authorization: Basic authenticationContent-Type: application/json
Differences from createMessage
- ID Required: Must include the message ID to identify which message to update
- sendAfter Minimum: Allows 0 days (vs. 1 day minimum for create)
- Endpoint: Uses
/update-one/:idinstead of/create-one