@campxdev/shared 1.11.32-alpha.1 → 1.11.32-alpha.10
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 +1 -1
- package/src/components/Institutions/InsititutionsDialog.tsx +1 -4
- package/src/components/Institutions/InstitutionsDropdown.tsx +1 -4
- package/src/components/LoginForm.tsx +1 -1
- package/src/config/axios.ts +2 -2
- package/src/contexts/Providers.tsx +24 -18
- package/src/hooks/useAuth.ts +3 -4
package/package.json
CHANGED
|
@@ -32,12 +32,9 @@ export default function InstitutionsDialog({ close }) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const InstitutionCard = ({ institution }) => {
|
|
35
|
-
const urlTenantKey = window.location.pathname.split('/')[1]
|
|
36
35
|
const handleClick = () => {
|
|
37
36
|
localStorage.setItem('institution_key', institution?.code)
|
|
38
|
-
window.location.replace(
|
|
39
|
-
`${window.location.origin}/${urlTenantKey}/${institution?.code}`,
|
|
40
|
-
)
|
|
37
|
+
window.location.replace(`${window.location.origin}/${institution?.code}`)
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
return (
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { urlTenantKey } from '../../contexts/Providers'
|
|
2
1
|
import { InstitutionsStore } from '../../shared-state/InstitutionsStore'
|
|
3
2
|
import { SearchSingleSelect } from '../Input/SearchSingleSelect'
|
|
4
3
|
|
|
@@ -8,9 +7,7 @@ export default function SchoolSwitch() {
|
|
|
8
7
|
const handleChange = (value) => {
|
|
9
8
|
if (value) {
|
|
10
9
|
localStorage.setItem('institution_key', value?.value)
|
|
11
|
-
window.location.replace(
|
|
12
|
-
`${window.location.origin}/${urlTenantKey}/${value?.value}`,
|
|
13
|
-
)
|
|
10
|
+
window.location.replace(`${window.location.origin}/${value?.value}`)
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
13
|
const options =
|
|
@@ -63,7 +63,7 @@ export function LoginForm({
|
|
|
63
63
|
})
|
|
64
64
|
Cookies.set('campx_tenant', res?.data?.subDomain)
|
|
65
65
|
Cookies.set('campx_session_key', res.data?.token)
|
|
66
|
-
window.location.href = window.location.origin
|
|
66
|
+
window.location.href = window.location.origin
|
|
67
67
|
} catch (err) {
|
|
68
68
|
// eslint-disable-next-line no-console
|
|
69
69
|
console.log(err)
|
package/src/config/axios.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { isDevelopment, isSetup } from '../constants'
|
|
|
6
6
|
import { InstitutionsStore } from '../shared-state/InstitutionsStore'
|
|
7
7
|
|
|
8
8
|
const sessionKey = Cookies.get('campx_session_key')
|
|
9
|
-
const clientId = window.location.
|
|
10
|
-
const institutionId = window.location.pathname.split('/')[
|
|
9
|
+
const clientId = window.location.hostname.split('.')[0] ?? 'campx_dev'
|
|
10
|
+
const institutionId = window.location.pathname.split('/')[1] ?? 'campx_dev'
|
|
11
11
|
const openPaymentsKey = Cookies.get('campx_open_payments_key')
|
|
12
12
|
|
|
13
13
|
export const formatParams = (params) => {
|
|
@@ -9,14 +9,19 @@ 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
|
-
import { isDevelopment } from '../constants'
|
|
13
12
|
import RootModal from './RootModal'
|
|
14
13
|
|
|
15
14
|
export const campxTenantKey = Cookies.get('campx_tenant')
|
|
16
|
-
export const urlTenantKey = window.location.
|
|
17
|
-
export const instituitionKey = window.location.pathname.split('/')[
|
|
15
|
+
export const urlTenantKey = window.location.hostname.split('.')[0]
|
|
16
|
+
export const instituitionKey = window.location.pathname.split('/')[1]
|
|
18
17
|
|
|
19
|
-
export default function Providers({
|
|
18
|
+
export default function Providers({
|
|
19
|
+
children,
|
|
20
|
+
module,
|
|
21
|
+
}: {
|
|
22
|
+
children: ReactNode
|
|
23
|
+
module?: string
|
|
24
|
+
}) {
|
|
20
25
|
const localInstituitionKey = localStorage.getItem('institution_key')
|
|
21
26
|
|
|
22
27
|
const getInstituitionKey = () => {
|
|
@@ -33,29 +38,30 @@ export default function Providers({ children }: { children: ReactNode }) {
|
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
useEffect(() => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (localInstituitionKey) {
|
|
41
|
+
console.log(instituitionKey, localInstituitionKey)
|
|
42
|
+
if (!instituitionKey) {
|
|
43
|
+
if (localInstituitionKey) {
|
|
44
|
+
if (module) {
|
|
45
|
+
window.location.replace(
|
|
46
|
+
window.location.origin + `/${localInstituitionKey}/${module}`,
|
|
47
|
+
)
|
|
48
|
+
} else {
|
|
45
49
|
window.location.replace(
|
|
46
|
-
window.location.origin + `/${
|
|
50
|
+
window.location.origin + `/${localInstituitionKey}`,
|
|
47
51
|
)
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
}, [])
|
|
52
56
|
|
|
53
|
-
const
|
|
54
|
-
?
|
|
55
|
-
|
|
57
|
+
const defaultBaseName = getInstituitionKey()
|
|
58
|
+
? module
|
|
59
|
+
? `${getInstituitionKey()}/${module}`
|
|
60
|
+
: `${getInstituitionKey()}`
|
|
61
|
+
: ''
|
|
56
62
|
|
|
57
63
|
return (
|
|
58
|
-
<BrowserRouter basename={
|
|
64
|
+
<BrowserRouter basename={defaultBaseName}>
|
|
59
65
|
<QueryClientProvider>
|
|
60
66
|
<MuiThemeProvider>
|
|
61
67
|
<ConfirmContextProvider>
|
package/src/hooks/useAuth.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { useEffect, useState } from 'react'
|
|
|
3
3
|
import { toast } from 'react-toastify'
|
|
4
4
|
import axios from '../config/axios'
|
|
5
5
|
import { isDevelopment } from '../constants'
|
|
6
|
-
import { urlTenantKey } from '../contexts/Providers'
|
|
7
6
|
import { openRootModal } from '../contexts/RootModal'
|
|
8
7
|
import { AssetsStore, PermissionsStore, UserStore } from '../shared-state'
|
|
9
8
|
import { InstitutionsStore } from '../shared-state/InstitutionsStore'
|
|
@@ -64,7 +63,7 @@ const checkIsAdmin = (user) => {
|
|
|
64
63
|
return isAdmin ? 1 : 0
|
|
65
64
|
}
|
|
66
65
|
const getInstitutionKey = () => {
|
|
67
|
-
const instituitionKey = window.location.pathname.split('/')[
|
|
66
|
+
const instituitionKey = window.location.pathname.split('/')[1]
|
|
68
67
|
if (!instituitionKey) {
|
|
69
68
|
const localInstituitionKey = localStorage.getItem('institution_key')
|
|
70
69
|
if (localInstituitionKey) {
|
|
@@ -91,12 +90,12 @@ function handleInstitutions(institutions) {
|
|
|
91
90
|
if (institutions?.length === 1) {
|
|
92
91
|
if (!insititutionKey) {
|
|
93
92
|
window.location.replace(
|
|
94
|
-
`${window.location.origin}/${
|
|
93
|
+
`${window.location.origin}/${institutions[0]?.code}`,
|
|
95
94
|
)
|
|
96
95
|
}
|
|
97
96
|
if (insititutionKey !== institutions[0]?.code) {
|
|
98
97
|
window.location.replace(
|
|
99
|
-
`${window.location.origin}/${
|
|
98
|
+
`${window.location.origin}/${institutions[0]?.code}`,
|
|
100
99
|
)
|
|
101
100
|
}
|
|
102
101
|
InstitutionsStore.update((s) => {
|