FAQ - hackforla/tdm-calculator GitHub Wiki
FAQ Form
- FAQ page helps user to understand the TDM website better as well as help to get answers to all frequently asked questions and if it is not answered, user can checkout guidelines page or reach us out at our feedback page.
- For browsing FAQ page, user do not need access to the website.
- Editing is only available to the admin
- Once you click on the "Edit FAQ Page" button the screen switches from screenshots 2 to 3 (below).
URLS
- Dev URL: https://tdm-dev.azurewebsites.net/faqs
- Prod URL: https://tdm.ladot.lacity.org/faqs
- GitHub location:
- Figma Design:
- WIKI TDM Calculator Figma Pages and Structure
- Figma [TDM Calculator Figma Pages and Structure, User-Facing Screens]
- Figma [TDM Calculator Handoff, User-Facing Screens]
Issue label
- Issue Label on Issue tab: p-feature: FAQ screen
- Issue label on Project Board: p-feature: FAQ screen
Screen shots of page
Technical Details
Overview
The FAQ system is a React-based implementation that allows both viewing and administrative management of Frequently Asked Questions organized by categories. The system provides a dynamic, interactive user interface with drag-and-drop capabilities for reordering both categories and FAQs within each category.
Key Components Architecture
The FAQ page is built using a hierarchical component structure:
- FaqView (FaqView.jsx) - The main container component that manages the overall state and functionality
- FaqCategoryList (FaqCategoryList.jsx) - Renders the list of FAQ categories
- FaqCategory (FaqCategory.jsx) - Handles individual category display and editing
- FaqList (FaqList.jsx) - Manages the list of FAQs within a category
- Faq (Faq.jsx) - Handles individual FAQ display and editing
- CategoryInputContainer (CategoryInputContainer.jsx) - Provides a container wrapper for category input fields with delete and drag controls
- CategoryInput (CategoryInput.jsx) - Manages the editable input field for category names and toggles between view/edit modes
- FaqButtonContainer (FaqButtonContainer.jsx) - Houses the interactive buttons for each FAQ, including expand/collapse, delete, and drag controls
- ExpandButtons (ExpandButtons.jsx) - Provides global expand/collapse functionality for all FAQs
- NewFaqButton (NewFaqButton.jsx) - Renders the button to add a new FAQ to a category
- NewFaqContainer (NewFaqContainer.jsx) - Manages the form interface for creating new FAQs
- Question (Question.jsx) and Answer (Answer.jsx) components - Handle the display and editing of individual FAQs
The architecture follows a parent-child data flow pattern where state is managed at higher levels and passed down to child components via props.
State Management
The FAQ state is primarily managed in the FaqView
component using React's useState hooks:
faqCategoryList
- The main state array containing all FAQ categories and their associated FAQsadmin
- Boolean flag determining if the page is in admin/edit modeexpanded
- Boolean flag tracking if all FAQs are expanded or collapsedformHasSaved
- Boolean tracking if there are unsaved changes- Various modal states for confirmations and warnings
Data is fetched from and saved to a backend service using the faqCategoryService
methods.
Core Functionality
Viewing FAQs (User Mode)
When a user visits the FAQ page, they can:
- View categories of FAQs
- Expand/collapse individual FAQs by clicking on questions
- Use "Expand All" or "Collapse All" buttons to show/hide all answers at once
- Follow links in answers, which will open in a new tab (external links are marked with an icon)
Managing FAQs (Admin Mode)
When an administrator activates admin mode via the edit toggle button, they can:
- Create new FAQ categories
- Edit category names by clicking on them
- Reorder categories via drag-and-drop
- Delete categories
- Add new FAQs to categories
- Edit FAQ questions and answers
- Reorder FAQs within and between categories via drag-and-drop
- Delete FAQs
- Save all changes to the backend
Rich Text Editing
The Answer component uses a Quill rich text editor to allow formatting in answers, including:
- Text styling (bold, italic, etc.)
- Links (with special handling for external links)
- Lists and other formatting options
Data Structure
The FAQ data follows this structure:
// Category structure
{
id: Number,
name: String,
displayOrder: Number,
faqs: Array // Array of FAQ objects
}
// FAQ structure
{
id: Number,
question: String,
answer: String, // Can contain HTML markup
faqCategoryId: Number,
displayOrder: Number,
expand: Boolean // UI state only, not stored in database
}
Drag and Drop Functionality
The system uses react-beautiful-dnd
for drag-and-drop functionality:
- Categories can be reordered via drag-and-drop
- FAQs can be:
- Reordered within the same category
- Moved between categories
The DragDropContext in FaqView.jsx
manages this functionality, with Droppable areas defined for both categories and FAQs.
Workflow and User Experience
User Flow
- Users can browse categories of FAQs
- Users can expand FAQs by clicking questions
- Users can expand/collapse all FAQs with dedicated buttons
- External links in answers open in new tabs
Admin Flow
- Admin toggles edit mode with the EditToggleButton
- Admin can add/edit/delete categories and FAQs
- Admin can reorder items via drag-and-drop
- When leaving edit mode:
- Changes are submitted to the backend
- If navigating away without saving, a confirmation dialog appears
Navigation Guards
The system uses React Router's useBlocker
hook to prevent accidental navigation away from the page when there are unsaved changes. A confirmation dialog appears allowing the user to:
- Stay on the page (to save changes)
- Continue navigating (discarding changes)
Key Components In Detail
FaqView
The main container component that:
- Fetches and manages the FAQ data
- Handles saving changes to the backend
- Manages admin mode state
- Provides functions for managing categories and FAQs to child components
- Implements drag-and-drop context
FaqCategory
Manages a single category, including:
- Editing the category name
- Managing the FAQs within the category
- Adding new FAQs
- Handling hover states for delete functionality
Faq
Manages a single FAQ, including:
- Editing question and answer
- Expanding/collapsing
- Hover states for admin actions
Question and Answer
Handle the display and editing of individual questions and answers:
- The Question component toggles between view and edit mode
- The Answer component integrates with the Quill rich text editor
- External links in answers are transformed to open in new tabs
Technical Implementation Notes
Styling
The application uses JSS (JavaScript Style Sheets) via react-jss
for styling. Styles are defined with the createUseStyles
function and applied to components through the classes
object.
State Propagation
The application follows a top-down state management approach where:
- State is primarily maintained in the
FaqView
component - Update functions are passed down to child components
- Child components call these functions to update the parent state
Form Handling
Form fields are controlled components with their values managed in React state. Changes trigger state updates, which in turn update the UI.
Rich Text Handling
The Quill editor is used for rich text editing in answers. The Interweave component is used to render HTML content safely in the view mode.
Event Handling
Event handlers throughout the application follow React's pattern of:
- Defining handler functions
- Passing them to components via props
- Components invoking them in response to user interactions
Optimizations
useCallback
is used for functions that are passed as props to prevent unnecessary re-renders- Component updates are minimized by careful state management
- The application uses conditional rendering to show/hide components based on state
Backend Integration
The FAQ system integrates with backend services via:
faqCategoryService
for fetching and saving category and FAQ data- Data is transformed before being sent to ensure only necessary data is included
Known Technical Considerations
- FAQ editing in admin mode requires careful state management across multiple components
- The Quill editor integration in the Answer component includes special handling for blur events and link transformations
- The drag-and-drop functionality requires specific component structure for proper functioning
- Navigation guards are implemented to prevent accidental data loss