@campxdev/shared 1.11.7-1.alpha.5 → 1.11.7-1.alpha.7

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.11.7-1.alpha.5",
3
+ "version": "1.11.7-1.alpha.7",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -61,10 +61,9 @@ export function LoginForm({
61
61
  ...deviceState.deviceInformation,
62
62
  },
63
63
  })
64
- Cookies.set('campx_tenant', res?.data?.subDomain)
65
64
  Cookies.set('campx_session_key', res.data?.token)
66
- Cookies.set('campx_institution', res.data?.institutionCode)
67
- window.location.reload();
65
+ window.location.href = `/${res.data.subDomain}/${res.data.institutionCode}`
66
+ //window.location.reload()
68
67
  } catch (err) {
69
68
  // eslint-disable-next-line no-console
70
69
  console.log(err)
@@ -1,4 +1,5 @@
1
1
  import { createContext, ReactNode, useState } from 'react'
2
+ import MuiThemeProvider from '../../theme/MuiThemeProvider'
2
3
  import PopupConfirm from './PopupConfirm'
3
4
 
4
5
  interface ConfirmContextProps {
@@ -30,10 +31,12 @@ const ConfirmContextProvider = ({ children }) => {
30
31
  })
31
32
 
32
33
  return (
33
- <ConfirmContext.Provider value={{ confirm, setConfirm }}>
34
- {children}
35
- <PopupConfirm />
36
- </ConfirmContext.Provider>
34
+ <MuiThemeProvider>
35
+ <ConfirmContext.Provider value={{ confirm, setConfirm }}>
36
+ {children}
37
+ <PopupConfirm />
38
+ </ConfirmContext.Provider>
39
+ </MuiThemeProvider>
37
40
  )
38
41
  }
39
42
 
@@ -3,14 +3,17 @@ 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'
7
+
6
8
  const sessionKey = Cookies.get('campx_session_key')
7
- const tenantId =
8
- Cookies.get('campx_tenant') ?? window.location.hostname.split('.')[0]
9
- const institutionId =
10
- Cookies.get('campx_institution') ?? window.location.pathname.split('/')[1]
11
- const openPaymentsKey = Cookies.get('campx_open_payments_key')
9
+ const tenantCode = isDevelopment
10
+ ? window.location.pathname.split('/')[1]
11
+ : window.location.hostname.split('.')[0]
12
+ const institutionCode = isDevelopment
13
+ ? window.location.pathname.split('/')[2]
14
+ : window.location.pathname.split('/')[1]
12
15
 
13
- const isProduction = process.env.NODE_ENV === 'production'
16
+ const openPaymentsKey = Cookies.get('campx_open_payments_key')
14
17
 
15
18
  export const formatParams = (params) => {
16
19
  return Object.fromEntries(
@@ -21,14 +24,12 @@ export const formatParams = (params) => {
21
24
  )
22
25
  }
23
26
 
24
- console.log(institutionId, sessionKey, 'test')
25
-
26
27
  let axios = Axios.create({
27
28
  baseURL: process.env.REACT_APP_API_HOST,
28
29
  withCredentials: true,
29
30
  headers: {
30
- 'x-tenant-id': tenantId,
31
- 'x-institution-code': institutionId,
31
+ 'x-tenant-id': tenantCode,
32
+ 'x-institution-code': institutionCode,
32
33
  campx_session_key: sessionKey,
33
34
  ...(openPaymentsKey && {
34
35
  campx_open_payments_key: openPaymentsKey,
@@ -1,5 +1,2 @@
1
- export const isDevelopment =
2
- process.env.NODE_ENV === 'development' ||
3
- window.location.origin.split('campx')[1] === '.dev'
4
-
1
+ export const isDevelopment = process.env.NODE_ENV === 'development'
5
2
  export const isSetup = window.location.hostname.split('.').includes('setup')
@@ -4,20 +4,66 @@ import MuiThemeProvider from '../theme/MuiThemeProvider'
4
4
  import QueryClientProvider from './QueryClientProvider'
5
5
 
6
6
  import Cookies from 'js-cookie'
7
- import { ReactNode } from 'react'
7
+ import { ReactNode, useEffect } from 'react'
8
8
  import { ToastContainer } from '../components'
9
9
  import DialogProvider from '../components/DrawerWrapper/DrawerWrapper'
10
10
  import GlobalNetworkLoadingIndicator from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
11
11
  import ErrorModalProvider from '../components/ErrorModalWrapper/ErrorModalWrapper'
12
12
  import RootModal from './RootModal'
13
13
 
14
- export const campxTenantKey = Cookies.get('campx_tenant')
15
- export const urlTenantKey = Cookies.get('campx_tenant')
16
- export const instituitionKey = window.location.pathname.split('/')[2]
14
+ const isDevelopment = process.env.NODE_ENV == 'development'
15
+
16
+ export const campxTenantKey = isDevelopment
17
+ ? window.location.pathname.split('/')[1]
18
+ : window.location.hostname.split('.')[0] ?? Cookies.get('campx_tenant')
19
+ export const urlTenantKey = isDevelopment
20
+ ? window.location.pathname.split('/')[1]
21
+ : window.location.hostname.split('.')[0] ?? Cookies.get('campx_tenant')
22
+ export const instituitionKey = isDevelopment
23
+ ? window.location.pathname.split('/')[2]
24
+ : window.location.pathname.split('/')[1]
17
25
 
18
26
  export default function Providers({ children }: { children: ReactNode }) {
27
+ const sessionKey = Cookies.get('campx_session_key')
28
+ var baseName = '/'
29
+ var tenantCode
30
+ var institutionCode
31
+
32
+ if (isDevelopment) {
33
+ tenantCode = window.location.pathname.split('/')[1]
34
+ institutionCode = window.location.pathname.split('/')[2]
35
+ if (
36
+ tenantCode &&
37
+ institutionCode &&
38
+ window.location.pathname !== '/auth/login'
39
+ ) {
40
+ baseName = `/${tenantCode}/${institutionCode}`
41
+ }
42
+ } else {
43
+ tenantCode = window.location.hostname.split('.')[0]
44
+ institutionCode = window.location.pathname.split('/')[1]
45
+
46
+ if (institutionCode && window.location.pathname !== '/auth/login') {
47
+ baseName = `/${institutionCode}`
48
+ }
49
+ }
50
+
51
+ useEffect(() => {
52
+ if (
53
+ isDevelopment &&
54
+ location.pathname === '/' &&
55
+ institutionCode &&
56
+ tenantCode
57
+ ) {
58
+ window.location.replace(
59
+ window.location.origin + `/${tenantCode}/${institutionCode}`,
60
+ )
61
+ } else if (location.pathname === '/' && institutionCode) {
62
+ window.location.replace(window.location.origin + `/${institutionCode}`)
63
+ }
64
+ }, [])
19
65
  return (
20
- <BrowserRouter>
66
+ <BrowserRouter basename={baseName}>
21
67
  <QueryClientProvider>
22
68
  <MuiThemeProvider>
23
69
  <ConfirmContextProvider>
@@ -1,4 +1,3 @@
1
- import Cookies from 'js-cookie'
2
1
  import { useEffect, useState } from 'react'
3
2
  import { useNavigate } from 'react-router-dom'
4
3
  import { toast } from 'react-toastify'
@@ -98,18 +97,18 @@ const useAuth = ({
98
97
  permissionsEndpoint,
99
98
  loginUrl,
100
99
  }: AuthParams): AuthResponse => {
101
- const [loading, setLoading] = useState<boolean>(false)
100
+ const [loading, setLoading] = useState<boolean>(true)
102
101
  const [data, setData] = useState<any>(null)
103
102
  const { current } = InstitutionsStore.useState()
104
103
  const navigate = useNavigate()
105
104
 
106
105
  const appInit = async () => {
107
- setLoading(true)
108
106
  try {
109
107
  const res = await axios.get(permissionsEndpoint)
110
108
  const isAdmin = checkIsAdmin(res.data.user)
111
-
109
+ setLoading(false)
112
110
  setData(res.data)
111
+
113
112
  UserStore.update((s) => {
114
113
  s.username = res.data?.user?.username
115
114
  s.user = res.data?.user
@@ -143,17 +142,13 @@ const useAuth = ({
143
142
 
144
143
  InstitutionsStore.update((s) => {
145
144
  s.institutions = res.data?.institutions
146
- s.current = res.data?.institutions.find(
147
- (item) => item.code === Cookies.get('campx_institution'),
148
- )
145
+ s.current = res.data?.institutions[0]
149
146
  })
150
147
 
151
148
  AssetsStore.update((s) => {
152
149
  s.logo = res.data?.assets.logo
153
150
  s.logo_square = res.data?.assets.logo_square
154
151
  })
155
-
156
- setLoading(false)
157
152
  } catch (err: any) {
158
153
  setLoading(false)
159
154
  const origin = window.location.origin
@@ -176,10 +171,11 @@ const useAuth = ({
176
171
  }
177
172
  }
178
173
  }
179
-
174
+ console.log(loading, !data?.permissions, !current, 'abc1')
180
175
  useEffect(() => {
181
176
  appInit()
182
177
  }, [])
178
+ console.log(loading, !data?.permissions, !current, 'abc2')
183
179
 
184
180
  return {
185
181
  loading: loading || !data?.permissions || !current,