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.any.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // @flow
  2. import { SET_DETAILS } from './actionTypes';
  3. import { getVpaasTenant, sendGetDetailsRequest } from './functions';
  4. import logger from './logger';
  5. /**
  6. * Action used to set the jaas customer details in store.
  7. *
  8. * @param {Object} details - The customer details object.
  9. * @returns {Object}
  10. */
  11. function setCustomerDetails(details) {
  12. return {
  13. type: SET_DETAILS,
  14. payload: details
  15. };
  16. }
  17. /**
  18. * Sends a request for retrieving jaas customer details.
  19. *
  20. * @returns {Function}
  21. */
  22. export function getCustomerDetails() {
  23. return async function(dispatch: Function, getState: Function) {
  24. const state = getState();
  25. const baseUrl = state['features/base/config'].jaasActuatorUrl || 'https://api-vo-pilot.jitsi.net/jaas-actuator';
  26. const appId = getVpaasTenant(state);
  27. const shouldSendRequest = Boolean(baseUrl && appId);
  28. if (shouldSendRequest) {
  29. try {
  30. const details = await sendGetDetailsRequest({
  31. appId,
  32. baseUrl
  33. });
  34. dispatch(setCustomerDetails(details));
  35. } catch (err) {
  36. logger.error('Could not send request', err);
  37. }
  38. }
  39. };
  40. }