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