The Trucking Company
Practicing styling with CSS Modules, React Router, and error handling

This CodeLab exercise is mainly designed to help you practice the concepts you have learned in the Frontend Week IV module. But you will need to use the knowledge from the previous weeks as well.
You will be building a simple application for a trucking company. The application will allow you to manage trucks and drivers. You will be able to view a list of trucks and drivers, register new drivers, and view details about each truck and driver.

The Assignment
Basic setup with pages
- Create a new React application with Vite.
- Install the react router.
- Create 2 new folders called
componentsandpagesin thesrcfolder. - Add the json Mock server.
- Get the
db.jsonfile from here and place it in the root of your project. -
Create the following pages:
Homepage that shows an image of a truck and explains what the app is about (Administering a trucking company).Trucksa page that displays a list of trucks. Each truck should have a name and a description with weight and capacity.Driversa page that displays a list of drivers. Each driver should have a name, and a description (with driver details).RegisterDrivera page that allows you to register a new driver. Use a form similar to this example.
Components
- Create a
Headercomponent that displays a navigation bar with links to the different pages. - Create a
Footercomponent that displays the text “© 2025 Trucking Company”. - Create a
TruckCardcomponent that displays a truck with a name, description, and picture. The card should have its own route and be displayed when you click on a truck. - Create a
DriverCardcomponent that displays a driver with a name, description, and picture. The card should have its own route and be displayed when you click on a driver.
Styling and error handling
- Style everything using CSS Modules. For each component, create a corresponding
.module.cssfile (e.g.,TruckCard.module.css). Use semantic class names likecard,title,container, etc. - Use global CSS variables in
global.cssto define light/dark theme colors and apply them via thebodyclass (e.g.body.light,body.dark). - Add error handling to the
TruckCardandDriverCardcomponents. If the truck or driver does not exist, display an error message in a sharedErrorBannercomponent rendered in the mainOutlet. - Add a 404 page that displays a message saying “Page not found” and a link to the home page.
- Add a 500 error page that displays a message saying “Server error” when a component fails to render.
- Use
try-catchblocks in the fetch logic insideTruckCardandDriverCardto catch and display errors in the error banner.
Extra
- Implement buttons to delete or edit trucks and drivers. The edit button should take you to a form where you can update truck or driver details.
Note: You are expected to apply your knowledge of React Context and CSS Modules for theming from the light/dark theme tutorial. See tutorial here.