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.ts 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { doGetJSON } from '../base/util/httpUtils';
  2. import {
  3. SET_DYNAMIC_BRANDING_DATA,
  4. SET_DYNAMIC_BRANDING_FAILED,
  5. SET_DYNAMIC_BRANDING_READY
  6. } from './actionTypes';
  7. import { getDynamicBrandingUrl } from './functions.any';
  8. import logger from './logger';
  9. /**
  10. * Fetches custom branding data.
  11. * If there is no data or the request fails, sets the `customizationReady` flag
  12. * so the defaults can be displayed.
  13. *
  14. * @returns {Function}
  15. */
  16. export function fetchCustomBrandingData() {
  17. return async function(dispatch: Function, getState: Function) {
  18. const state = getState();
  19. const { customizationReady } = state['features/dynamic-branding'];
  20. if (!customizationReady) {
  21. const url = await getDynamicBrandingUrl(state);
  22. if (url) {
  23. try {
  24. const res = await doGetJSON(url);
  25. return dispatch(setDynamicBrandingData(res));
  26. } catch (err) {
  27. logger.error('Error fetching branding data', err);
  28. return dispatch(setDynamicBrandingFailed());
  29. }
  30. }
  31. dispatch(setDynamicBrandingReady());
  32. }
  33. };
  34. }
  35. /**
  36. * Action used to set the user customizations.
  37. *
  38. * @param {Object} value - The custom data to be set.
  39. * @returns {Object}
  40. */
  41. export function setDynamicBrandingData(value: Object) {
  42. return {
  43. type: SET_DYNAMIC_BRANDING_DATA,
  44. value
  45. };
  46. }
  47. /**
  48. * Action used to signal the branding elements are ready to be displayed.
  49. *
  50. * @returns {Object}
  51. */
  52. export function setDynamicBrandingReady() {
  53. return {
  54. type: SET_DYNAMIC_BRANDING_READY
  55. };
  56. }
  57. /**
  58. * Action used to signal the branding request failed.
  59. *
  60. * @returns {Object}
  61. */
  62. export function setDynamicBrandingFailed() {
  63. return {
  64. type: SET_DYNAMIC_BRANDING_FAILED
  65. };
  66. }