Function Signature
src/lib/actions/people/deletePerson.ts:9
Parameters
Previous state object returned from the last invocation. Used by React’s
useActionState hook.Form data containing the person identifier
Return Value
Validation
This function performs simple validation without Zod:Behavior
- Validation: Checks that the ID field is present
- API Call: Makes a POST request to
{BACKEND_URL}/people/delete-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
Usage Example
Alternative Usage with Confirmation
Backend Endpoint
POST/people/delete-one/:id
Headers:
Authorization: Basic authentication
Cascading Effects
Deleting a person may affect related data:- Messages: Any scheduled messages associated with the deleted person’s phone number may become orphaned
- Data Integrity: Ensure your backend handles cascading deletes or orphaned references appropriately
Best Practices
- Confirmation: Always ask for user confirmation before deleting
- Soft Deletes: Consider implementing soft deletes on the backend to allow recovery
- Error Handling: Display clear error messages to users
- Audit Trail: Log deletion actions for compliance and debugging