mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-03 18:22:57 +00:00
4.7 KiB
4.7 KiB
Poll Creation Feature in Activity Management
Summary
Enhanced the activity creation/editing interface to allow direct poll (anketa) creation without navigating away to a separate page.
Changes Made
1. Enhanced PollLinker Component
File: frontend/src/components/admin/PollLinker.tsx
New Features:
-
Tabbed Interface: Added two tabs for better organization
- Tab 1: "Propojit existující" - Link existing polls (original functionality)
- Tab 2: "Vytvořit novou" - Create new polls inline
-
Inline Poll Creation Form includes:
- Poll title (required)
- Description (optional)
- Poll type selector (single/multiple choice)
- Dynamic options list (min. 2 options)
- Add/remove options with validation
- Each option has its own input field
- Guest voting toggle
- Active status toggle
- Create button with loading state
Technical Implementation:
- Added state management for new poll form (
newPollData) - Implemented
createPollMutationfor poll creation - Added helper functions:
resetNewPollForm()- Resets form to initial statehandleCreatePoll()- Validates and submits new polladdOption()- Adds new poll optionremoveOption()- Removes poll option with validationupdateOption()- Updates option text
- Automatically links created poll to the current activity/article
2. Updated AdminActivitiesPage
File: frontend/src/pages/admin/AdminActivitiesPage.tsx
Changes:
- Always shows the "Anketa" section (previously hidden for new activities)
- When creating a new activity:
- Displays helpful message: "💡 Nejprve uložte aktivitu, poté budete moci vytvořit nebo připojit anketu přímo zde."
- When editing an existing activity:
- Shows full PollLinker component with both tabs
- Users can immediately create or link polls
User Experience Flow
Creating Activity with Poll:
- User creates a new activity
- Fills in activity details
- Sees poll section with informative message
- Saves the activity first
- Reopens the activity for editing
- In the "Anketa" section:
- Switch to "Vytvořit novou" tab
- Fill in poll details (title, description, type)
- Add poll options (at least 2 required)
- Configure settings (guest voting, active status)
- Click "Vytvořit anketu"
- Poll is automatically created and linked to the activity
Editing Activity - Adding Poll:
- Open existing activity
- Scroll to "Anketa" section at the bottom
- Choose between:
- Propojit existující: Select and link an existing poll
- Vytvořit novou: Create a new poll inline
- Poll appears on the activity detail page for users to vote
Technical Details
API Integration:
- Uses
/admin/pollsPOST endpoint for poll creation - Automatically sets
related_event_idwhen creating poll - Invalidates relevant query cache after operations
Validation:
- Poll title is required
- Minimum 2 options required
- Empty options are filtered out before submission
- Warning toasts for validation errors
State Management:
- React Query for data fetching and mutations
- Local state for form inputs
- Automatic cache invalidation for data consistency
Benefits
- Improved UX: No need to navigate to separate poll management page
- Faster Workflow: Create polls directly when creating activities
- Better Context: Poll creation happens in the context of the activity
- Reduced Clicks: Fewer page transitions required
- Clearer Process: Tabbed interface makes options obvious
Future Enhancements (Optional)
- Allow poll creation before saving activity (requires state management)
- Poll templates for common questions (e.g., "Dorazíš na trénink?")
- Duplicate existing poll functionality
- Poll preview before creation
- Rich text editor for poll descriptions
- Image support for poll options
- Poll scheduling (start/end dates) in the inline form
Testing Checklist
- ✅ Create new activity and see poll section message
- ✅ Save activity and reopen to create poll
- ✅ Create poll with 2 options
- ✅ Add more options dynamically
- ✅ Try to submit poll without title (should show error)
- ✅ Try to submit poll with <2 options (should show error)
- ✅ Toggle guest voting and active status
- ✅ Verify poll appears linked after creation
- ✅ Link existing poll still works
- ✅ Unlink poll still works
- ✅ Poll displays on activity detail page
Notes
- Frontend changes require rebuild if running in Docker:
docker compose restart frontend - For local development, changes should hot-reload automatically
- Poll creation requires the activity to be saved first (has an ID)
- All poll text is in Czech to match the application language