README
md13 kBIn Mock exam: React
React Advanced Exam - Event Management System
⚠️ IMPORTANT: Before You Start
Add your information as comments at the top of src/App.jsx:
/*
Student ID: [Your Student ID]
Full Name: [Your Full Name]
Date: [Exam Date]
*/You must include this information in your submission. Missing information will result in a 10-point deduction.
Instructions
- Duration: 90 minutes
- Answer all questions by implementing the solutions in the provided React template
- Write clean, maintainable code following React best practices
- Only
useStatehook is allowed - no other hooks - All components must use functional component syntax
- Use controlled components for all forms
- Test your solution thoroughly before submission
- You may create additional component files in
src/components/if needed
Scenario Overview
You are building an Event Management System for a technology conference. The system allows admins to view events, filter them dynamically, manage registrations, and edit event details through a comprehensive form.
Question 1: Event Dashboard with Advanced Filtering (35 points)
Objective
Create the main event dashboard with smart filtering capabilities using derived state (no useEffect for filtering).
Part A: Initial Setup (10 points)
In App.jsx, initialize the following state:
-
events- array of at least 5 event objects with these properties:id(string/number)title(string)speaker(string)type(string: 'workshop' or 'talk')capacity(number - total seats)registered(number - seats taken)requirements(string - e.g., "Laptop required" or "None")
-
filters- object containing:type(string: 'all', 'workshop', or 'talk')showFullEvents(boolean: true to show full events, false to hide them)searchQuery(string: searches title and speaker)
-
selectedEventId- currently selected event for editing (or null)
Part B: Smart Filtering Logic (15 points)
Create a derived state variable called filteredEvents that combines ALL filters:
Requirements:
- Type Filter: Only show events matching the type (or all if type is 'all')
- Capacity Filter: If
showFullEventsis false, hide events whereregistered >= capacity - Search Filter: Case-insensitive search that matches BOTH
titleANDspeakerfields - Important: Do NOT use
useEffectto filter - calculate directly during render
Part C: Event Cards with Conditional Rendering (10 points)
Create an EventCard component that:
-
Displays:
- Event title and speaker
- Event type badge (workshop/talk)
- Capacity info: "X / Y seats"
- Requirements (if any)
-
Conditional Status Badges:
- 🔴 "SOLD OUT" (red) - when
registered >= capacity - 🟡 "Almost Full" (yellow) - when
capacity - registered <= 5and not sold out - 🟢 "Available" (green) - otherwise
- 🔴 "SOLD OUT" (red) - when
-
Visual Highlight:
- Add a distinct border/background when
isSelectedis true
- Add a distinct border/background when
-
Interactions:
- Clicking the card calls
onSelect(event.id) - Include an "Edit" button that triggers the same selection
- Clicking the card calls
Part D: Empty State Handling (bonus +5 points)
- When
filteredEvents.length === 0, show a helpful empty state message - Include a "Clear All Filters" button that resets filters to default
Question 2: Filter Panel Component (20 points)
Objective
Create a FilterPanel component that provides all filtering controls.
Requirements
-
Props:
filters- current filter state objectonFilterChange- callback to update filters (receives partial filter object)
-
Filter Controls (all must be controlled components):
- Search Input: Text field with placeholder "Search by title or speaker..."
- Type Selector: Radio buttons or segmented control for 'All', 'Workshop', 'Talk'
- Capacity Toggle: Checkbox labeled "Hide full events"
-
Filter Summary Display:
- Show a text summary of active filters below the controls
- Example: "Showing workshops with available seats"
- Example: "Showing all events matching 'React'"
- Hide summary when no filters are active
-
Reset Functionality:
- Include a "Reset Filters" button
- Only show the button when filters differ from default values
- Clicking resets all filters to:
{ type: 'all', showFullEvents: true, searchQuery: '' }
Question 3: Edit Event Form with Dynamic Validation (30 points)
Objective
Create an EditEventForm component that allows editing a selected event with conditional fields and complex validation.
Requirements
-
Props:
event- the selected event objectonSave- callback that receives updated event dataonCancel- callback to close the form
-
Form Fields (all controlled):
Basic Fields (always visible):
- Title (text input)
- Speaker (text input)
- Type (select dropdown: 'workshop' or 'talk')
- Capacity (number input)
Conditional Fields (based on type):
- IF type is 'workshop':
- Show checkbox: "Laptop Required"
- Show text input: "Software Requirements" (visible only if laptop is checked)
- IF type is 'talk':
- Hide laptop and software fields (and reset their values)
-
Validation Rules:
Implement real-time validation with an
errorsstate object:-
Title:
- Required
- Minimum 5 characters
- Error: "Title must be at least 5 characters"
-
Speaker:
- Required
- Cannot be empty
- Error: "Speaker name is required"
-
Capacity:
- Must be a valid number
- Critical: Cannot be less than current
registeredcount - Error: "Capacity cannot be less than current registrations (X)"
-
Software Requirements (when visible):
- Required if "Laptop Required" is checked
- Error: "Please specify software requirements"
-
-
Form Behavior:
- Disable "Save Changes" button if ANY validation errors exist
- Show error messages inline below each field (only after field is touched)
- On save: validate all fields, then call
onSavewith updated data - On cancel: confirm with user before closing if form has changes
-
State Management:
- Use a single
formDatastate object for all field values - Use a separate
errorsstate object for validation messages - Track which fields have been
touchedto control error display
- Use a single
Question 4: Statistics Dashboard (15 points)
Objective
Create a StatsDashboard component that displays real-time analytics based on the current filtered view.
Requirements
-
Props:
events- the filtered events array (from Question 1)
-
Calculated Statistics (derive, don't store in state):
Display the following metrics:
-
Total Events: Count of events in the filtered list
-
Total Capacity: Sum of all
capacityvalues -
Total Registered: Sum of all
registeredvalues -
Occupancy Rate: Calculate as
(Total Registered / Total Capacity) * 100- Format as percentage: "85.5% Occupied"
-
Available Seats:
Total Capacity - Total Registered
-
-
Conditional Alert:
-
If Occupancy Rate > 90%, display a warning alert:
- "⚠️ High Attendance Expected - Prepare Overflow Seating"
- Use distinct styling (red/orange background)
-
Otherwise, show a normal status message
-
-
Event Type Breakdown:
- Count workshops vs talks in the filtered list
- Display: "X workshops, Y talks"
Important: All statistics must be calculated during render, NOT stored in separate state variables. They should update automatically when the filtered events change.
Bonus Question: Event Registration (Optional - 10 points extra credit)
Objective
Add the ability to register attendees for events and track registrations.
Requirements
-
In App.jsx, add state:
registrations- array of registration objects
-
Create a simple RegistrationForm component that:
- Shows for the selected event
- Has fields: Name (text), Email (text)
- Validates: both required, email must contain '@'
- On submit:
- If event has available seats: increment
registeredcount - Add registration to the array
- Show success message
- If event has available seats: increment
-
Display a RegistrationsList component:
- Shows all registrations for the selected event
- Displays: attendee name and email
- Include a "Cancel Registration" button that:
- Decrements the event's
registeredcount - Removes registration from array
- Decrements the event's
Technical Requirements & Best Practices
Code Quality
- Use meaningful variable and function names
- Add comments for complex logic only (code should be self-documenting)
- Keep components focused (single responsibility)
- Avoid code duplication - extract repeated logic
React Best Practices
- Do NOT use
useEffectto derive state - calculate filtered data during render - All form inputs must be controlled components
- Event handlers should use descriptive names (e.g.,
handleFilterChange, notonChange) - Component props should be documented with comments
Validation
- Show error messages only after a field has been "touched"
- Disable submit buttons when validation fails
- Provide clear, helpful error messages
File Structure
Your submission should follow this structure:
src/
App.jsx # Main component with state management
components/
EventCard.jsx # Q1 - Event display component
FilterPanel.jsx # Q2 - Filter controls
EditEventForm.jsx # Q3 - Event editing form
StatsDashboard.jsx # Q4 - Statistics display
(RegistrationForm.jsx) # Bonus - Optional
Submission Instructions
-
Test thoroughly:
- Test all filter combinations
- Try different event types in the edit form
- Verify the capacity validation works correctly
- Check that statistics update when filters change
- Test conditional field visibility in the form
-
Compress and submit:
- Include your entire project folder
- Exclude
node_modulesdirectory - Name the file:
StudentID_ReactExam.zip - Upload to the designated platform
-
Before submitting:
- Ensure your Student ID and Name are in App.jsx comments
- Run
npm run devto verify no errors - Check that all required components are included
Grading Rubric
| Question | Points | Key Criteria |
|---|---|---|
| Q1: Event Dashboard & Filtering | 35 | State structure (10), filtering logic (15), conditional rendering (10) |
| Q2: Filter Panel | 20 | Controlled components (10), filter summary (5), reset functionality (5) |
| Q3: Edit Event Form | 30 | Form structure (10), conditional fields (10), validation (10) |
| Q4: Statistics Dashboard | 15 | Correct calculations (10), conditional alert (5) |
| Bonus: Registration | +10 | Optional extra credit |
| Code Quality & Style | -0 to -10 | Deductions for poor practices, bugs, missing comments |
| Total | 100 | (110 with bonus) |
Common Pitfalls to Avoid
⚠️ Difficulty Factor 1: Students often fail to combine ALL filters correctly. Make sure your filtering logic uses && to combine type, capacity, AND search filters.
⚠️ Difficulty Factor 2: The validation rule capacity < registered requires cross-referencing two values. Don't forget to check against the CURRENT registered count.
⚠️ Difficulty Factor 3: Statistics must be calculated on-the-fly during render, NOT stored in state. If you use useState for totalCapacity, you'll lose points.
⚠️ Difficulty Factor 4: Conditional form fields must fully disappear when type changes - don't just hide them with CSS, actually don't render them.
Time Management Suggestions
- Q1 (35 min): Set up state, implement filtering, create event cards
- Q2 (15 min): Build filter panel with controlled inputs
- Q3 (25 min): Create edit form with validation
- Q4 (10 min): Add statistics dashboard
- Buffer (5 min): Testing and debugging
- Bonus (optional): If time permits
Good Luck! 🚀
Remember:
- Start with Q1 - getting the data structure right makes everything easier
- Test each component as you build it
- Use descriptive variable names
- Focus on making it work correctly before making it look perfect
- Only attempt the bonus if you finish the main questions early
End of Exam