IMPORTANT: All forms in the CoRide Morocco app must use the form-driven schema system. Never create standalone forms - always leverage the schema registry for consistency, validation, and maintainability.
The CoRide Morocco app uses a centralized form system based on JSON Schema that provides:
- ✅ Automatic form rendering and validation
- ✅ Consistent UI/UX across all forms
- ✅ Type safety with TypeScript interfaces
- ✅ Mock API integration for development
- ✅ Centralized form definitions
- Purpose: Central registry for all form definitions
- Pattern: Use JSON Schema format for consistent structure
- Forms Available: contactSupport, createRideRequest, createRideOffer, submitFeedback, reportIssue
- Purpose: Renders forms as modal overlays
- Usage: For quick forms and secondary actions
- Integration: Uses mock API functions for CoRide Morocco
- Purpose: Renders forms as full-screen experiences
- Usage: For complex forms and primary actions
- Features: Navigation, keyboard handling, validation feedback
- Purpose: Renders individual form fields based on schema
- Support: Text, email, password, number, select, textarea, datetime fields
- Features: Automatic validation, error display, accessibility
export const formSchemas: FormSchemas = {
myNewForm: {
schema: {
type: "object",
title: "My New Form",
description: "Description of what this form does",
properties: {
fieldName: {
type: "string",
title: "Field Label",
// Add validation rules here
}
},
required: ["fieldName"]
},
uiSchema: {
fieldName: {
"ui:widget": "text",
"ui:placeholder": "Enter value..."
}
},
successMessage: "Form submitted successfully!",
errorMessage: "There was an error submitting the form."
}
};// In FormModal.tsx or FormScreen.tsx
const mockSubmitForm = async (formName: string, data: any) => {
// Add your form handling logic
switch (formName) {
case "myNewForm":
return { success: true, message: "Success message" };
}
};// For Modal
<FormModal
isVisible={isModalVisible}
onClose={() => setModalVisible(false)}
formName="myNewForm"
/>
// For Screen (via navigation)
router.push(`/form-screen?formName=myNewForm`);- Purpose: User support requests and inquiries
- Fields: subject, message, priority
- Usage: Help section, support chat
- Purpose: Passengers requesting rides
- Fields: from, to, departureTime, passengers, notes
- Features: Default departure time, passenger count validation
- Purpose: Drivers offering rides
- Fields: from, to, departureTime, availableSeats, pricePerSeat, notes
- Features: Seat count validation, price formatting
- Purpose: User experience feedback and ratings
- Fields: rating, category, message
- Features: 5-star rating system, categorized feedback
- Purpose: Safety and quality issue reporting
- Fields: type, description, severity, occurred, location
- Features: Severity levels, timestamp tracking
string: Text input with optional length limitsnumber: Numeric input with min/max validationemail: Email validation with format checkingdatetime-local: Date and time pickerselect: Dropdown with predefined optionstextarea: Multi-line text input
uiSchema: {
fieldName: {
"ui:widget": "text" | "textarea" | "select" | "number" | "email" | "datetime-local",
"ui:placeholder": "Placeholder text",
"ui:description": "Help text for users",
"ui:options": ["option1", "option2"] // For select fields
}
}- Always use the schema registry for new forms
- Follow the established naming conventions
- Include comprehensive validation rules
- Provide clear error messages
- Add accessibility labels
- Use mock API functions for development
- Test forms on both modal and screen components
- Create standalone form components
- Hardcode form fields in JSX
- Skip validation or error handling
- Forget to update the schema registry
- Use real API calls in development
- Mix form patterns (always use schema-driven)
- Automatic field-level validation based on JSON Schema
- Real-time error display as users type
- Form-level validation before submission
- Clear, actionable error messages
- Network error handling with retry options
- User-friendly error messages
- Haptic feedback for better UX
- Logging for debugging purposes
- Define schema in
formSchemas.ts - Add mock API function
- Test with both FormModal and FormScreen
- Verify validation rules work correctly
- Test accessibility features
- Update this documentation
- Update schema definition
- Ensure backward compatibility
- Test all form usage locations
- Update validation tests
- Verify API integration still works
- Test all field types and validation rules
- Test both success and error scenarios
- Verify accessibility (screen readers, keyboard navigation)
- Test on different screen sizes
- Test with real data variations
// Navigate to form screen
router.push(`/(main)/form-screen?formName=${formName}`);
// Open form modal
setFormModalVisible(true);
setSelectedForm(formName);- Mock functions during development
- Replace with real API calls when backend is ready
- Maintain same response format for consistency
- Handle loading states and error scenarios
- All input sanitization through JSON Schema
- Type checking at runtime
- Required field enforcement
- Length limits and format validation
- No sensitive data in form schemas
- Secure transmission for production APIs
- Proper error message handling (no data leaks)
- Input sanitization for security
- File upload support for forms
- Multi-step form wizard capability
- Dynamic field conditions (show/hide based on other fields)
- Form analytics and usage tracking
- Offline form submission queue
- Plugin system for custom field types
- Custom validation rules
- Form templates for common patterns
- Integration with external services
Remember: The form-driven schema system is the foundation of all form interactions in CoRide Morocco. Always use this system to ensure consistency, maintainability, and the best user experience.
For questions or clarifications about the form system, refer to this guide or check the existing form implementations in the schema registry.