App.js 5.4 KB
import React, { Component } from 'react';

import Modal from './components/Modal/Modal'

import Profilation from './components/Profilation'
import Activation from './components/Activation'
import ActivationStep from './components/Activation/ActivationStep'
import MobileUpload from './components/Activation/MobileUpload'
import MobileUploadComplete from './components/Activation/MobileUploadComplete'
import ActivationStep5 from './components/Activation/steps/ActivationStep5'
import ActivationCheck from './components/Activation/steps/ActivationCheck'

import ExpiredSolution from './components/Solution/ExpiredSolution'

import Solution from './components/Solution'

import Loader from './components/Loader'

import MobileConnect from './components/MobileConnect'

import { Provider } from 'react-redux';
import  ProfilationSelectReducer  from './components/reducers/profilationSelect';


import { createStore, combineReducers, applyMiddleware, compose } from 'redux'

import createHistory from 'history/createBrowserHistory'
import Route from 'react-router-dom/Route';
import * as storage from 'redux-storage'

import './styles/style.css'

import { ConnectedRouter, routerReducer, routerMiddleware } from 'react-router-redux'
import createEngine from 'redux-storage-engine-localstorage';

import Header from "./components/header/index";
import Footer from "./components/Footer/index";

import { observer, observe } from 'redux-observers'
import {dataBucketsProfilationObserver, 
        dataBucketPrivacyObserver, 
        dataBucketContactObserver } from './service/dataBucketObservers.js';

import LemaApi from "./service/service.js";
import {ContactModals} from "./components/structures/ContactsModalStructure";
import {ToastContainer} from 'react-toastify';
import { style } from "react-toastify";

// Style for Toaster
style({
    width: "480px",
    colorDefault: "#fff",
    colorInfo: "#3498db",
    colorSuccess: "#07bc0c",
    colorWarning: "#f1c40f",
    colorError: "#e74c3c",
    fontFamily: "sans-serif"    
});


//const history = createHistory();

// If APP installed in a subdirectory 
const history = createHistory({
    basename: '/Home/Profilation/'
});

const engine = createEngine('pro');
const middlewareRouter = routerMiddleware(history)
const middleware = storage.createMiddleware(engine);
const reducer = storage.reducer(combineReducers({
  ProfilationSelectReducer: ProfilationSelectReducer,
  router: routerReducer
}));



const store = createStore(
  reducer,
  compose(applyMiddleware(middlewareRouter), applyMiddleware(middleware))
)

const load = storage.createLoader(engine);
load(store);

load(store)
    .then((newState) => console.log('Loaded state:', newState))
    .catch(() => console.log('Failed to load previous state'));

// Imposto gli observers sullo store
observe(store, [dataBucketsProfilationObserver, dataBucketPrivacyObserver, dataBucketContactObserver])

  
class App extends Component {    
    constructor() {
        super();
    }

    componentDidMount() {                
         // Servizio per interazione con il server
        var lemaApi = new LemaApi();
        var contactsModal = new ContactModals();        
        localStorage.setItem("ContactsModel", "[]");
    }


  render() {

   return (
    <Provider store={store}>

      <div className="repower-app" id='wrap' >
        <ToastContainer hideProgressBar={true} className="ToastContainer"/>         
          <ConnectedRouter history={history} >
      <div className={history.location.pathname.substring(1)+'__main-wrapper'}>

       <Header history={history} pathname={history.location.pathname}/>
      <Modal history={history}/>

      <Route exact path="/" 
          render={(props) => <Profilation {...props}
          updatePropValue={this.props.updatePropValue} 
          history={history} />        
        }/>

        {/* <Route exact path="/" 
            component={Profilation} 
            updatePropValue={this.props.updatePropValue} 
            history={history}         
        /> */}
         <Route path="/loader" render={()=><Loader 
                    goTo={'/solution'}
                    history={history} 
                    heading={'Ci siamo quasi'}
                    subHeading={'Stiamo costruendo la soluzione più adatta, basandoci sulle tue abitudini di consumo.'}/>}/>
        <Route exact path="/solution" history={history} component={Solution}/>
        <Route exact path="/expired-solution" history={history} component={ExpiredSolution}/>
        <Route exact path="/activation" component={Activation}/>
        <Route exact path="/activation-steps" component={ActivationStep}/>
        <Route exact path="/activation-step-5" component={ActivationStep5}/>
        <Route exact path="/activation-check" component={ActivationCheck}/>
        <Route exact path="/mobile-connect" component={MobileConnect}/>
        <Route exact path="/mobile-upload" component={MobileUpload}/>
        <Route path="/mobile-upload-loader" render={()=><Loader
            goTo={'/mobile-upload-complete'}
                    history={history} 
                    heading={'Caricamento documenti in corso...'}
                    subHeading={''}
                    className={'mobile-upload-loader'}
                    hideProgressbar={true}
                    />}/>
        <Route exact path="/mobile-upload-complete" component={MobileUploadComplete}/>
        <Footer/>
      </div>
    </ConnectedRouter>

    

      </div>
      </Provider>


    );
  }
}

export default App;