react-waitlist
Version:
A customizable waitlist form component for React applications
81 lines (80 loc) • 2.41 kB
TypeScript
import { Field, SecurityConfig, ResendMapping, WebhookConfig } from '../core/types';
import { eventBus } from '../core/events';
/**
* Form states
*/
export type FormState = 'idle' | 'submitting' | 'success' | 'error';
/**
* Hook options
*/
export interface UseWaitlistFormOptions {
/** Fields to collect */
fields: Field[];
/** Security configuration */
security?: SecurityConfig;
/** Mapping to Resend API fields */
resendMapping?: ResendMapping;
/** Resend Audience ID */
resendAudienceId?: string;
/** Endpoint for Resend proxy API */
resendProxyEndpoint?: string;
/** Endpoint for webhook proxy API */
webhookProxyEndpoint?: string;
/** Resend API key (only use in server components or with proxy) */
apiKey?: string;
/** Analytics configuration */
analytics?: any;
/** Webhook configuration */
webhooks?: WebhookConfig[];
/** Callback when view event occurs */
onView?: (data: {
timestamp: string;
}) => void;
/** Callback when submit event occurs */
onSubmit?: (data: {
timestamp: string;
formData: Record<string, any>;
}) => void;
/** Callback when success event occurs */
onSuccess?: (data: {
timestamp: string;
formData: Record<string, any>;
response: any;
}) => void;
/** Callback when error event occurs */
onError?: (data: {
timestamp: string;
formData: Record<string, any>;
error: Error;
}) => void;
}
/**
* Hook return value
*/
export interface UseWaitlistFormReturn {
/** Current form state */
formState: FormState;
/** Form values */
formValues: Record<string, string | boolean>;
/** Validation results */
validationResults: Record<string, {
valid: boolean;
message?: string;
}>;
/** Error message */
errorMessage: string;
/** Honeypot field name */
honeypotFieldName: string;
/** Handle input change */
handleChange: (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => void;
/** Handle form submission */
handleSubmit: (e: React.FormEvent) => Promise<void>;
/** Reset form */
resetForm: () => void;
/** Event bus */
eventManager: typeof eventBus;
}
/**
* Hook for waitlist form functionality
*/
export declare const useWaitlistForm: (options: UseWaitlistFormOptions) => UseWaitlistFormReturn;