您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // @flow
  2. import uuid from 'uuid';
  3. import { SET_BILLING_ID, SET_ENDPOINT_COUNTED } 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. dispatch(setEndpointCounted());
  31. }
  32. };
  33. }
  34. /**
  35. * Action used to set the user billing id.
  36. *
  37. * @param {string} value - The uid.
  38. * @returns {Object}
  39. */
  40. function setBillingId(value) {
  41. return {
  42. type: SET_BILLING_ID,
  43. value
  44. };
  45. }
  46. /**
  47. * Action used to mark the endpoint as counted.
  48. *
  49. * @returns {Object}
  50. */
  51. function setEndpointCounted() {
  52. return {
  53. type: SET_ENDPOINT_COUNTED
  54. };
  55. }