Fakultas Ilmu Komputer UI

schema.ts 1.39 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
19
20
21
22
23
      if (!user.cart_id) {
        return {
          initialRoute: ROUTES.allAccessQuestionnaire,
          navigation: unpaidClientNavigation,
        };
      }
24
      if ([TransactionStatus.UNPAID, null].includes(user.transaction_status)) {
Wulan Mantiri's avatar
Wulan Mantiri committed
25
26
27
28
        return {
          initialRoute: ROUTES.checkout,
          navigation: unpaidClientNavigation,
        };
29
      } else {
Wulan Mantiri's avatar
Wulan Mantiri committed
30
        return {
31
32
          initialRoute: ROUTES.clientTabNavigation,
          navigation: paidClientNavigation,
Wulan Mantiri's avatar
Wulan Mantiri committed
33
        };
34
35
      }
    }
36

37
38
39
40
41
42
    if (user.role === UserRole.NUTRITIONIST) {
      return {
        initialRoute: ROUTES.clientListForNutritionist,
        navigation: nutritionistNavigation,
      };
    }
Wulan Mantiri's avatar
Wulan Mantiri committed
43

44
45
46
47
48
49
    if (user.role === UserRole.ADMIN) {
      return {
        initialRoute: ROUTES.clientListForAdmin,
        navigation: adminNavigation,
      };
    }
Wulan Mantiri's avatar
Wulan Mantiri committed
50
  }
51

Wulan Mantiri's avatar
Wulan Mantiri committed
52
53
54
55
56
  return {
    initialRoute: ROUTES.initial,
    navigation: publicNavigation,
  };
};