Advertisement
Guest User

Routes

a guest
Aug 18th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Updates the RouteStore with static routes.
  3.  */
  4. export function setStaticRoutes ({state, apiClient}: AppContextProps) {
  5.   state.routes.setRoot(() => ({
  6.     // Require locale url prefix
  7.     path: `:locale<${localeRegexString}>`,
  8.     populate: () => state.i18n.availableLocales,
  9.  
  10.     // Always render the Layout
  11.     component: Layout,
  12.  
  13.     children: [
  14.       // Public routes are available on ocast.com
  15.       state.origin.isPublic && {
  16.         children: [
  17.           {component: PublicLanding},
  18.           {path: 'pricing', component: PublicPricing, layout: () => RouteLayout.Top},
  19.           {path: 'browse', ...createBrowseRoute(state, apiClient), layout: () => RouteLayout.Top},
  20.           ...createUserAccountRoutes(state)
  21.         ]
  22.       },
  23.  
  24.       // Whitelabel routes are available via ad portal
  25.       state.origin.isPortal && {
  26.         ...(() => {
  27.           // Use the media kit color and logo
  28.           const resource = apiClient.getMediaKits({ad_portal_host: state.origin.hostname});
  29.           const kit = resource.value.data && resource.value.data[0];
  30.           return {
  31.             layoutBackColor: kit && kit.color,
  32.             layoutLogoUrl: kit && kit.logoUrl
  33.           };
  34.         })(),
  35.         children: [
  36.           ...createUserAccountRoutes(state, false),
  37.           createMediaKitRoute(false, state, apiClient)
  38.         ]
  39.       },
  40.  
  41.       // Dashboard routes are always available
  42.       {
  43.         ...requireAuth(state),
  44.         path: 'dashboard',
  45.         component: DashboardBehavior,
  46.         layout: () => RouteLayout.Menu,
  47.         children: [
  48.           {component: DashboardOverview},
  49.           {path: 'browse', ...createBrowseRoute(state, apiClient)},
  50.           {path: 'mediakits', ...createBrowseRoute(state, apiClient, {create: true})},
  51.           {path: 'preferences', component: OrganisationPreferences},
  52.           {path: 'team', component: OrganisationTeam},
  53.           {path: 'billing', component: () => <span>Billing</span>}
  54.         ]
  55.       },
  56.  
  57.       // Library routes are always available
  58.       {
  59.         ...requireAuth(state),
  60.         path: 'library',
  61.         children: [
  62.           {path: 'organisation', children: [
  63.             {path: 'roles', component: OrganisationRoles},
  64.             {path: 'members', children: [
  65.               {component: OrganisationMembers},
  66.               {path: 'invite', component: InviteFindUser},
  67.               {path: 'invite/new', component: InviteNewUser},
  68.               {path: 'invite/send', component: InviteSend},
  69.               {path: 'changeRole/:userId', component: OrganisationChangeRole}
  70.             ]},
  71.           ]}
  72.         ]
  73.       },
  74.  
  75.       // Development routes
  76.       buildOptions.devTools && {
  77.         path: 'dev',
  78.         layout: () => RouteLayout.Menu,
  79.         children: [
  80.           {component: DevTools},
  81.           {path: 'theme', component: DevTheme},
  82.           {path: 'typography', component: DevTypography},
  83.           {path: 'sitemap', component: DevSitemap},
  84.           {path: 'i18n', component: DevI18n},
  85.           {path: 'overflow', component: DevOverflow},
  86.           {path: 'appState', component: DevAppState},
  87.           {
  88.             path: 'ui-components',
  89.             pathToFirstChild: true,
  90.             children: componentDemos.map((demo) => ({
  91.               path: demo.name,
  92.               label: demo.name,
  93.               component: () => <Page>{demo.render()}</Page>
  94.             }))
  95.           }
  96.         ]
  97.       }
  98.     ]
  99.   }));
  100.  
  101.   state.routes.setFallback({
  102.     meta: {index: false},
  103.     component: PublicNotFound
  104.   });
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement