@campxdev/shared 1.8.31 → 1.8.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.8.31",
3
+ "version": "1.8.33",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -28,6 +28,16 @@ type AuthResponse = {
28
28
  }
29
29
  }
30
30
 
31
+ const ApplicationObj = {
32
+ enroll: 'enroll_x',
33
+ ums: 'square',
34
+ payments: 'payments',
35
+ exams: 'exams',
36
+ }
37
+ const checkIsAdmin = (userProfile, application) => {
38
+ const profile = userProfile.find((item) => item.application == application)
39
+ return profile ? profile.isAdmin : false
40
+ }
31
41
  function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
32
42
  const { openLoginForm } = useLoginForm()
33
43
  const [loading, setLoading] = useState<boolean>(false)
@@ -39,12 +49,15 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
39
49
  .get(permissionsEndpoint)
40
50
  .then((res) => {
41
51
  const origin = window.location.origin
42
- const domain = origin.split('campx')[0].split('//')[1]
52
+ const originSubdomain =
53
+ window.location.host.split('.')?.slice(-3)[0] ?? 'ums'
43
54
 
44
55
  const isStaging = origin.split('campx')[1] === '.dev'
45
56
 
46
57
  if (isDevelopment == false && isStaging == false) {
47
- if (!res.data.applications.includes(domain)) {
58
+ if (
59
+ !res.data.applications.includes(ApplicationObj[originSubdomain])
60
+ ) {
48
61
  window.location.replace(
49
62
  `https://www.id.campx.in/apps?redirect_to=${url}`,
50
63
  )
@@ -66,6 +79,7 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
66
79
  can_dashboard_view: 1,
67
80
  can_individual_pages_view: 1,
68
81
  can_analatics_view: res.data.user.isSuperuser == true ? 1 : 0,
82
+ can_admin_view: res.data.user.isSuperuser == true ? 1 : 0,
69
83
  } as any
70
84
  s.applications = res.data?.applications ?? []
71
85
  })
@@ -939,6 +939,8 @@ export enum Permission {
939
939
  CAN_EXAM_TIME_SLOTS_ADD = 'can_exam_time_slots_add',
940
940
  CAN_EXAM_TIME_SLOTS_EDIT = 'can_exam_time_slots_edit',
941
941
  CAN_EXAM_TIME_SLOTS_DELETE = 'can_exam_time_slots_delete',
942
+
943
+ CAN_ADMIN_VIEW = 'can_admin_view',
942
944
  }
943
945
 
944
946
  export interface IPermissions {