In this task, you are going to crate a form to add a new pet to the pets website. You are going to use MOBX
and react-bootstrap
.
- Fork and clone this repository to your
Development
folder.
npm install react-bootstrap bootstrap@5.1.3
- Create a file called
PetCreateModal.js
inComponents
- Setup your component and import
Modal
from bootstrap. Create the modal as the docs suggets - Create a state for showing the modal with an intial value of
false
. - Create a
handleClose
andhandleShow
functions that changes our state tofalse
ortrue
. - Create a button that when pressed calls the
handleShow
function.
- In the Modal body create a form with the following fields:
name
,type
andimage
. Docs are your friend! click here for the docs - Create a state object to hold the form data.
- For every field in the form, pass
onChange
attribute a method. Create that method and call ithandleChange
, that modifies our state object. - Add a
name
property to each field that matches the state object. - Create a
handleSubmit
method that - for now - console logs our state data and closes the modal. Also pass this method to your submit button. - Don't forget to prevent the page from refreshing.
- Import our modal in
PetsList
and render it at the top.
- In our
petStore
let's create a method for adding a pet. - It takes an argument with our pet data but we still need an
id
. - Generate a unique
id
for every new pet. - In
PetCreateModal.js
import our store, and inhandleSubmit
call the method that adds a new pet from the store, and pass the method the new pet data that was taken from the form.
- Create a file called
PetUpdateModal.js
inComponents
, Create a new modal that is similar toPetCreateModal
, call itPetUpdateModal
- Import the update modal in your
PetItem
component below the adopt button. - For updating, we need the old values for the user to see, so let's pass the old data from
PetItem
to our modal using props. - In our update modal get those props to create an inital value for our state, also add an id value because we already have one. but how to display them in our fields? hint: use the
value
property. - In our mobx store create an
update
method thats takes an arguemnt and replaces the old pet with the new data coming with the sameid
. - In
PetUpdateModal
call this new method in thehandleSubmit
function.