| 
									
										
										
										
											2019-04-11 19:07:00 +02:00
										 |  |  | // /**
 | 
					
						
							|  |  |  | //  *
 | 
					
						
							|  |  |  | //  * app.js
 | 
					
						
							|  |  |  | //  *
 | 
					
						
							|  |  |  | //  * Entry point of the application
 | 
					
						
							|  |  |  | //  */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import '@babel/polyfill'; | 
					
						
							| 
									
										
										
										
											2017-08-18 14:17:15 +02:00
										 |  |  | import 'sanitize.css/sanitize.css'; | 
					
						
							| 
									
										
										
										
											2019-04-11 19:07:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import React from 'react'; | 
					
						
							|  |  |  | import ReactDOM from 'react-dom'; | 
					
						
							|  |  |  | import { Provider } from 'react-redux'; | 
					
						
							| 
									
										
										
										
											2019-04-16 11:53:29 +02:00
										 |  |  | import { BrowserRouter } from 'react-router-dom'; | 
					
						
							|  |  |  | // import { ConnectedRouter } from 'react-router-redux';
 | 
					
						
							|  |  |  | import basename from './utils/basename'; | 
					
						
							| 
									
										
										
										
											2019-04-11 19:07:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { merge } from 'lodash'; | 
					
						
							| 
									
										
										
										
											2018-01-17 12:58:14 +01:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2019-04-11 19:07:00 +02:00
										 |  |  |   freezeApp, | 
					
						
							|  |  |  |   pluginLoaded, | 
					
						
							|  |  |  |   unfreezeApp, | 
					
						
							|  |  |  |   updatePlugin, | 
					
						
							| 
									
										
										
										
											2019-04-12 18:23:26 +02:00
										 |  |  |   getAppPluginsSucceeded, | 
					
						
							|  |  |  |   // unsetHasUserPlugin,
 | 
					
						
							| 
									
										
										
										
											2019-02-22 10:05:07 +01:00
										 |  |  | } from './containers/App/actions'; | 
					
						
							| 
									
										
										
										
											2019-04-11 19:07:00 +02:00
										 |  |  | import { showNotification } from './containers/NotificationProvider/actions'; | 
					
						
							|  |  |  | import injectReducer from './utils/injectReducer'; | 
					
						
							|  |  |  | import injectSaga from './utils/injectSaga'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Import root component
 | 
					
						
							|  |  |  | import App from './containers/App'; | 
					
						
							|  |  |  | // Import Language provider
 | 
					
						
							|  |  |  | import LanguageProvider from './containers/LanguageProvider'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import configureStore from './configureStore'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Import i18n messages
 | 
					
						
							|  |  |  | import { translationMessages, languages } from './i18n'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Create redux store with history
 | 
					
						
							|  |  |  | import history from './utils/history'; | 
					
						
							|  |  |  | const initialState = {}; | 
					
						
							|  |  |  | const store = configureStore(initialState, history); | 
					
						
							|  |  |  | const { dispatch } = store; | 
					
						
							|  |  |  | const MOUNT_NODE = document.getElementById('app'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-12 18:23:26 +02:00
										 |  |  | // TODO remove temporary to access the admin
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | dispatch(getAppPluginsSucceeded([])); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 19:07:00 +02:00
										 |  |  | // TODO
 | 
					
						
							|  |  |  | const remoteURL = (() => { | 
					
						
							|  |  |  |   if (window.location.port === '4000') { | 
					
						
							|  |  |  |     return 'http://localhost:4000/admin'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Relative URL (ex: /dashboard)
 | 
					
						
							|  |  |  |   if (process.env.REMOTE_URL[0] === '/') { | 
					
						
							|  |  |  |     return (window.location.origin + process.env.REMOTE_URL).replace(/\/$/, ''); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return process.env.REMOTE_URL.replace(/\/$/, ''); | 
					
						
							|  |  |  | })(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const registerPlugin = plugin => { | 
					
						
							|  |  |  |   // Merge admin translation messages
 | 
					
						
							|  |  |  |   merge(translationMessages, plugin.translationMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   plugin.leftMenuSections = plugin.leftMenuSections || []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   dispatch(pluginLoaded(plugin)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | const displayNotification = (message, status) => { | 
					
						
							|  |  |  |   dispatch(showNotification(message, status)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | const lockApp = data => { | 
					
						
							|  |  |  |   dispatch(freezeApp(data)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | const unlockApp = () => { | 
					
						
							|  |  |  |   dispatch(unfreezeApp()); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | window.strapi = Object.assign(window.strapi || {}, { | 
					
						
							|  |  |  |   node: MODE || 'host', | 
					
						
							|  |  |  |   remoteURL, | 
					
						
							|  |  |  |   backendURL: BACKEND_URL, | 
					
						
							|  |  |  |   registerPlugin, | 
					
						
							|  |  |  |   notification: { | 
					
						
							|  |  |  |     success: message => { | 
					
						
							|  |  |  |       displayNotification(message, 'success'); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     warning: message => { | 
					
						
							|  |  |  |       displayNotification(message, 'warning'); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     error: message => { | 
					
						
							|  |  |  |       displayNotification(message, 'error'); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     info: message => { | 
					
						
							|  |  |  |       displayNotification(message, 'info'); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   refresh: pluginId => ({ | 
					
						
							|  |  |  |     translationMessages: translationMessagesUpdated => { | 
					
						
							|  |  |  |       render(merge({}, translationMessages, translationMessagesUpdated)); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     leftMenuSections: leftMenuSectionsUpdated => { | 
					
						
							|  |  |  |       store.dispatch( | 
					
						
							|  |  |  |         updatePlugin(pluginId, 'leftMenuSections', leftMenuSectionsUpdated), | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }), | 
					
						
							|  |  |  |   router: history, | 
					
						
							|  |  |  |   languages, | 
					
						
							|  |  |  |   currentLanguage: | 
					
						
							|  |  |  |     window.localStorage.getItem('strapi-admin-language') || | 
					
						
							|  |  |  |     window.navigator.language || | 
					
						
							|  |  |  |     window.navigator.userLanguage || | 
					
						
							|  |  |  |     'en', | 
					
						
							|  |  |  |   lockApp, | 
					
						
							|  |  |  |   unlockApp, | 
					
						
							|  |  |  |   injectReducer, | 
					
						
							|  |  |  |   injectSaga, | 
					
						
							|  |  |  |   store, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const render = messages => { | 
					
						
							|  |  |  |   ReactDOM.render( | 
					
						
							|  |  |  |     <Provider store={store}> | 
					
						
							|  |  |  |       <LanguageProvider messages={messages}> | 
					
						
							| 
									
										
										
										
											2019-04-16 11:53:29 +02:00
										 |  |  |         {/* <ConnectedRouter history={history}> */} | 
					
						
							|  |  |  |         <BrowserRouter basename={basename}> | 
					
						
							| 
									
										
										
										
											2019-04-11 19:07:00 +02:00
										 |  |  |           <App store={store} /> | 
					
						
							| 
									
										
										
										
											2019-04-16 11:53:29 +02:00
										 |  |  |         </BrowserRouter> | 
					
						
							| 
									
										
										
										
											2019-04-11 19:07:00 +02:00
										 |  |  |       </LanguageProvider> | 
					
						
							|  |  |  |     </Provider>, | 
					
						
							|  |  |  |     MOUNT_NODE, | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (module.hot) { | 
					
						
							|  |  |  |   module.hot.accept(['./i18n', './containers/App'], () => { | 
					
						
							|  |  |  |     ReactDOM.unmountComponentAtNode(MOUNT_NODE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     render(translationMessages); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Chunked polyfill for browsers without Intl support
 | 
					
						
							|  |  |  | if (!window.Intl) { | 
					
						
							|  |  |  |   new Promise(resolve => { | 
					
						
							|  |  |  |     resolve(import('intl')); | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |     .then(() => | 
					
						
							|  |  |  |       Promise.all([ | 
					
						
							|  |  |  |         import('intl/locale-data/jsonp/en.js'), | 
					
						
							|  |  |  |         import('intl/locale-data/jsonp/de.js'), | 
					
						
							|  |  |  |       ]), | 
					
						
							|  |  |  |     ) // eslint-disable-line prettier/prettier
 | 
					
						
							|  |  |  |     .then(() => render(translationMessages)) | 
					
						
							| 
									
										
										
										
											2017-11-02 19:36:09 +01:00
										 |  |  |     .catch(err => { | 
					
						
							| 
									
										
										
										
											2019-04-11 19:07:00 +02:00
										 |  |  |       throw err; | 
					
						
							| 
									
										
										
										
											2017-11-02 19:36:09 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-04-11 19:07:00 +02:00
										 |  |  | } else { | 
					
						
							|  |  |  |   render(translationMessages); | 
					
						
							| 
									
										
										
										
											2017-11-02 19:36:09 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-12 18:23:26 +02:00
										 |  |  | // @Pierre Burgy exporting dispatch for the notifications...
 | 
					
						
							| 
									
										
										
										
											2019-04-02 22:45:21 +02:00
										 |  |  | export { dispatch }; | 
					
						
							| 
									
										
										
										
											2019-04-12 18:23:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // TODO remove this for the new Cypress tests
 | 
					
						
							|  |  |  | if (window.Cypress) { | 
					
						
							|  |  |  |   window.__store__ = Object.assign(window.__store__ || {}, { store }); | 
					
						
							|  |  |  | } |