Task 08 - Next.js - RSC, Forms
This week your task is to implement an application that will allow CRUD operations over a movie database. The retrieval of movie data will be exclusively via asynchronous RSC. Create, update, and delete will be via the API by default.
Description
Your task is to implement simple Nextjs application with three pages:
- Home page
/ - Movies list page
/movies - Movie edit page
/movie/:id
Home page /
- This page contains just a form with two fields. Form is specified below. After submitting the form (creating new movie), user should be redirected to the movies list page
/movies.
Movies list page /movies
- This page must be RSC component. You must get movies from file
movies.jsonand display them. Each movie must have two actions - Edit and Delete.- Edit button redirects user to
/movie/:idpage - Delete button deletes movie from
movies.jsonfile and redirects user to/page
- Edit button redirects user to
Movie edit page /movies/:id
- This page contains the same form as
/, but with prefilled values. After submitting, user is redirected to/movies.
Requirements
- Form - use
React Hook Formlibrary andZodvalidation.- Name field - text field.
- Type field - select field. In root of the project, there's
movie-types.jsonfile. All types from this file must be listed as options in the select field. You must get these types from a file using RSC. You are required to create a loading state while getting movie types from the file.
- There are three API routes:
POST /api/movie- creates new moviePUT /api/movie/:id- updates movie with givenidDELETE /api/movie/:id- deletes movie with givenid
- For working with API routes, use
tanstack querylibrary. - There is a prepared function
readMoviesto get movies frommovies.jsonfile. You can find it insrc/server/movie.tsfile. This function can only run in RSC. You must use it to get movies in/moviesand/movie/:idpage. - For
/and/movie/:id, create a loading page, since both pages are async RSC.
Video
Hints
- See
src/componentsfolder, what is already implemented for you. - While developing, you can lower
sleepfunction. - In
src/schema, you can find zod schema for movie. - Use
Suspensearound the component, that gets data frommovie-types.jsonfile. - In
/movie/:idpage, you can get movie data using async RSC and functionreadMoviesand filter byid.
Submission
There should be created a pull request called "Feedback" immediately after accepting the github classroom assignment.
If you have a Feedback pull request
You can push your solution straight to main. You will then see the diff against main in the pull request feedback. Once you have the solution in main, mark the Feedback PR as submitted.
If you don't have a Feedback pull request
It may be that it will be created later, or it may not be created at all... Therefore, as a precaution, create a new branch solution from main as soon as you accept the assignment, and then push your solution to it.
- If the Feedback PR does not appear, make a pull request from your
solutionbranch to mainu and mark this PR as submitted. - If the Feedback PR does appear, merge your branch
solutioninto main, then mark the Feedback PR as submitted.