Build a Feedback Widget
Learn how to build a feedback widget in supastarter – a complete guide from database to UI
In this guide, we'll take you through the process of implementing a feature in supastarter from start to finish. This will a lot of the things from the previous guides and documentation, but we'll be doing it in a more complete way and with a more concrete example of creating a feedback widget for your app.
Overview
The feedback widget consists of:
- Database Schema: Prisma model to store feedback data
- Database Queries: Dedicated query functions for feedback operations
- API Endpoint: REST API to handle feedback submissions with session integration
- Frontend Component: React component with form and UI
- Translations: Internationalization support for the widget
Step 1: Database Schema
First, we added a Feedback
model to the Prisma schema:
We also added the relation to the User model:
Step 2: Database Queries
Created dedicated query functions for feedback operations:
Updated the queries index to export the feedback functions:
Step 3: API Endpoint
Created the feedback API route with validation and session integration:
Added the router to the main API app:
Step 4: Frontend Component
Created a React component with form validation, session integration, and internationalization:
Step 5: Translations
Added translation keys for the feedback widget:
Step 6: Integration
Add the feedback widget to your layout or pages:
Step 7: Evaluation
The next logical step would be to add some way to evaluate the feedback. You could either send it an admin email or build a small page in the admin dashboard to view the feedback.
We'll cover this in a future guide.
Features
The feedback widget includes the following features:
- Session Integration: Automatically associates feedback with logged-in users
- Conditional Fields: Name and email fields are hidden for logged-in users
- Internationalization: Full i18n support with English and German translations
- Form Validation: Client-side validation with Zod schema
- Responsive Design: Mobile-friendly UI with Tailwind CSS
- Database Storage: Persistent storage with Prisma ORM
- API Integration: RESTful API with proper error handling
- Type Safety: Full TypeScript support throughout the stack
Usage
The feedback widget will appear as a floating button in the bottom-right corner of the page. Users can:
- Click the feedback button to open the dialog
- Select a feedback type (General, Bug Report, or Feature Request)
- Enter their name and email (only for non-logged-in users)
- Write their feedback message
- Submit the feedback
The widget automatically handles:
- Form validation
- Loading states
- Success messages
- Error handling
- Session management
- Database storage
Further Considerations
Here are some additional features you might want to consider adding to your feedback widget:
- Analytics and Insights: Track feedback patterns and user behavior
- Email Notifications: Send admin notifications for new feedback submissions
- Rate Limiting: Prevent spam by limiting submissions per IP address
- Feedback Management Dashboard: Create an admin interface to view and manage feedback
- Sentiment Analysis: Integrate AI services to analyze feedback sentiment
- Export and Reporting: Add CSV export functionality for feedback data
- Accessibility Improvements: Enhance screen reader support and keyboard navigation
- Customization Options: Allow configuration of widget position, theme, and visibility
- Multi-language Support: Add more translation languages beyond English and German
- Feedback Categories: Add more specific feedback types or custom categories
- File Attachments: Allow users to attach screenshots or files with their feedback
- Follow-up Communication: Enable two-way communication with feedback submitters
Conclusion
This guide demonstrates how to build a complete feedback widget in supastarter, covering all aspects from database design to user interface. The implementation follows supastarter's best practices:
- Type Safety: Full TypeScript integration throughout the stack
- Database Design: Proper Prisma schema with relationships
- API Design: RESTful endpoints with validation and error handling
- UI/UX: Modern, accessible components with Shadcn UI
- Internationalization: Multi-language support
- Session Integration: Seamless user experience for logged-in users
- Error Handling: Comprehensive error management and user feedback
The feedback widget serves as an excellent example of how to implement features in supastarter, showcasing the framework's capabilities for building production-ready applications. The modular approach allows for easy extension and customization based on your specific needs.
Key takeaways:
- Start with database schema and work your way up to the UI
- Use TypeScript for type safety across the entire stack
- Implement proper validation and error handling
- Consider user experience and accessibility
- Plan for scalability and maintenance
- Follow the established patterns in your codebase
This pattern can be applied to build other features like contact forms, support tickets, or any user input system. The feedback widget demonstrates the power and flexibility of the supastarter framework for building real-world applications.