2022-10-13 08:26:28 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { doGetJSON } from '../base/util/httpUtils';
|
2022-05-23 15:02:14 +00:00
|
|
|
|
|
|
|
import { UNSET_DYNAMIC_BRANDING } from './actionTypes';
|
|
|
|
import {
|
|
|
|
setDynamicBrandingData,
|
|
|
|
setDynamicBrandingFailed,
|
|
|
|
setDynamicBrandingReady
|
|
|
|
} from './actions.any';
|
2022-06-29 14:50:06 +00:00
|
|
|
import { getDynamicBrandingUrl } from './functions.any';
|
2022-05-23 15:02:14 +00:00
|
|
|
import logger from './logger';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
2022-10-13 08:26:28 +00:00
|
|
|
return async function(dispatch: IStore['dispatch'], getState: IStore['getState']) {
|
2022-05-23 15:02:14 +00:00
|
|
|
const state = getState();
|
2022-06-29 14:50:06 +00:00
|
|
|
const dynamicBrandingUrl = await getDynamicBrandingUrl(state);
|
2022-05-23 15:02:14 +00:00
|
|
|
|
|
|
|
if (dynamicBrandingUrl) {
|
|
|
|
try {
|
|
|
|
return dispatch(
|
|
|
|
setDynamicBrandingData(
|
|
|
|
await doGetJSON(dynamicBrandingUrl))
|
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
logger.error('Error fetching branding data', err);
|
|
|
|
|
|
|
|
return dispatch(
|
|
|
|
setDynamicBrandingFailed()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dispatch(unsetDynamicBranding());
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(setDynamicBrandingReady());
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action used to unset branding elements.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function unsetDynamicBranding() {
|
|
|
|
return {
|
|
|
|
type: UNSET_DYNAMIC_BRANDING
|
|
|
|
};
|
|
|
|
}
|