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

actions.js 1.9KB

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