@campxdev/shared 1.11.31 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campxdev/shared",
3
- "version": "1.11.31",
3
+ "version": "1.11.32-alpha.10",
4
4
  "main": "./exports.ts",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
@@ -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 =
@@ -2,6 +2,7 @@ import {
2
2
  StyledLeftNavContainer,
3
3
  StyledMainContentContainer,
4
4
  } from '../../layouts/Components/styles'
5
+ import { PermissionsStore } from '../../shared-state'
5
6
  import ErrorBoundary from '../ErrorBoundary'
6
7
  import SideNav from './SideNav'
7
8
  interface Props {
@@ -15,12 +16,29 @@ export default function LayoutWrapper({
15
16
  menu,
16
17
  sideMenuHeader,
17
18
  }: Props) {
19
+ const permissions = PermissionsStore.useState()
20
+
18
21
  return (
19
22
  <ErrorBoundary>
20
- <StyledLeftNavContainer>
21
- <SideNav menuItems={menu as any[]} header={sideMenuHeader} />
22
- </StyledLeftNavContainer>
23
- <StyledMainContentContainer>
23
+ {!permissions.isHomePageEnabled && (
24
+ <StyledLeftNavContainer>
25
+ <SideNav menuItems={menu as any[]} header={sideMenuHeader} />
26
+ </StyledLeftNavContainer>
27
+ )}
28
+ <StyledMainContentContainer
29
+ style={{
30
+ width: permissions.isHomePageEnabled
31
+ ? 'inherit'
32
+ : 'calc(100% - 220px)',
33
+ position: permissions.isHomePageEnabled ? 'unset' : 'fixed',
34
+ marginTop: permissions.isHomePageEnabled ? '10px' : '0px',
35
+ borderRadius: permissions.isHomePageEnabled ? '10px' : '0px',
36
+ border: permissions.isHomePageEnabled ? '1px solid #1212' : 'none',
37
+ height: permissions.isHomePageEnabled
38
+ ? 'calc(100vh - 74px)'
39
+ : 'calc(100vh - 64px)',
40
+ }}
41
+ >
24
42
  <ErrorBoundary>{children}</ErrorBoundary>
25
43
  </StyledMainContentContainer>
26
44
  </ErrorBoundary>
@@ -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 + `/${res?.data?.subDomain}`
66
+ window.location.href = window.location.origin
67
67
  } catch (err) {
68
68
  // eslint-disable-next-line no-console
69
69
  console.log(err)
@@ -26,13 +26,13 @@ const ExamGroupSelector = (props: ExamGroupSelectorProps) => {
26
26
  const [prevExamType, setPrevExamType] = useState(null)
27
27
  const [prevCourseId, setPrevCourseId] = useState(null)
28
28
  let api =
29
- filters.examType !== 'internal'
29
+ filters?.examType !== 'internal'
30
30
  ? '/exams/exams/exam-groups'
31
31
  : '/exams/internal-exams'
32
32
  const handleOpen = () => {
33
33
  if (filters) {
34
34
  if (
35
- (filters.examType && filters.examType !== prevExamType) ||
35
+ (filters?.examType && filters?.examType !== prevExamType) ||
36
36
  (filters?.courseId && filters?.courseId !== prevCourseId)
37
37
  ) {
38
38
  setOptions([])
@@ -46,12 +46,12 @@ const ExamGroupSelector = (props: ExamGroupSelectorProps) => {
46
46
  })
47
47
  .then((response) => {
48
48
  setOptions(
49
- filters.examType !== 'internal'
49
+ filters?.examType !== 'internal'
50
50
  ? response.data?.examGroups
51
51
  : response.data?.exams,
52
52
  )
53
- setPrevExamType(filters.examType)
54
- setPrevCourseId(filters.courseId)
53
+ setPrevExamType(filters?.examType)
54
+ setPrevCourseId(filters?.courseId)
55
55
  })
56
56
  .catch((error) => {
57
57
  console.error('Error fetching data from the API:', error)
@@ -59,9 +59,18 @@ const ExamGroupSelector = (props: ExamGroupSelectorProps) => {
59
59
  }
60
60
  } else if (options.length === 0) {
61
61
  axios
62
- .get(api)
62
+ .get(api, {
63
+ params: {
64
+ isArchived: 'false',
65
+ isExamPublished: 'true',
66
+ },
67
+ })
63
68
  .then((response) => {
64
- setOptions(response.data)
69
+ setOptions(
70
+ filters?.examType !== 'internal'
71
+ ? response.data?.examGroups
72
+ : response.data?.exams,
73
+ )
65
74
  })
66
75
  .catch((error) => {
67
76
  console.error('Error fetching data from the API:', error)
@@ -80,7 +89,7 @@ const ExamGroupSelector = (props: ExamGroupSelectorProps) => {
80
89
  ...(allowAll ? [{ value: 'all', label: 'All' }] : []),
81
90
  ...options.map((item) => ({
82
91
  label:
83
- filters.examType != 'internal'
92
+ filters?.examType != 'internal'
84
93
  ? item?.groupName
85
94
  : item?.displayName,
86
95
  value: item?.id,
@@ -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.pathname.split('/')[1] ?? 'campx_dev'
10
- const institutionId = window.location.pathname.split('/')[2] ?? 'campx_dev'
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.pathname.split('/')[1]
17
- export const instituitionKey = window.location.pathname.split('/')[2]
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({ children }: { children: ReactNode }) {
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
- if (!urlTenantKey) {
37
- if (isDevelopment) {
38
- window.location.replace(window.location.origin + `/aupulse`)
39
- }
40
- if (campxTenantKey)
41
- window.location.replace(window.location.origin + `/${campxTenantKey}`)
42
- } else {
43
- if (!instituitionKey) {
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 + `/${urlTenantKey}/${localInstituitionKey}`,
50
+ window.location.origin + `/${localInstituitionKey}`,
47
51
  )
48
52
  }
49
53
  }
50
54
  }
51
55
  }, [])
52
56
 
53
- const baseName = getInstituitionKey()
54
- ? `${urlTenantKey}/${getInstituitionKey()}`
55
- : urlTenantKey
57
+ const defaultBaseName = getInstituitionKey()
58
+ ? module
59
+ ? `${getInstituitionKey()}/${module}`
60
+ : `${getInstituitionKey()}`
61
+ : ''
56
62
 
57
63
  return (
58
- <BrowserRouter basename={baseName}>
64
+ <BrowserRouter basename={defaultBaseName}>
59
65
  <QueryClientProvider>
60
66
  <MuiThemeProvider>
61
67
  <ConfirmContextProvider>
@@ -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'
@@ -26,6 +25,7 @@ type AuthResponse = {
26
25
  logo: string
27
26
  logo_square: string
28
27
  }
28
+ isHomePageEnabled?: boolean
29
29
  }
30
30
  }
31
31
 
@@ -63,7 +63,7 @@ const checkIsAdmin = (user) => {
63
63
  return isAdmin ? 1 : 0
64
64
  }
65
65
  const getInstitutionKey = () => {
66
- const instituitionKey = window.location.pathname.split('/')[2]
66
+ const instituitionKey = window.location.pathname.split('/')[1]
67
67
  if (!instituitionKey) {
68
68
  const localInstituitionKey = localStorage.getItem('institution_key')
69
69
  if (localInstituitionKey) {
@@ -90,12 +90,12 @@ function handleInstitutions(institutions) {
90
90
  if (institutions?.length === 1) {
91
91
  if (!insititutionKey) {
92
92
  window.location.replace(
93
- `${window.location.origin}/${urlTenantKey}/${institutions[0]?.code}`,
93
+ `${window.location.origin}/${institutions[0]?.code}`,
94
94
  )
95
95
  }
96
96
  if (insititutionKey !== institutions[0]?.code) {
97
97
  window.location.replace(
98
- `${window.location.origin}/${urlTenantKey}/${institutions[0]?.code}`,
98
+ `${window.location.origin}/${institutions[0]?.code}`,
99
99
  )
100
100
  }
101
101
  InstitutionsStore.update((s) => {
@@ -235,6 +235,7 @@ function useAuth({ permissionsEndpoint, loginUrl }: AuthParams): AuthResponse {
235
235
  s.isMasterInstitutionUser = res.data?.institutions
236
236
  ?.map((institution) => institution?.id)
237
237
  ?.includes(res?.data?.masterInstitutionUniqueId)
238
+ s.isHomePageEnabled = res.data?.isHomePageEnabled
238
239
  })
239
240
  AssetsStore.update((s) => {
240
241
  s.logo = res.data?.assets.logo
@@ -1,5 +1,5 @@
1
- import styled from 'styled-components'
2
1
  import { styled as muiStyled } from '@mui/material'
2
+ import styled from 'styled-components'
3
3
 
4
4
  export const headerHeight = '64px'
5
5
  export const sideNavWidth = '220px'
@@ -59,16 +59,29 @@ export const StyledMainContentContainer = muiStyled('main')(() => ({
59
59
  overflowY: 'auto',
60
60
 
61
61
  '&::-webkit-scrollbar': {
62
- width: '0.6em',
63
- height: '0.6em',
62
+ width: '0.4em',
63
+ height: '0.4em',
64
64
  },
65
65
 
66
66
  '&::-webkit-scrollbar-thumb': {
67
- backgroundColor: 'rgba(0,0,0, 0.3)',
67
+ backgroundColor: 'rgba(0, 0, 0, 0.2)',
68
68
  borderRadius: '3px',
69
-
70
69
  '&:hover': {
71
70
  background: 'rgba(0,0,0, 0.4)',
72
71
  },
73
72
  },
73
+
74
+ // '&::-webkit-scrollbar': {
75
+ // width: '0.6em',
76
+ // height: '0.6em',
77
+ // },
78
+
79
+ // '&::-webkit-scrollbar-thumb': {
80
+ // backgroundColor: 'rgba(0,0,0, 0.3)',
81
+ // borderRadius: '3px',
82
+
83
+ // '&:hover': {
84
+ // background: 'rgba(0,0,0, 0.4)',
85
+ // },
86
+ // },
74
87
  }))
@@ -2047,6 +2047,7 @@ interface IPermissionsStore {
2047
2047
  masterInstitutionId?: string
2048
2048
  isMasterInstitution: boolean
2049
2049
  isMasterInstitutionUser?: boolean
2050
+ isHomePageEnabled?: boolean
2050
2051
  }
2051
2052
 
2052
2053
  export const PermissionsStore = new Store<IPermissionsStore>({
@@ -2057,4 +2058,5 @@ export const PermissionsStore = new Store<IPermissionsStore>({
2057
2058
  masterInstitutionId: null,
2058
2059
  isMasterInstitution: false,
2059
2060
  isMasterInstitutionUser: false,
2061
+ isHomePageEnabled: false,
2060
2062
  })