Module Structure
The utilities are organized into the following categories:Constants
Application-wide constants including:- Environment configuration and API URLs
- Status and severity options for dropdowns
- Asset types and component configurations
- Modal identifiers and permission modules
- Filter options for users, transactions, and entities
Helper Functions
Utility functions for common operations:- Date formatting - Convert timestamps to user timezones
- String manipulation - kebab-case, sentence case, camelCase conversions
- File operations - CSV generation and download
- Status helpers - Get variants and text for UI components
- Pagination - Generate page lists with ellipsis
- Role utilities - Extract permissions and determine routes
Validation Schemas
Zod-based validation schemas for forms and API payloads:- Shared validators - Email, password, phone number, numeric strings
- Entity schemas - Assets, samples, alarms, recommendations
- Auth schemas - Sign up, login, OTP verification
- Organization schemas - Sites, departments, organizations
Installation
Utilities are exported from@/utils and can be imported directly:
Usage Example
Common Patterns
Status Badge Variants
UsegetStatusVariant() to determine the appropriate color variant for status badges:
Permission-Based Routing
UsegetFirstRouteFromUser() to redirect users based on their permissions:
Query String Building
UsegetQueryString() to build URL query parameters:
Best Practices
Validation First: Always use Zod schemas to validate user input before sending data to server actions. This ensures type safety and prevents invalid data from reaching the API.
Timezone Awareness: When displaying dates, always use
formatDate() with the user’s timezone to ensure accurate time representation across different regions.CSV Export: Use
generateAndDownloadCsv() for client-side data exports. The function handles proper escaping and encoding of CSV data.Type Safety
All utilities are written in TypeScript and include proper type definitions. Zod schemas automatically infer TypeScript types:Related Resources
- Server Actions - Use validated data with server actions
- Type Definitions - Entity type definitions
- Forms & Validation - Form handling guide