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.web.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // @flow
  2. import { openDialog } from '../base/dialog';
  3. import { VPAAS_TENANT_PREFIX } from '../billing-counter/constants';
  4. import { getVpaasTenant } from '../billing-counter/functions';
  5. import { SET_DETAILS } from './actionTypes';
  6. import { PremiumFeatureDialog } from './components';
  7. import { isFeatureDisabled, sendGetDetailsRequest } from './functions';
  8. import logger from './logger';
  9. /**
  10. * Action used to set the jaas customer details in store.
  11. *
  12. * @param {Object} details - The customer details object.
  13. * @returns {Object}
  14. */
  15. function setCustomerDetails(details) {
  16. return {
  17. type: SET_DETAILS,
  18. payload: details
  19. };
  20. }
  21. /**
  22. * Sends a request for retrieving jaas customer details.
  23. *
  24. * @returns {Function}
  25. */
  26. export function getCustomerDetails() {
  27. return async function(dispatch: Function, getState: Function) {
  28. const state = getState();
  29. const baseUrl = state['features/base/config'].jaasActuatorUrl;
  30. const jwt = state['features/base/jwt'].jwt;
  31. const appId = getVpaasTenant(state).replace(VPAAS_TENANT_PREFIX, '');
  32. const shouldSendRequest = Boolean(baseUrl && jwt && appId);
  33. if (shouldSendRequest) {
  34. try {
  35. const details = await sendGetDetailsRequest({
  36. baseUrl,
  37. jwt,
  38. appId
  39. });
  40. dispatch(setCustomerDetails(details));
  41. } catch (err) {
  42. logger.error('Could not send request', err);
  43. }
  44. }
  45. };
  46. }
  47. /**
  48. * Shows a dialog prompting users to upgrade, if requested feature is disabled.
  49. *
  50. * @param {string} feature - The feature to check availability for.
  51. *
  52. * @returns {Function}
  53. */
  54. export function maybeShowPremiumFeatureDialog(feature: string) {
  55. return function(dispatch: Function, getState: Function) {
  56. if (isFeatureDisabled(getState(), feature)) {
  57. dispatch(openDialog(PremiumFeatureDialog));
  58. return true;
  59. }
  60. return false;
  61. };
  62. }