Wanhenri / Projeto-ERP

0 stars 0 forks source link

activate 'DELETE' button #33

Closed Wanhenri closed 4 years ago

Wanhenri commented 4 years ago

in API:

    def delete(self):
        json_data = request.get_json()
        delete_id = str(json_data['id'])
        delete_user_reports = delete_user(delete_id)
        return delete_user_reports

and in APP:

    //DELETE
    const [deletes, setdeletes] = React.useState([]);
    const DeleteData = async (id) => {
      await fetch(`${process.env.REACT_APP_API_URL}/vendor_item`, {
        method: "DELETE",
        headers: {
          "Content-Type": "application/json"
        },
        body: JSON.stringify({
          id
        })
      })
        .then((response) => response.json())
        .then((data) => {
          console.log("DELETE")
          console.log(data)
          setdeletes(data);
        })
        .catch((error) => console.log(error));
    };

    useEffect(() => {
      DeleteData("3", () => {});
    }, []);

How to add delete button in APP?? It is working, but it is deleting the value being passed and not in the 'event click'

Wanhenri commented 4 years ago
                  <Button 
                      style={{marginBottom: 3, backgroundColor: "var(--color-first)" }}
                      onClick={() => {
                        refreshPage();
                        props.onSubmit(row.id)}}                     
                    >DELETE
                    </Button>