@campxdev/shared 1.10.93 → 1.10.94
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 +3 -3
- package/src/components/Institutions/InstitutionsDropdown.tsx +2 -2
- package/src/components/MyProfile/MyProfile.tsx +2 -2
- package/src/config/axios.ts +2 -2
- package/src/hooks/useAuth.ts +4 -4
- package/src/shared-state/InstitutionsStore.ts +1 -1
- package/src/utils/getUrlParams.ts +3 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Box, TextField, Typography, styled } from '@mui/material'
|
|
2
2
|
import { useState } from 'react'
|
|
3
|
-
import {
|
|
3
|
+
import { InstitutionsStore } from '../../shared-state/InstitutionsStore'
|
|
4
4
|
import Image from '../Image/Image'
|
|
5
5
|
|
|
6
|
-
export default function
|
|
6
|
+
export default function InstitutionsDialog({ close }) {
|
|
7
7
|
const [searchText, setSearchText] = useState('')
|
|
8
|
-
const { institutions } =
|
|
8
|
+
const { institutions } = InstitutionsStore.useState((s) => s)
|
|
9
9
|
const filteredInstitutions = institutions.filter((item) =>
|
|
10
10
|
item.name.toLowerCase().includes(searchText.toLowerCase()),
|
|
11
11
|
)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { urlTenantKey } from '../../contexts/Providers'
|
|
2
|
-
import {
|
|
2
|
+
import { InstitutionsStore } from '../../shared-state/InstitutionsStore'
|
|
3
3
|
import { SearchSingleSelect } from '../Input/SearchSingleSelect'
|
|
4
4
|
|
|
5
5
|
export default function SchoolSwitch() {
|
|
6
|
-
const { current, institutions } =
|
|
6
|
+
const { current, institutions } = InstitutionsStore.useState((s) => s)
|
|
7
7
|
|
|
8
8
|
const handleChange = (value) => {
|
|
9
9
|
if (value) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Box, Chip, Container, Typography } from '@mui/material'
|
|
2
2
|
import { useQuery } from 'react-query'
|
|
3
3
|
import axios from '../../config/axios'
|
|
4
|
-
import {
|
|
4
|
+
import { InstitutionsStore } from '../../shared-state/InstitutionsStore'
|
|
5
5
|
import PageHeader from '../PageHeader'
|
|
6
6
|
import Spinner from '../Spinner'
|
|
7
7
|
import Education from './Education/Education'
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
import Workshop from './Workshop/Workshop'
|
|
20
20
|
|
|
21
21
|
const MyProfile = ({ close }) => {
|
|
22
|
-
const { institutions, current } =
|
|
22
|
+
const { institutions, current } = InstitutionsStore.useState((s) => s)
|
|
23
23
|
|
|
24
24
|
const { data, isLoading } = useQuery('dashboard', () =>
|
|
25
25
|
axios.get('/square/users/dashboard').then((res) => res?.data),
|
package/src/config/axios.ts
CHANGED
|
@@ -3,7 +3,7 @@ import Cookies from 'js-cookie'
|
|
|
3
3
|
import { toast } from 'react-toastify'
|
|
4
4
|
import { NetworkStore } from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
|
|
5
5
|
import { isDevelopment, isSetup } from '../constants'
|
|
6
|
-
import {
|
|
6
|
+
import { InstitutionsStore } from '../shared-state/InstitutionsStore'
|
|
7
7
|
|
|
8
8
|
const sessionKey = Cookies.get('campx_session_key')
|
|
9
9
|
const clientId = window.location.pathname.split('/')[1] ?? 'campx_dev'
|
|
@@ -31,7 +31,7 @@ let axios = Axios.create({
|
|
|
31
31
|
|
|
32
32
|
axios.interceptors.request.use(
|
|
33
33
|
function (config: AxiosRequestConfig) {
|
|
34
|
-
const { current } =
|
|
34
|
+
const { current } = InstitutionsStore.getRawState()
|
|
35
35
|
if (current) {
|
|
36
36
|
config.headers['x-institution-code'] = current.code
|
|
37
37
|
} else {
|
package/src/hooks/useAuth.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { isDevelopment } from '../constants'
|
|
|
6
6
|
import { urlTenantKey } from '../contexts/Providers'
|
|
7
7
|
import { openRootModal } from '../contexts/RootModal'
|
|
8
8
|
import { AssetsStore, PermissionsStore, UserStore } from '../shared-state'
|
|
9
|
-
import {
|
|
9
|
+
import { InstitutionsStore } from '../shared-state/InstitutionsStore'
|
|
10
10
|
|
|
11
11
|
const url = window.location.origin
|
|
12
12
|
|
|
@@ -97,7 +97,7 @@ function handleInstitutions(institutions) {
|
|
|
97
97
|
`${window.location.origin}/${urlTenantKey}/${institutions[0]?.code}`,
|
|
98
98
|
)
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
InstitutionsStore.update((s) => {
|
|
101
101
|
s.current = institutions[0]
|
|
102
102
|
s.institutions = institutions
|
|
103
103
|
})
|
|
@@ -125,7 +125,7 @@ function handleInstitutions(institutions) {
|
|
|
125
125
|
},
|
|
126
126
|
})
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
InstitutionsStore.update((s) => {
|
|
129
129
|
s.institutions = institutions
|
|
130
130
|
s.current = institutions.find((item) => item.code === insititutionKey)
|
|
131
131
|
})
|
|
@@ -174,7 +174,7 @@ const loginErrorHandler = ({
|
|
|
174
174
|
function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
|
|
175
175
|
const [loading, setLoading] = useState<boolean>(false)
|
|
176
176
|
const [data, setData] = useState(null)
|
|
177
|
-
const { current } =
|
|
177
|
+
const { current } = InstitutionsStore.useState()
|
|
178
178
|
|
|
179
179
|
const appInit = async () => {
|
|
180
180
|
setLoading(true)
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export default function getUrlParams() {
|
|
2
2
|
const urlSearchParams = new URLSearchParams(window.location.search)
|
|
3
3
|
const params = Object.fromEntries(urlSearchParams.entries())
|
|
4
|
+
for (const i in params) {
|
|
5
|
+
params[i] = decodeURIComponent(params[i])
|
|
6
|
+
}
|
|
4
7
|
return params
|
|
5
8
|
}
|