2020-05-22 06:36:24 +00:00
|
|
|
import { doGetJSON } from '../base/util';
|
|
|
|
|
2020-09-16 10:44:49 +00:00
|
|
|
import {
|
|
|
|
SET_DYNAMIC_BRANDING_DATA,
|
|
|
|
SET_DYNAMIC_BRANDING_FAILED,
|
|
|
|
SET_DYNAMIC_BRANDING_READY
|
|
|
|
} from './actionTypes';
|
2021-11-16 21:16:18 +00:00
|
|
|
import { getDynamicBrandingUrl } from './functions.any';
|
2022-05-23 15:02:14 +00:00
|
|
|
import logger from './logger';
|
2020-05-22 06:36:24 +00:00
|
|
|
|
2020-12-11 10:16:58 +00:00
|
|
|
|
2020-05-22 06:36:24 +00:00
|
|
|
/**
|
|
|
|
* Fetches custom branding data.
|
|
|
|
* If there is no data or the request fails, sets the `customizationReady` flag
|
|
|
|
* so the defaults can be displayed.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function fetchCustomBrandingData() {
|
|
|
|
return async function(dispatch: Function, getState: Function) {
|
|
|
|
const state = getState();
|
|
|
|
const { customizationReady } = state['features/dynamic-branding'];
|
|
|
|
|
|
|
|
if (!customizationReady) {
|
2021-10-07 06:42:57 +00:00
|
|
|
const url = await getDynamicBrandingUrl();
|
2020-05-22 06:36:24 +00:00
|
|
|
|
2020-12-11 10:16:58 +00:00
|
|
|
if (url) {
|
2020-05-22 06:36:24 +00:00
|
|
|
try {
|
2020-12-11 10:16:58 +00:00
|
|
|
const res = await doGetJSON(url);
|
2020-05-22 06:36:24 +00:00
|
|
|
|
|
|
|
return dispatch(setDynamicBrandingData(res));
|
|
|
|
} catch (err) {
|
|
|
|
logger.error('Error fetching branding data', err);
|
2020-09-16 10:44:49 +00:00
|
|
|
|
|
|
|
return dispatch(setDynamicBrandingFailed());
|
2020-05-22 06:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(setDynamicBrandingReady());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action used to set the user customizations.
|
|
|
|
*
|
|
|
|
* @param {Object} value - The custom data to be set.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-05-23 15:02:14 +00:00
|
|
|
export function setDynamicBrandingData(value) {
|
2020-05-22 06:36:24 +00:00
|
|
|
return {
|
|
|
|
type: SET_DYNAMIC_BRANDING_DATA,
|
|
|
|
value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action used to signal the branding elements are ready to be displayed.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-05-23 15:02:14 +00:00
|
|
|
export function setDynamicBrandingReady() {
|
2020-05-22 06:36:24 +00:00
|
|
|
return {
|
|
|
|
type: SET_DYNAMIC_BRANDING_READY
|
|
|
|
};
|
|
|
|
}
|
2020-09-16 10:44:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Action used to signal the branding request failed.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-05-23 15:02:14 +00:00
|
|
|
export function setDynamicBrandingFailed() {
|
2020-09-16 10:44:49 +00:00
|
|
|
return {
|
|
|
|
type: SET_DYNAMIC_BRANDING_FAILED
|
|
|
|
};
|
|
|
|
}
|