React_Labs_Chapters_08_09
zip25 files31 kBIn React labs: chapters 8–9
lab3-solution/6
index.html1 kBpackage.json1 kBREADME.md6 kBREFLECTION.md6 kBvite.config.js1 kBlab3-template/4
index.html1 kBpackage.json1 kBvite.config.js1 kBReact_Lab_Ch08-09_Student.md
React Lab 03 – Chapters 08–09 (Student Guide)
Goal
Build the Workshop Registration Control Room focusing on Chapter 08 (conditional rendering patterns) and Chapter 09 (forms & validation). Students will coordinate filters, empty states, and confirmation banners while implementing a fully controlled registration form.
Template Requirement
- Duplicate the provided
lab3-templatefolder and rename itreact-lab03-<yourname>. - Run
npm installinside the duplicated folder. - Do not rename starter files. Add new components under
src/components. - Keep the schedule times exactly as provided (use ق.ظ. / ب.ظ. abbreviations).
Styling Rules
- The file
src/styles/lab-theme.cssalready contains the layout grid, hero styles, pills, and summary panel colors. - Extend styling by adding new utility classes in the same folder if necessary.
- Avoid inline styles—use the supplied CSS tokens/variables for consistency.
Part 1 – Data Flow & Selection State (Chapter 08)
- Import
useStateand initialize:workshopswithINITIAL_WORKSHOPS.filterswith{ showOnlyOpen: false, mode: 'all', focus: 'all' }.selectedWorkshopIdwith the first workshop’sid.lastRegistrationwithnull.
- Derive
filteredWorkshopsby applying these rules:- When
filters.showOnlyOpenis true, drop sessions whereseats.taken >= seats.total. - When
filters.mode!=='all', match only workshops with thatmode. - When
filters.focus!=='all', requireworkshop.focus === filters.focus.
- When
- Pick
selectedWorkshopby matchingselectedWorkshopId. If the selected workshop is filtered out, automatically fall back to the first available workshop usinguseEffect. - Compute helper values:
openCount– count workshops with available seats.isFull– bool for the currently selected workshop.almostFull– remaining seats<= 3.noResults– boolean whenfilteredWorkshops.length === 0.
- Render the hero pills:
"X of Y sessions still open"(always visible)."Urgent · Almost full"pill only whenalmostFullis true.
Part 2 – Filter Panel & Workshop Cards (Chapter 08)
- Complete
FilterPanel.jsx:- Controlled checkbox for
showOnlyOpen. - Radio/segmented buttons for delivery
mode. <select>forfocus(all,events,forms,assessment).- Call
onFilterChange(partial)and merge it into state inApp.jsx.
- Controlled checkbox for
- Show a caption below the filters summarizing the active filters (e.g., "Showing remote-only workshops focused on forms").
- Build
WorkshopCard.jsx:- Accept props
{ workshop, isSelected, onSelect }. - Highlight the card when selected (
workshop-card--selected). - Display badges for mode/focus and seat status (
Open,Filling fast,Waitlist only). - Button triggers
onSelect(workshop.id).
- Accept props
- Replace the placeholder paragraph in
App.jsxwith:- An empty state article when
noResultsis true. - A
.workshop-gridthat mapsfilteredWorkshopsto<WorkshopCard />.
- An empty state article when
Part 3 – Registration Form (Chapter 09)
-
Finish
RegistrationForm.jsxusinguseState:const [formData, setFormData] = useState({ fullName: '', email: '', experience: 'beginner', attendanceType: workshop?.mode === 'remote' ? 'remote' : 'in-person', needsEquipment: false, dietary: 'none', notes: '' }) -
Validate inputs:
- Name must be at least 3 characters.
- Email must contain
'@'(manual check per instructor preference).
-
Add radio inputs for attendance type. Disable the in-person option when
workshop.mode === 'remote'. -
Show conditional fields:
- When
needsEquipmentis true, display an extra textarea asking what is needed. - When
dietary !== 'none', show a helper note reminding the instructor.
- When
-
On submit:
- Prevent default.
- Abort if invalid or if the workshop is full and you plan to skip waitlists.
- Call
onSubmit({ ...formData, workshopId: workshop.id }). - Reset the form & errors.
Part 4 – Confirmation Panel & Seat Updates (Chapters 08–09)
- In
App.jsx, createhandleRegistrationSubmit(payload):- Determine if the workshop still has seats.
- If seats remain, increment
seats.taken. - Otherwise, flag the payload as
waitlist: truewithout changing seats. - Save
{ ...payload, waitlist, submittedAt: new Date().toISOString() }tolastRegistration.
- Pass
registration={lastRegistration}andonClear={() => setLastRegistration(null)}toSummaryPanel. - In
SummaryPanel.jsx:- Render nothing when
registrationisnull. - Show attendee info, target session, and status ("Confirmed" vs "Waitlist").
- Only show dietary/equipment notes when provided.
- Include a “Clear summary” button.
- Render nothing when
- Optional stretch goals:
- Keyboard shortcut: pressing
wtoggles between workshops. - Persist registrations in
localStorage. - Animate summary panel entrance.
- Keyboard shortcut: pressing
Deliverables
- Working React project that satisfies all sections.
README.mddescribing setup, state variables, components, and conditional logic implemented.- Optional
REFLECTION.mdwith lessons learned from each part.
Submission Checklist
- Template duplicated, dependencies installed.
- Filters adjust the workshop grid with correct empty-state handling.
- Cards highlight selection and show accurate seat badges.
- Registration form uses controlled inputs + inline validation.
- Seat counts update (or waitlist is triggered) after submission.
- Summary panel reflects the latest registration with correct styling.
- Hero + badges use conditional rendering as specified.
- README completed with setup notes and feature overview.
Good luck! Test each conditional branch (open vs full, remote vs in-person, filter edge cases) before you move on.