@campxdev/shared 3.1.2 → 3.1.3-alpha1

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": "3.1.2",
3
+ "version": "3.1.3-alpha1",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -3,14 +3,29 @@ import Cookies from 'js-cookie'
3
3
  import { toast } from 'react-toastify'
4
4
  import { NetworkStore } from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
5
5
 
6
- const isDevelopment = process.env.NODE_ENV == 'development'
6
+ // Declare the extended axios types to include our custom property
7
+ declare module 'axios' {
8
+ export interface AxiosRequestConfig {
9
+ workspace?: boolean
10
+ }
11
+ }
12
+
13
+ export const isDevelopment = window.location.hostname.includes('localhost')
7
14
 
8
- const tenantCode =
9
- isDevelopment || window.location.hostname === 'localhost'
10
- ? Cookies.get('campx_tenant')
11
- : window.location.hostname.split('.')[0]
15
+ const tenantCode = window.location.hostname.split('.')[0]
12
16
  const institutionCode = window.location.pathname.split('/')[1]
13
17
 
18
+ // Workspace to API endpoint prefix mapping
19
+ const workspaceApiMapping: Record<string, string> = {
20
+ 'student-workspace': '/student-api',
21
+ 'faculty-workspace': '/faculty-api',
22
+ 'department-workspace': '/department-api',
23
+ 'academic-coordinator-workspace': '/academic-coordinator-api',
24
+ 'academic-admin-workspace': '/academic-admin-api',
25
+ 'hostel-admin-workspace': '/hostel-admin-api',
26
+ 'transport-coordinator-workspace': '/transport-coordinator-api',
27
+ }
28
+
14
29
  export const formatParams = (params) => {
15
30
  return Object.fromEntries(
16
31
  Object.entries(params ?? {})?.map((i) => [
@@ -35,6 +50,19 @@ axios.interceptors.request.use(
35
50
  NetworkStore.update((s) => {
36
51
  s.loading = true
37
52
  })
53
+
54
+ // Handle workspace routing (default: true)
55
+ if (
56
+ config.workspace !== false &&
57
+ window.location.pathname.split('/')[2] &&
58
+ window.location.pathname.split('/')[2] !== 'common-workspace' &&
59
+ workspaceApiMapping[window.location.pathname.split('/')[2]]
60
+ ) {
61
+ const workspacePrefix = workspaceApiMapping[window.location.pathname.split('/')[2]]
62
+ config.url = `${workspacePrefix}${config.url}`
63
+ }
64
+
65
+ // Add session keys from cookies if available
38
66
  const sessionKey = Cookies.get('campx_session_key')
39
67
  const openPaymentsKey = Cookies.get('campx_open_payments_key')
40
68
 
@@ -73,6 +101,7 @@ axios.interceptors.response.use(
73
101
 
74
102
  // Check if the error is an unauthorized error (401)
75
103
  if (err?.response && err?.response?.status === 401) {
104
+ // Clear session keys from cookies on unauthorized error
76
105
  Cookies.remove('campx_session_key')
77
106
  Cookies.remove('campx_tenant')
78
107
  Cookies.remove('campx_institution')
@@ -11,6 +11,8 @@ const tenantBatchConfig = {
11
11
  '2022 - 2023': ['_JUL', '_JAN'],
12
12
  '2023 - 2024': ['_JAN', '_JUL'],
13
13
  '2024 - 2025': ['_JUL', '_JAN'],
14
+ '2025 - 2026': ['_JAN', '_JUL'],
15
+
14
16
  // Add more specific year configurations as needed
15
17
  },
16
18
  },
@@ -3,7 +3,6 @@ import ConfirmContextProvider from '../components/PopupConfirm/ConfirmContextPro
3
3
  import MuiThemeProvider from '../theme/MuiThemeProvider'
4
4
  import QueryClientProvider from './QueryClientProvider'
5
5
 
6
- import Cookies from 'js-cookie'
7
6
  import { ReactNode, useEffect } from 'react'
8
7
  import { ToastContainer } from '../components'
9
8
  import DialogProvider from '../components/DrawerWrapper/DrawerWrapper'
@@ -11,41 +10,19 @@ import GlobalNetworkLoadingIndicator from '../components/ErrorBoundary/GlobalNet
11
10
  import ErrorModalProvider from '../components/ErrorModalWrapper/ErrorModalWrapper'
12
11
  import RootModal from './RootModal'
13
12
 
14
- const isDevelopment = process.env.NODE_ENV == 'development'
13
+ const isDevelopment = window.location.hostname.includes('localhost')
15
14
 
16
- export const campxTenantKey = isDevelopment
17
- ? Cookies.get('campx_tenant')
18
- : window.location.hostname.split('.')[0]
19
- export const urlTenantKey = isDevelopment
20
- ? Cookies.get('campx_tenant')
21
- : window.location.hostname.split('.')[0]
22
- export const instituitionKey =
23
- window.location.pathname.split('/')[1] != ''
24
- ? window.location.pathname.split('/')[1]
25
- : Cookies.get('campx_institution')
15
+ export const campxTenantKey = window.location.hostname.split('.')[0]
16
+ export const urlTenantKey = window.location.hostname.split('.')[0]
17
+ export const instituitionKey = window.location.pathname.split('/')[1]
26
18
 
27
19
  export default function Providers({ children }: { children: ReactNode }) {
28
20
  var baseName = '/'
29
- var tenantCode
30
- var institutionCode =
31
- window.location.pathname.split('/')[1] != ''
32
- ? window.location.pathname.split('/')[1]
33
- : Cookies.get('campx_institution')
21
+ var tenantCode = window.location.hostname.split('.')[0]
22
+ var institutionCode = window.location.pathname.split('/')[1]
34
23
 
35
- if (isDevelopment) {
36
- tenantCode = Cookies.get('campx_tenant')
37
- if (
38
- tenantCode &&
39
- institutionCode &&
40
- window.location.pathname !== '/auth/login'
41
- ) {
42
- baseName = `/${institutionCode}`
43
- }
44
- } else {
45
- tenantCode = window.location.hostname.split('.')[0]
46
- if (institutionCode && window.location.pathname !== '/auth/login') {
47
- baseName = `/${institutionCode}`
48
- }
24
+ if (institutionCode && window.location.pathname !== '/auth/login') {
25
+ baseName = `/${institutionCode}`
49
26
  }
50
27
 
51
28
  useEffect(() => {