Blame view
imports/client/app/routes.js
3.7 KB
c42d4eeac
|
1 |
/* eslint-disable max-len */ |
b48d5cb1c
|
2 3 4 5 6 |
import React from 'react'; import { render } from 'react-dom'; import { Router, Route, IndexRoute, browserHistory } from 'react-router'; import { Meteor } from 'meteor/meteor'; |
48c0461d6
|
7 8 9 10 |
/** * General Components */ |
b48d5cb1c
|
11 |
import Index from '/imports/client/views/app/module/Index'; |
48c0461d6
|
12 13 14 15 |
/** * Org Components */ |
c4d3e07d0
|
16 |
import { App } from '/imports/client/layouts/OrgApp'; |
39d8f536d
|
17 |
import { AppModule } from '/imports/client/views/org/app/module/Index'; |
b48d5cb1c
|
18 |
import { Orgs } from '/imports/collections/orgs/index'; |
13ef5ba8c
|
19 |
import { importCsvController } from '/imports/client/views/org/importCsv/index' |
39d8f536d
|
20 |
import NotFound from '/imports/client/views/org/NotFound'; |
6be49625f
|
21 |
|
48c0461d6
|
22 23 24 |
/** * NonOrg Components */ |
b48d5cb1c
|
25 |
import Signup from '/imports/client/views/nonOrg/enter/SignupView'; |
48c0461d6
|
26 27 28 29 |
/** * Invalid Org Components */ |
4c9b3dfc1
|
30 |
const authenticate = (nextState, replace) => { |
cac7cbc73
|
31 |
if (!Meteor.loggingIn() && !Meteor.userId()) { |
2b1ad7917
|
32 33 |
replace({ pathname: '/login', |
cac7cbc73
|
34 |
state: { nextPathname: nextState.location.pathname }, |
2b1ad7917
|
35 36 37 |
}); } }; |
cc8fd8a94
|
38 |
|
48c0461d6
|
39 |
const detectOrg = () => { |
6be49625f
|
40 |
orgSlug = ""; |
ff976df49
|
41 42 43 |
var hostnameArray = document.location.hostname.split( "." ); if(hostnameArray[1]=='localhost'){ orgSlug = hostnameArray[0]; |
6be49625f
|
44 45 46 |
} if(orgSlug!=""){ Meteor.call('checkExistingOrg', {slug:orgSlug}, function(err, res) { |
cc8fd8a94
|
47 |
if(res){ |
b7054c9b2
|
48 |
Session.set('orgId', res._id); |
c4d3e07d0
|
49 |
Session.set('orgSlug', orgSlug); |
48c0461d6
|
50 |
render(getOrgRoutes(),document.getElementById('app')); |
6be49625f
|
51 |
}else{ |
48c0461d6
|
52 |
render(getInvalidOrgRoute(),document.getElementById('app')); |
6be49625f
|
53 54 |
} }); |
ff976df49
|
55 |
}else{ |
48c0461d6
|
56 |
render(getNonOrgRoutes(),document.getElementById('app')); |
ff976df49
|
57 |
} |
ff976df49
|
58 |
} |
6be49625f
|
59 60 |
const checkSlug = (nextState, replace) => { orgId = Session.get('orgId'); |
6be49625f
|
61 |
} |
cc8fd8a94
|
62 63 64 65 66 67 68 |
/** 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 **/ |
6be49625f
|
69 70 71 |
const getOrgRoutes = () => ( <Router history={ browserHistory }> <Route path="/" component={ App }> |
39d8f536d
|
72 |
<IndexRoute name="index" component={ AppModule } /> |
13ef5ba8c
|
73 |
<Route name="import" path="/import" component={ importCsvController } /> |
6be49625f
|
74 75 76 77 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
cc8fd8a94
|
78 |
|
b48d5cb1c
|
79 |
|
cc8fd8a94
|
80 |
const getInvalidOrgRoute = () => ( |
6be49625f
|
81 82 |
<Router history={ browserHistory }> <Route path="/" component={ App }> |
cc8fd8a94
|
83 |
<IndexRoute name="index" component={ NotFound } /> |
6be49625f
|
84 85 86 87 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
ff976df49
|
88 |
|
cc8fd8a94
|
89 |
const getNonOrgRoutes = () => ( |
6be49625f
|
90 91 |
<Router history={ browserHistory }> <Route path="/" component={ App }> |
39d8f536d
|
92 |
<IndexRoute name="index" component={ Index } /> |
cc8fd8a94
|
93 |
<Route name="signup" path="/signup" component={ Signup } /> |
6be49625f
|
94 95 96 97 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
2b1ad7917
|
98 |
|
27ed00b55
|
99 |
|
6be49625f
|
100 101 |
Meteor.startup(() => { detectOrg(); |
2b1ad7917
|
102 |
}); |