Members
(constant) API_BASE_URL :string
API base URL - JSONPlaceholder for development/testing
Type:
- string
- Source:
(constant) INITIAL_ERRORS :Object
Initial state for validation errors
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
firstName |
string | Empty error message for first name |
lastName |
string | Empty error message for last name |
email |
string | Empty error message for email |
birthDate |
string | Empty error message for birth date |
postalCode |
string | Empty error message for postal code |
city |
string | Empty error message for city |
- Source:
(constant) INITIAL_FORM_DATA :Object
Initial state for form data
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
firstName |
string | Empty first name field |
lastName |
string | Empty last name field |
email |
string | Empty email field |
birthDate |
string | Empty birth date field |
postalCode |
string | Empty postal code field |
city |
string | Empty city field |
- Source:
(constant) INITIAL_TOUCHED :Object
Initial state for field touch status (tracks if user has interacted with field)
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
firstName |
boolean | First name field not yet touched |
lastName |
boolean | Last name field not yet touched |
email |
boolean | Email field not yet touched |
birthDate |
boolean | Birth date field not yet touched |
postalCode |
boolean | Postal code field not yet touched |
city |
boolean | City field not yet touched |
- Source:
(constant) apiService
API service for user management Handles all HTTP requests to the backend API
- Source:
Methods
Home() → {JSX.Element}
Home component that displays the list of registered users
Features:
- Displays user count and list of all registered users
- Shows success toast notification when redirected after registration
- Highlights newly registered user row for 3 seconds
- Provides navigation to registration page
- Shows empty state when no users exist
- Sorts users by registration date (newest first)
- Source:
Returns:
Home page with user list, statistics, and navigation
- Type
- JSX.Element
Register() → {JSX.Element}
Register page component that wraps the UserForm Handles successful registration by adding user to context and navigating to home
- Source:
Returns:
Register page with form
- Type
- JSX.Element
UserForm(props) → {JSX.Element}
Form component that collects user information (first name, last name, email, birth date, postal code, city) with immediate validation feedback.
Parameters:
| Name | Type | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
props |
Object | Component props Properties
|
- Source:
Returns:
The rendered form component
- Type
- JSX.Element
UserProvider(props) → {JSX.Element}
UserProvider component that manages user state globally
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
props |
Object | Component props Properties
|
- Source:
Returns:
Provider component
- Type
- JSX.Element
transformUserFromApi(apiUser) → {Object}
Transform JSONPlaceholder user format to application format
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
apiUser |
Object | User object from JSONPlaceholder API Properties
|
- Source:
Returns:
User object in application format
- Type
- Object
Example
transformUserFromApi({
id: 1,
name: "Leanne Graham",
email: "Sincere@april.biz",
address: { city: "Gwenborough", zipcode: "92998-3874" }
})
// Returns:
// {
// id: 1,
// firstName: "Leanne",
// lastName: "Graham",
// email: "sincere@april.biz",
// age: 31,
// city: "Gwenborough",
// postalCode: "92998",
// timestamp: "2026-02-20T..."
// }
useUsers() → {UserContextValue}
Custom hook to use the UserContext
- Source:
Throws:
-
If used outside of UserProvider
- Type
- Error
Returns:
User context value
- Type
- UserContextValue
validateAge(birthDate, referenceDate) → {void}
Validates that a person is of legal age (>= 18 years) based on their birth date. Performs precise age calculation taking into account the exact day.
Parameters:
| Name | Type | Description |
|---|---|---|
birthDate |
Date | The birth date to validate |
referenceDate |
Date | The reference date for calculation (default: today) |
- Source:
Throws:
-
Throws an exception with a specific error code if validation fails
- Type
- ValidationError
Returns:
- Type
- void
validateEmail(email) → {void}
Validates that an email address follows a standard valid format.
Parameters:
| Name | Type | Description |
|---|---|---|
email |
string | The email address to validate |
- Source:
Throws:
-
Throws an exception with a specific error code if validation fails
- Type
- ValidationError
Returns:
- Type
- void
validateEmailComplete(email, existingUsersopt) → {void}
Validates email format and uniqueness. Combines format validation and uniqueness check.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
email |
string | The email address to validate |
||
existingUsers |
Array.<Object> |
<optional> |
null | Optional array of existing users for uniqueness check |
- Source:
Throws:
-
Throws an exception if validation fails
- Type
- ValidationError
Returns:
- Type
- void
validateIdentity(identity) → {void}
Validates that a name or first name follows proper format rules.
Parameters:
| Name | Type | Description |
|---|---|---|
identity |
string | The name or first name to validate |
- Source:
Throws:
-
Throws an exception with a specific error code if validation fails
- Type
- ValidationError
Returns:
- Type
- void
validatePostalCode(postalCode) → {void}
Validates that a postal code follows the French format (exactly 5 digits).
Parameters:
| Name | Type | Description |
|---|---|---|
postalCode |
string | The postal code to validate |
- Source:
Throws:
-
Throws an exception with a specific error code if validation fails
- Type
- ValidationError
Returns:
- Type
- void
validateUniqueEmail(email, existingUsersopt) → {void}
Validates that an email address is not already registered.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
email |
string | The email address to check for uniqueness |
||
existingUsers |
Array.<Object> |
<optional> |
null | Optional array of existing users. If not provided, reads from localStorage |
- Source:
Throws:
-
Throws an exception if the email is already registered
- Type
- ValidationError
Returns:
- Type
- void
validateUser(userData) → {boolean}
Validates a complete user form with all required fields. This is the main validation function that orchestrates all individual validations.
Parameters:
| Name | Type | Description | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
userData |
Object | The user data object to validate Properties
|
- Source:
Returns:
Returns true if all validations pass, false otherwise
- Type
- boolean
Example
const userData = {
firstName: "Jean",
lastName: "Dupont",
birthDate: new Date(1990, 0, 1),
email: "jean.dupont@example.com",
postalCode: "75001"
};
const isValid = validateUser(userData); // returns true
Type Definitions
User
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
firstName |
string | First name of the user |
lastName |
string | Last name of the user |
email |
string | Email address of the user |
age |
number | Age of the user |
postalCode |
string | Postal code of the user |
city |
string | City of the user |
timestamp |
string | ISO date string of registration |
- Source:
UserContextValue
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
users |
Array.<User> | Array of registered users |
addUser |
function | Function to add a new user (async) |
refreshUsers |
function | Function to refresh users from API (async) |
loading |
boolean | Loading state for API operations |
error |
string | null | Error message if API call fails |
- Source: