fix: Production warning in admin
parent
7b9b664cdf
commit
14eddc5459
|
@ -6,7 +6,7 @@ import { useNotification } from '@strapi/helper-plugin';
|
|||
import { Alert } from '@strapi/design-system/Alert';
|
||||
import { Typography } from '@strapi/design-system/Typography';
|
||||
|
||||
import { getAllConfigDiff } from '../../state/actions/Config';
|
||||
import { getAllConfigDiff, getAppEnv } from '../../state/actions/Config';
|
||||
import ConfigList from '../../components/ConfigList';
|
||||
import ActionButtons from '../../components/ActionButtons';
|
||||
|
||||
|
@ -15,14 +15,16 @@ const ConfigPage = () => {
|
|||
const dispatch = useDispatch();
|
||||
const isLoading = useSelector((state) => state.getIn(['config', 'isLoading'], Map({})));
|
||||
const configDiff = useSelector((state) => state.getIn(['config', 'configDiff'], Map({})));
|
||||
const appEnv = useSelector((state) => state.getIn(['config', 'appEnv']));
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(getAllConfigDiff(toggleNotification));
|
||||
dispatch(getAppEnv(toggleNotification));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Box paddingLeft={8} paddingRight={8} paddingBottom={8}>
|
||||
{process.env.NODE_ENV === 'production' && (
|
||||
{appEnv === 'production' && (
|
||||
<Box paddingBottom={4}>
|
||||
<Alert variant="danger">
|
||||
<Typography variant="omega" fontWeight="bold">You're in the production environment</Typography><br />
|
||||
|
|
|
@ -30,7 +30,7 @@ const configureStore = () => {
|
|||
const composedEnhancers = devtools || compose;
|
||||
const storeEnhancers = composedEnhancers(
|
||||
applyMiddleware(...middlewares),
|
||||
...enhancers
|
||||
...enhancers,
|
||||
);
|
||||
|
||||
const store = createStore(
|
||||
|
|
|
@ -2,7 +2,7 @@ const pluginPkg = require('../../../package.json');
|
|||
|
||||
const pluginId = pluginPkg.name.replace(
|
||||
/^strapi-plugin-/i,
|
||||
''
|
||||
'',
|
||||
);
|
||||
|
||||
module.exports = pluginId;
|
||||
|
|
|
@ -54,7 +54,7 @@ export default {
|
|||
locale,
|
||||
};
|
||||
});
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
return Promise.resolve(importedTrads);
|
||||
|
|
|
@ -80,3 +80,24 @@ export function setLoadingState(value) {
|
|||
value,
|
||||
};
|
||||
}
|
||||
|
||||
export function getAppEnv(toggleNotification) {
|
||||
return async function(dispatch) {
|
||||
try {
|
||||
const env = await request('/config-sync/app-env', {
|
||||
method: 'GET',
|
||||
});
|
||||
dispatch(setAppEnvInState(env));
|
||||
} catch (err) {
|
||||
toggleNotification({ type: 'warning', message: { id: 'notification.error' } });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const SET_APP_ENV_IN_STATE = 'SET_APP_ENV_IN_STATE';
|
||||
export function setAppEnvInState(value) {
|
||||
return {
|
||||
type: SET_APP_ENV_IN_STATE,
|
||||
value,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,12 +5,18 @@
|
|||
*/
|
||||
|
||||
import { fromJS, Map, List } from 'immutable';
|
||||
import { SET_CONFIG_DIFF_IN_STATE, SET_CONFIG_PARTIAL_DIFF_IN_STATE, SET_LOADING_STATE } from '../../actions/Config';
|
||||
import {
|
||||
SET_CONFIG_DIFF_IN_STATE,
|
||||
SET_CONFIG_PARTIAL_DIFF_IN_STATE,
|
||||
SET_LOADING_STATE,
|
||||
SET_APP_ENV_IN_STATE,
|
||||
} from '../../actions/Config';
|
||||
|
||||
const initialState = fromJS({
|
||||
configDiff: Map({}),
|
||||
partialDiff: List([]),
|
||||
isLoading: false,
|
||||
appEnv: 'development',
|
||||
});
|
||||
|
||||
export default function configReducer(state = initialState, action) {
|
||||
|
@ -24,6 +30,9 @@ export default function configReducer(state = initialState, action) {
|
|||
case SET_LOADING_STATE:
|
||||
return state
|
||||
.update('isLoading', () => fromJS(action.value));
|
||||
case SET_APP_ENV_IN_STATE:
|
||||
return state
|
||||
.update('appEnv', () => fromJS(action.value));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -83,4 +83,10 @@ module.exports = {
|
|||
|
||||
return strapi.plugin('config-sync').service('main').getFormattedDiff();
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the current Strapi env.
|
||||
* @returns {string} The current Strapi environment.
|
||||
*/
|
||||
getAppEnv: async () => strapi.server.app.env,
|
||||
};
|
||||
|
|
|
@ -27,5 +27,13 @@ module.exports = {
|
|||
policies: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
method: "GET",
|
||||
path: "/app-env",
|
||||
handler: "config.getAppEnv",
|
||||
config: {
|
||||
policies: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
@ -15,7 +15,7 @@ const sortByKeys = (unordered) => {
|
|||
obj[key] = unordered[key];
|
||||
return obj;
|
||||
},
|
||||
{}
|
||||
{},
|
||||
);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue