Fakultas Ilmu Komputer UI

schema.ts 1.23 KB
Newer Older
Wulan Mantiri's avatar
Wulan Mantiri committed
1
2
3
import * as ROUTES from 'constants/routes';
import {
  publicNavigation,
4
  nutritionistNavigation,
5
  adminNavigation,
Wulan Mantiri's avatar
Wulan Mantiri committed
6
  unpaidClientNavigation,
7
  paidClientNavigation,
Wulan Mantiri's avatar
Wulan Mantiri committed
8
} from 'constants/navigation';
9
import { UserRole, AuthUserResponse } from 'services/auth/models';
10
import { TransactionStatus } from 'services/payment/models';
Wulan Mantiri's avatar
Wulan Mantiri committed
11

12
13
14
15
export const getNavigation = (
  isAuthenticated: boolean,
  user: AuthUserResponse,
) => {
Wulan Mantiri's avatar
Wulan Mantiri committed
16
  if (isAuthenticated) {
17
    if (user.role === UserRole.CLIENT) {
18
      if ([TransactionStatus.UNPAID, null].includes(user.transaction_status)) {
Wulan Mantiri's avatar
Wulan Mantiri committed
19
20
21
22
        return {
          initialRoute: ROUTES.checkout,
          navigation: unpaidClientNavigation,
        };
23
      } else {
Wulan Mantiri's avatar
Wulan Mantiri committed
24
        return {
25
26
          initialRoute: ROUTES.clientTabNavigation,
          navigation: paidClientNavigation,
Wulan Mantiri's avatar
Wulan Mantiri committed
27
        };
28
29
      }
    }
30

31
32
33
34
35
36
    if (user.role === UserRole.NUTRITIONIST) {
      return {
        initialRoute: ROUTES.clientListForNutritionist,
        navigation: nutritionistNavigation,
      };
    }
Wulan Mantiri's avatar
Wulan Mantiri committed
37

38
39
40
41
42
43
    if (user.role === UserRole.ADMIN) {
      return {
        initialRoute: ROUTES.clientListForAdmin,
        navigation: adminNavigation,
      };
    }
Wulan Mantiri's avatar
Wulan Mantiri committed
44
  }
45

Wulan Mantiri's avatar
Wulan Mantiri committed
46
47
48
49
50
  return {
    initialRoute: ROUTES.initial,
    navigation: publicNavigation,
  };
};