Practicing styling with styled-components and error handling

This CodeLab exercise is designed to help you practice the concepts you have learned in the Frontend Week IV module. You will be working with a partner to complete the tasks in this exercise.


The assignment
Basic setup with pages
- Create a new React application using
npm create vite@latestand choose the React template. - Install the following dependencies:
styled-componentsreact-router-dom@6.28.0
- Create 2 new folders called
componentsandpagesin thesrcfolder. - In package.json add a new script called
json-serverthat runsjson-server --watch db.json --port 3000. - 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. Something like this
Components
- Create a
Headercomponent that displays a navigation bar with links to the different pages. - Create a
Footercomponent that displays the text “© 2024 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
styled-components. Add a theme object with colors and fonts and use it in your components with theThemeProvider. - Add error handling to the
TruckCardandDriverCardcomponents. If the truck or driver does not exist, display an error message in an error banner in the main Outlet component. - 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 can not render due to an error.
- Add try-catch blocks to the fetch requests in the
TruckCardandDriverCardcomponents to catch errors and display the error message 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 edit the truck or driver.