summaryrefslogtreecommitdiff
path: root/web-ui/src/common/util.js
blob: c70a84447edab5c8ffcfaedb11181e19b75f50bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import browser from 'helpers/browser';

export const hasQueryParameter = (param) => {
  const decodedUri = decodeURIComponent(window.location.search.substring(1));
  return !(decodedUri.split('&').indexOf(param) < 0);
};

export const submitForm = (event, url, body = {}) => {
  event.preventDefault();

  return fetch(url, {
    credentials: 'same-origin',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      csrftoken: [browser.getCookie('XSRF-TOKEN')],
      ...body
    })
  });
};

export default {
  hasQueryParameter,
  submitForm
};