A React-based form library for Polydock registration with hooks and components.
- Registration Form Component: Pre-built form for Polydock app registration
- React Hooks: Reusable hooks for API integration (
useRegions,useRegister) - TypeScript Support: Full type safety and autocompletion
- Dual Build: Static demo app and reusable library output
- API Integration: Connects to
/api/registerand/api/regionsendpoints
- Node.js 18+
- npm or yarn
npm installnpm run devThis starts a development server with:
- Registration form demo with Tailwind CSS styling
- Mock API for testing (no backend required)
- Hot module replacement
npm run buildCreates a static build in dist/ for deployment.
npm run build:libCreates library files in dist/ for importing in other projects.
import { RegistrationForm, useRegions, useRegister } from 'polydock-forms';
// Use the complete form component
function MyApp() {
return (
<RegistrationForm
apiBaseUrl="https://your-api.com/api"
onSuccess={(response) => console.log('Success:', response)}
onError={(error) => console.error('Error:', error)}
/>
);
}
// Or use individual hooks
function CustomForm() {
const { regions, loading, error } = useRegions('https://your-api.com/api');
const { register, loading: registering } = useRegister('https://your-api.com/api');
// Your custom form implementation
}Fetches available regions and apps from /api/regions.
Returns:
regions: Array of regions with their appsloading: Boolean loading stateerror: Error message if anyrefetch: Function to refetch data
Handles registration form submission to /api/register.
Returns:
register: Function to submit registration dataloading: Boolean loading stateerror: Error message if anyresponse: API response objectreset: Function to reset state
| Prop | Type | Description |
|---|---|---|
apiBaseUrl |
string |
Base URL for API calls (default: /api) |
onSuccess |
(response) => void |
Success callback |
onError |
(error) => void |
Error callback |
Returns available regions and apps:
{
"status": "success",
"data": {
"regions": [
{
"id": 1,
"label": "USA",
"uuid": null,
"apps": [
{
"uuid": "app-uuid-123",
"label": "Drupal Commerce"
}
]
}
]
}
}Accepts registration data:
{
"polydock_store_app_uuid": "app-uuid-123",
"first_name": "John",
"last_name": "Doe",
"email": "[email protected]",
"type": "trial",
"accepted_privacy_policy": true,
"accepted_aup": true
}All API types are exported from the library:
import type {
Region,
App,
RegionsResponse,
RegisterFormData,
RegisterResponse
} from 'polydock-forms';- Development Mode: Uses mock API data, no backend required
- Production Mode: Connects to real polydock-engine API endpoints
- The library build excludes React/ReactDOM as external dependencies
- Styling uses Tailwind CSS with responsive design
- Mock API simulates realistic loading times and responses