Function Signature
src/lib/actions/people/createPerson.ts:18
Parameters
Previous state object returned from the last invocation. Used by React’s
useActionState hook.Form data containing the person details
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}/people/create-one - 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/people/create-one
Headers:
Authorization: Basic authenticationContent-Type: application/json
Phone Number Format
The phone number must follow Bangladesh’s mobile number format:- Prefix:
8801(country code 880 + mobile prefix 1) - Digits: Exactly 9 additional digits
- Total Length: 13 characters
- Example:
8801712345678
Valid Examples
8801712345678(Grameenphone)8801812345678(Robi)8801912345678(Banglalink)8801612345678(Airtel)8801512345678(Teletalk)
Invalid Examples
01712345678(missing country code)+8801712345678(includes + symbol)88017123456(too few digits)880171234567890(too many digits)