/* eslint-disable max-len */
import React from 'react';
import { render } from 'react-dom';
import { Router, Route,
IndexRoute, browserHistory } from 'react-router';
import { Meteor } from 'meteor/meteor';
/**
* General Components
*/
import Index from '/imports/client/views/app/module/Index';
/**
* Org Components
*/
import { App } from '/imports/client/layouts/OrgApp';
import { AppModule } from '/imports/client/views/org/app/module/Index';
import { Orgs } from '/imports/collections/orgs/index';
import { importCsvController } from '/imports/client/views/org/importCsv/index'
//admin
import { StudentDataController } from '/imports/client/views/org/admin/students/index'
import NotFound from '/imports/client/views/org/NotFound';
/**
* NonOrg Components
*/
import Signup from '/imports/client/views/nonOrg/enter/SignupView';
/**
* Invalid Org Components
*/
const authenticate = (nextState, replace) => {
if (!Meteor.loggingIn() && !Meteor.userId()) {
replace({
pathname: '/login',
state: { nextPathname: nextState.location.pathname },
});
}
};
const detectOrg = () => {
orgSlug = "";
var hostnameArray = document.location.hostname.split( "." );
if(hostnameArray[1]=='localhost'){
orgSlug = hostnameArray[0];
}
if(orgSlug!=""){
Meteor.call('checkExistingOrg', {slug:orgSlug}, function(err, res) {
if(res){
Session.set('orgId', res._id);
Session.set('orgSlug', orgSlug);
render(getOrgRoutes(),document.getElementById('app'));
}else{
render(getInvalidOrgRoute(),document.getElementById('app'));
}
});
}else{
render(getNonOrgRoutes(),document.getElementById('app'));
}
}
const checkSlug = (nextState, replace) => {
orgId = Session.get('orgId');
}
/**
There are three types of routes
1)getOrgRoutes: all the routes that should be present for a registered org
2)getInvalidOrgRoute: all the routes where someone tries to enter a subdomain which hasn't been registered yet (404 mostly :D)
3)getNonOrgRoutes: all routes linked to normal site, ie signing up a new org. CHeking out demo and everything internal
**/
const getOrgRoutes = () => (
)
const getInvalidOrgRoute = () => (
)
const getNonOrgRoutes = () => (
)
Meteor.startup(() => {
detectOrg();
});