Documentation Index Fetch the complete documentation index at: https://mintlify.com/anupom69/bun-hono-frontend-nextjs/llms.txt
Use this file to discover all available pages before exploring further.
Function Signature
async function updateMessage (
prevState : MessagePrevState ,
formData : FormData
) : Promise < MessagePrevState >
Source: src/lib/actions/message/updateMessage.ts:21
Parameters
Previous state object returned from the last invocation. Used by React’s useActionState hook. Indicates if the previous operation was successful
Error message from the previous operation
Form data containing the message details to update The unique identifier of the message to update Validation:
Minimum length: 1 character
Error: “ID is required”
The updated message content Validation:
Minimum length: 1 character
Error: “Content cannot be empty”
Updated phone number to send the message to Validation:
Pattern: /^8801\d{9}$/
Must start with “8801” followed by exactly 9 digits
Error: “Invalid phone number format. Must be 8801XXXXXXXXX”
Updated number of days after which to send the message Validation:
Minimum: 0 days
Error: “Send after is required and minimum after 0 day”
Return Value
Set to true when the message is updated successfully
Error message describing what went wrong Possible errors:
Validation errors: Comma-separated list of field validation failures
Backend errors: “Backend Error: ”
Generic errors: “Something went wrong”
Validation Schema
The function uses Zod for validation:
const messageSchema = z . object ({
id: z . string (). min ( 1 , "ID is required" ),
content: z . string (). min ( 1 , "Content cannot be empty" ),
sendToPhone: z
. string ()
. regex ( / ^ 8801 \d {9} $ / , "Invalid phone number format. Must be 8801XXXXXXXXX" ),
sendAfter: z
. number ()
. min ( 0 , "Send after is required and minimum after 0 day" ),
});
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
import { useActionState } from "react" ;
import updateMessage from "@/lib/actions/message/updateMessage" ;
function EditMessageForm ({ messageId } : { messageId : string }) {
const [ state , formAction ] = useActionState ( updateMessage , {});
return (
< form action = { formAction } >
< input type = "hidden" name = "id" value = { messageId } />
< textarea name = "content" placeholder = "Message content" />
< input name = "sendToPhone" placeholder = "8801XXXXXXXXX" />
< input name = "sendAfter" type = "number" min = "0" />
< button type = "submit" > Update Message </ button >
{ state . error && < p >{ state . error }</ p >}
{ state . success && < p > Message updated !</ p >}
</ form >
);
}
Backend Endpoint
POST /messages/update-one/:id
Headers:
Authorization: Basic authentication
Content-Type: application/json
Body:
{
"id" : "message-123" ,
"content" : "Updated message" ,
"sendToPhone" : "8801234567890" ,
"sendAfter" : 3
}
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/:id instead of /create-one