src\routes.js

mail@pastecode.io avatar
unknown
typescript
6 days ago
4.6 kB
1
Indexable
Never
import { lazy } from 'react'
import { PATH } from '@Constants'
import { Redirect } from 'react-router-dom'

import { ECORAIL_TIER } from '@Constants'
import DetailedTripReview from '@Screens/detailedTripReview/DetailedTripReview'
const DefaultDashboard = lazy(() => import('@Screens/dashboard/DefaultDashboard'))
const PremiumDailyMetrics = lazy(() => import('@Screens/dailyMetrics/PremiumDailyMetrics'))
const DefaultTrendingMetrics = lazy(() => import('@Screens/trendingMetrics/DefaultTrendingMetrics'))
const DefaultAggregateMetrics = lazy(() => import('@Screens/aggregateMetrics/DefaultAggregateMetrics'))
const Infractions = lazy(() => import('@Screens/infractions/Infractions'))
const Report = lazy(() => import('@Screens/report/Report'))
const TripReview = lazy(() => import('@Screens/tripReview/TripReview'))
const Settings = lazy(() => import('@Screens/settings/Settings'))
const Page404 = lazy(() => import('@Screens/page404/Page404'))
const DefaultAdmin = lazy(() => import('@Screens/admin/DefaultAdmin'))
const UserSettings = lazy(() => import('@Screens/admin/userSettings/UserSettings'))
const AddUsers = lazy(() => import('@Screens/admin/addUsers/AddUsers'))
const LiveTrain = lazy(() => import('@Screens/liveTrainView/LiveTrainView'))
const SpeedLimit = lazy(() =>  import('@Screens/speedLimit/SpeedLimit'))

const ADMIN_PRO_ROUTES = [
  { path: PATH.DASHBOARD, exact: true, name: 'Dashboard', component: DefaultDashboard },
  { path: PATH.DAILY_METRICS, name: 'DailyMetrics', component: PremiumDailyMetrics },
  { path: PATH.TRENDING_METRICS, name: 'TrendingMetrics', component: DefaultTrendingMetrics },
  { path: PATH.INFRACTIONS, name: 'Infractions', component: Infractions },
  { path: PATH.REPORT, name: 'Report', component: Report },
  { path: PATH.DETAILED_TRIP_REVIEW, name: 'DetailedTripReview', component: DetailedTripReview},
  { path: PATH.SETTINGS, name: 'Settings', component: Settings },
  { path: PATH.NOT_FOUND, name: '404', component: Page404 }
]


const BASE_MODE_ROUTES = [
  { path: PATH.DASHBOARD, exact: true, name: 'Dashboard', component: () => <Redirect to={'/live-train'}/> },
  { path: PATH.LIVE_TRAIN_VIEW, exact: true, name: 'LiveTrain', component: LiveTrain },
  { path: PATH.SPEED_LIMIT ,exact: true, name:'SpeedLimit' , component: SpeedLimit },
  { path: PATH.NOT_FOUND, name: '404', component: () => <Redirect to={'/'}/> },
]


const TRIP_MODE_ROUTES = [
  { path: PATH.DASHBOARD, exact: true, name: 'Dashboard', component: () => <Redirect to={'/trip-review'}/> },
  { path: PATH.LIVE_TRAIN_VIEW, exact: true, name: 'LiveTrain', component: LiveTrain },
  { path: PATH.TRIP_REVIEW, exact: true, name: 'TripReview', component: TripReview },
  { path: PATH.DETAILED_TRIP_REVIEW, name: 'DetailedTripReview', component: DetailedTripReview},
  { path: PATH.ADMIN, exact: true, name: 'Admin', component: DefaultAdmin },
  { path: PATH.USER_SETTING, exact: true, name: 'UserSettings', component: UserSettings },
  { path: PATH.ADD_USERS, exact: true, name: 'AddUsers', component: AddUsers },
  { path: PATH.SPEED_LIMIT ,exact: true, name:'SpeedLimit' , component: SpeedLimit },
  { path: PATH.NOT_FOUND, name: '404', component: () => <Redirect to={'/'}/> },
]

const FUEL_SAVING_MODE_ROUTES = [
  { path: PATH.DASHBOARD, exact: true, name: 'Dashboard', component: () => <Redirect to={'/trip-review'}/> },
  { path: PATH.LIVE_TRAIN_VIEW, exact: true, name: 'LiveTrain', component: LiveTrain },
  { path: PATH.TRIP_REVIEW, exact: true, name: 'TripReview', component: TripReview },
  { path: PATH.AGGREGATE_METRICS, exact: true, name: 'AggregateMetrics', component: DefaultAggregateMetrics },
  { path: PATH.DETAILED_TRIP_REVIEW, name: 'DetailedTripReview', component: DetailedTripReview},
  { path: PATH.ADMIN, exact: true, name: 'Admin', component: DefaultAdmin },
  { path: PATH.USER_SETTING, exact: true, name: 'UserSettings', component: UserSettings },
  { path: PATH.ADD_USERS, exact: true, name: 'AddUsers', component: AddUsers },
  { path: PATH.SPEED_LIMIT ,exact: true, name:'SpeedLimit' , component: SpeedLimit },
  { path: PATH.NOT_FOUND, name: '404', component: () => <Redirect to={'/'}/> },
]

const getRoutes = (railroadId, tier) => {
  if (railroadId?.toUpperCase().includes('MLNX')) {
    return ADMIN_PRO_ROUTES
  } else {
    if(tier === ECORAIL_TIER.BASE_MODE){
      return BASE_MODE_ROUTES
    }
    else if (tier === ECORAIL_TIER.TRIP_MODE) {
      return TRIP_MODE_ROUTES
    } else if (tier === ECORAIL_TIER.FUEL_SAVINGS_MODE) {
      return FUEL_SAVING_MODE_ROUTES
    }
  }
}

export default getRoutes
Leave a Comment