Files
MyClub/POLL_CREATION_FEATURE.md
T
Tomas Dvorak 77213f4e83 dev day #65
2025-10-19 17:16:57 +02:00

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 createPollMutation for poll creation
  • Added helper functions:
    • resetNewPollForm() - Resets form to initial state
    • handleCreatePoll() - Validates and submits new poll
    • addOption() - Adds new poll option
    • removeOption() - Removes poll option with validation
    • updateOption() - 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:

  1. User creates a new activity
  2. Fills in activity details
  3. Sees poll section with informative message
  4. Saves the activity first
  5. Reopens the activity for editing
  6. 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"
  7. Poll is automatically created and linked to the activity

Editing Activity - Adding Poll:

  1. Open existing activity
  2. Scroll to "Anketa" section at the bottom
  3. Choose between:
    • Propojit existující: Select and link an existing poll
    • Vytvořit novou: Create a new poll inline
  4. Poll appears on the activity detail page for users to vote

Technical Details

API Integration:

  • Uses /admin/polls POST endpoint for poll creation
  • Automatically sets related_event_id when 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

  1. Improved UX: No need to navigate to separate poll management page
  2. Faster Workflow: Create polls directly when creating activities
  3. Better Context: Poll creation happens in the context of the activity
  4. Reduced Clicks: Fewer page transitions required
  5. 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