@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
80 lines (78 loc) • 3.57 kB
JavaScript
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { createReducer } from '@reduxjs/toolkit';
import { fetchSystemVersionComplete } from '../actions/env';
import { setSiteSocketStatus, storeInitialized } from '../actions/system';
export const envInitialState = ((origin) => {
var _a, _b, _c, _d, _e, _f, _g, _h;
return {
authoringBase: (_a = process.env.REACT_APP_AUTHORING_BASE) !== null && _a !== void 0 ? _a : `${origin}/studio`,
logoutUrl: process.env.REACT_APP_AUTHORING_BASE
? `${process.env.REACT_APP_AUTHORING_BASE}/logout`
: `${origin}/studio/logout`,
guestBase: (_b = process.env.REACT_APP_GUEST_BASE) !== null && _b !== void 0 ? _b : origin,
xsrfHeader:
(_d = (_c = document.querySelector('#xsrfHeader')) === null || _c === void 0 ? void 0 : _c.textContent) !==
null && _d !== void 0
? _d
: 'X-XSRF-TOKEN',
xsrfArgument:
(_f = (_e = document.querySelector('#xsrfArgument')) === null || _e === void 0 ? void 0 : _e.textContent) !==
null && _f !== void 0
? _f
: '_csrf',
useBaseDomain:
((_g = document.querySelector('#useBaseDomain')) === null || _g === void 0 ? void 0 : _g.textContent) === 'true',
siteCookieName: 'crafterSite',
previewLandingBase:
(_h = process.env.REACT_APP_PREVIEW_LANDING) !== null && _h !== void 0 ? _h : `${origin}/studio/preview-landing`,
version: null,
packageBuild: null,
packageVersion: null,
packageBuildDate: null,
activeEnvironment: null,
socketConnected: false
};
})(window.location.origin);
const reducer = createReducer(envInitialState, {
[fetchSystemVersionComplete.type]: (state, { payload }) =>
Object.assign(Object.assign({}, state), {
version: payload.packageVersion.replace('-SNAPSHOT', ''),
packageBuild: payload.packageBuild,
packageVersion: payload.packageVersion,
packageBuildDate: payload.packageBuildDate
}),
[storeInitialized.type]: (state, { payload }) =>
Object.assign(Object.assign({}, state), { activeEnvironment: payload.activeEnvironment }),
[setSiteSocketStatus.type]: (state, { payload }) =>
Object.assign(Object.assign({}, state), { socketConnected: payload.connected })
});
export default reducer;