@campxdev/shared 3.1.2 → 3.1.3-alpha2

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-alpha2",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -1,11 +1,7 @@
1
- import TourIcon from '@mui/icons-material/Tour'
2
1
  import { Box, Button, Typography } from '@mui/material'
3
- import { ReactNode, useEffect, useState } from 'react'
4
- import ReactJoyride, { Step, CallBackProps } from 'react-joyride'
5
- import { useQuery } from 'react-query'
6
- import axios from '../config/axios'
2
+ import { ReactNode, useState } from 'react'
3
+ import ReactJoyride, { Step } from 'react-joyride'
7
4
  import './CustomJoyRideStyles.css'
8
- import Spinner from './Spinner'
9
5
 
10
6
  function ReactJoyRide({
11
7
  steps,
@@ -17,95 +13,65 @@ function ReactJoyRide({
17
13
  tourName: string
18
14
  }) {
19
15
  const [run, setRun] = useState(false)
20
- const [stepIndex, setStepIndex] = useState(0)
21
-
22
- const fetchTours = (params) => {
23
- return axios.get(`/square/tours`).then((res) => res.data)
24
- }
25
-
26
- const { data: toursData, isLoading: toursLoading } = useQuery(
27
- 'tours',
28
- fetchTours,
29
- )
30
-
31
- useEffect(() => {}, [run])
32
-
33
- const completeTour = async () => {
34
- try {
35
- await axios.post(`/square/tours/complete`, { tourName })
36
- } catch (error) {
37
- // console.error('Error in Completing Tour:', error)
38
- }
39
- }
40
-
41
- const handleJoyRideCallback = (data: CallBackProps) => {
42
- const { action, status, index } = data
43
-
44
- if (action === 'next' || action === 'prev') {
45
- setStepIndex(index + (action === 'next' ? 1 : 0))
46
- }
47
-
48
- if (action === 'reset') {
49
- setRun(false)
50
- setStepIndex(0)
51
- completeTour()
52
- }
53
- }
54
16
 
55
17
  const customSteps = steps.map((step, index) => ({
56
- ...step,
57
- title: '', // Remove the automatic title
58
- content: (
59
- <Box sx={{ fontFamily: 'Roboto, sans-serif',display: 'flex', flexDirection: 'column', }}>
60
-
61
- <Typography
62
- variant="caption"
63
- sx={{
64
- color: '#6b7280',
65
- fontWeight: 500,
66
- textTransform: 'uppercase',
67
- letterSpacing: '0.5px',
68
- fontSize: '11px',
18
+ ...step,
19
+ title: '', // Remove the automatic title
20
+ content: (
21
+ <Box
22
+ sx={{
23
+ fontFamily: 'Roboto, sans-serif',
24
+ display: 'flex',
25
+ flexDirection: 'column',
26
+ }}
27
+ >
28
+ <Typography
29
+ variant="caption"
30
+ sx={{
31
+ color: '#6b7280',
32
+ fontWeight: 500,
33
+ textTransform: 'uppercase',
34
+ letterSpacing: '0.5px',
35
+ fontSize: '11px',
36
+ }}
37
+ >
38
+ Step {index + 1}
39
+ </Typography>
40
+ <Box sx={{ padding: '4px 0' }}>
41
+ <Typography
42
+ sx={{
43
+ lineHeight: 1.5,
44
+ color: '#4b5563',
45
+ fontFamily: 'Poppins, sans-serif',
46
+ fontSize: '16px',
47
+ fontWeight: '600',
48
+ marginTop: '12px',
69
49
  }}
70
50
  >
71
- Step {index + 1}
51
+ {step.title}
72
52
  </Typography>
73
- <Box sx={{ padding: '4px 0' }}>
74
- <Typography
75
- sx={{
76
- lineHeight: 1.5,
77
- color: '#4b5563',
78
- fontFamily: 'Poppins, sans-serif',
79
- fontSize: '16px',
80
- fontWeight: '600',
81
- marginTop: '12px',
82
- }}
83
- >
84
- {step.title}
85
- </Typography>
86
- </Box>
87
- <Box sx={{ padding: '4px 0' }}>
88
- <Typography
89
- sx={{
90
- fontSize: '14px',
91
- lineHeight: 1.5,
92
- color: '#4b5563',
93
- fontFamily: 'Heebo, sans-serif',
94
- fontWeight: '500',
95
- }}
96
- >
97
- {step.content}
98
- </Typography>
99
- </Box>
100
53
  </Box>
101
- ),
102
- }))
54
+ <Box sx={{ padding: '4px 0' }}>
55
+ <Typography
56
+ sx={{
57
+ fontSize: '14px',
58
+ lineHeight: 1.5,
59
+ color: '#4b5563',
60
+ fontFamily: 'Heebo, sans-serif',
61
+ fontWeight: '500',
62
+ }}
63
+ >
64
+ {step.content}
65
+ </Typography>
66
+ </Box>
67
+ </Box>
68
+ ),
69
+ }))
103
70
 
104
71
  return (
105
72
  <>
106
73
  <Box>
107
74
  <ReactJoyride
108
- callback={handleJoyRideCallback}
109
75
  run={run}
110
76
  steps={customSteps}
111
77
  styles={{
@@ -119,7 +85,8 @@ function ReactJoyRide({
119
85
  },
120
86
  tooltip: {
121
87
  borderRadius: '12px',
122
- boxShadow: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
88
+ boxShadow:
89
+ '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',
123
90
  fontSize: '14px',
124
91
  padding: '20px',
125
92
  minWidth: '320px',
@@ -132,7 +99,7 @@ function ReactJoyRide({
132
99
  fontSize: '16px',
133
100
  fontWeight: '600',
134
101
  color: '#1f2937',
135
- fontFamily: 'Poppins, sans-serif',
102
+ fontFamily: 'Poppins, sans-serif',
136
103
  },
137
104
  tooltipContent: {
138
105
  fontSize: '14px',
@@ -140,7 +107,7 @@ function ReactJoyRide({
140
107
  color: '#4b5563',
141
108
  padding: '0',
142
109
  fontFamily: 'Heebo, sans-serif !important',
143
- fontWeight: '400'
110
+ fontWeight: '400',
144
111
  },
145
112
  buttonNext: {
146
113
  backgroundColor: '#121212',
@@ -246,7 +213,8 @@ function ReactJoyRide({
246
213
  '&:hover': {
247
214
  backgroundColor: '#1E027F',
248
215
  color: 'white',
249
- boxShadow: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
216
+ boxShadow:
217
+ '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
250
218
  transform: 'translateY(-50%) translateX(-4px)',
251
219
  },
252
220
  '&:active': {
@@ -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(() => {