{"size": 762, "ext": "js", "max_stars_repo_path": "src/components/view/functions/DeleteEntity.js", "max_stars_repo_name": "umayangag/GIG-Client", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/view/functions/DeleteEntity.js", "max_issues_repo_name": "umayangag/GIG-Client", "max_issues_repo_issues_event_min_datetime": "2022-03-15T17:29:24.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T17:29:24.000Z", "max_forks_repo_path": "src/components/view/functions/DeleteEntity.js", "max_forks_repo_name": "umayangag/GIG-Client", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 27.2142857143, "max_line_length": 83, "alphanum_fraction": 0.5695538058}
import {ApiRoutes, getServerUrl} from "../../../server";

export function deleteEntity(entity, navigate) {
  let isConfirmed = window.confirm("Are you sure you want to delete this entity?");
  if (isConfirmed) {
    let deleteUrl = getServerUrl(ApiRoutes.delete);
    const requestOptions = {
      headers: this.props.getHeaders(),
      method: 'POST',
      body: JSON.stringify({title: entity.title})
    };
    fetch(deleteUrl, requestOptions).then(results => {
      return results.json();
    }, error => {
      alert("error connecting to server");
    }).then(data => {
      if (data) {
        if (data.status === 200) {
          navigate('/');
        }
        else {
          alert("login error! " + data.status);
        }
      }
    });
  }
}
