Skip to content

Add New Button and Dialog in the Machine Table

Iryna edited this page Mar 25, 2020 · 2 revisions

Clicking on Add New Button in Machine table opens MachinesSaveNewForm. In this form, the information is gathered in the form and the state element productInEdit is set to a new JSON dataItem variable.

const dataItem = this.state.productInEdit; This Then this variable is stringified and passed into the body of the API request.

fetch('https://ken-fun-feat-usw2-task60.azurewebsites.net/api/v1/machines' , { method: "POST", headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(dataItem), }).then..............

After the request was completed, the this.state.productive it needs to be set to undefined, because the add new machine dialog appears only when the product is in edit state. If the product is in an undefined state, the dialog will disappear.

To find out if the POST request was successful or failed - look in the console for messages, and the table for a new added machine

Clone this wiki locally