You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // @flow
  2. import uuid from 'uuid';
  3. import { SET_BILLING_ID } from './actionTypes';
  4. import { extractVpaasTenantFromPath, getBillingId, sendCountRequest } from './functions';
  5. /**
  6. * Sends a billing count request when needed.
  7. * If there is no billingId, it presists one first and sends the request after.
  8. *
  9. * @returns {Function}
  10. */
  11. export function countEndpoint() {
  12. return function(dispatch: Function, getState: Function) {
  13. const state = getState();
  14. const baseUrl = state['features/base/config'].billingCounterUrl;
  15. const jwt = state['features/base/jwt'].jwt;
  16. const tenant = extractVpaasTenantFromPath(state['features/base/connection'].locationURL.pathname);
  17. const shouldSendRequest = Boolean(baseUrl && jwt && tenant);
  18. if (shouldSendRequest) {
  19. let billingId = getBillingId();
  20. if (!billingId) {
  21. billingId = uuid.v4();
  22. dispatch(setBillingId(billingId));
  23. }
  24. sendCountRequest({
  25. baseUrl,
  26. billingId,
  27. jwt,
  28. tenant
  29. });
  30. }
  31. };
  32. }
  33. /**
  34. * Action used to set the user billing id.
  35. *
  36. * @param {string} value - The uid.
  37. * @returns {Object}
  38. */
  39. function setBillingId(value) {
  40. return {
  41. type: SET_BILLING_ID,
  42. value
  43. };
  44. }