@campxdev/shared 0.5.0 → 0.5.1
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
|
@@ -14,6 +14,8 @@ import {useState} from 'react'
|
|
|
14
14
|
import {useForm} from 'react-hook-form'
|
|
15
15
|
import {FormTextField} from './HookForm'
|
|
16
16
|
|
|
17
|
+
const developmentOrigin = window.location.origin + '/campx_dev'
|
|
18
|
+
|
|
17
19
|
export const StyledTextField = styled(FormTextField)(({theme}) => ({
|
|
18
20
|
'& .MuiInputBase-root': {
|
|
19
21
|
minHeight: '60px',
|
|
@@ -42,7 +44,7 @@ export function LoginForm() {
|
|
|
42
44
|
data: values,
|
|
43
45
|
})
|
|
44
46
|
Cookies.set('campx_session_key', res.data.cookie)
|
|
45
|
-
window.location.href =
|
|
47
|
+
window.location.href = developmentOrigin
|
|
46
48
|
} catch (err) {
|
|
47
49
|
// eslint-disable-next-line no-console
|
|
48
50
|
console.log(err)
|
package/src/config/axios.ts
CHANGED
|
@@ -3,11 +3,10 @@ import _ from 'lodash'
|
|
|
3
3
|
import {toast} from 'react-toastify'
|
|
4
4
|
import Cookies from 'js-cookie'
|
|
5
5
|
import {NetworkStore} from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
|
|
6
|
+
import {isDevelopment} from '../constants'
|
|
6
7
|
|
|
7
|
-
const isDevelopment =
|
|
8
|
-
process.env.NODE_ENV === 'development' ||
|
|
9
|
-
window.location.origin.split('.').slice(-2).join('.') === 'campx.dev'
|
|
10
8
|
const sessionKey = Cookies.get('campx_session_key')
|
|
9
|
+
const clientId = window.location.pathname.split('/')[0] ?? 'campx_dev'
|
|
11
10
|
|
|
12
11
|
const formatParams = (params) => {
|
|
13
12
|
return Object.fromEntries(
|
|
@@ -21,12 +20,13 @@ const formatParams = (params) => {
|
|
|
21
20
|
let axios = Axios.create({
|
|
22
21
|
baseURL: process.env.REACT_APP_API_HOST,
|
|
23
22
|
withCredentials: true,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
headers: {
|
|
24
|
+
'x-tenent-id': isDevelopment ? 'campx_dev' : clientId,
|
|
25
|
+
...(isDevelopment &&
|
|
26
|
+
sessionKey && {
|
|
27
27
|
campx_session_key: sessionKey,
|
|
28
|
-
},
|
|
29
|
-
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
axios.interceptors.request.use(
|
|
@@ -7,10 +7,18 @@ import QueryClientProvider from './QueryClientProvider'
|
|
|
7
7
|
import DialogProvider from '../components/DrawerWrapper/DrawerWrapper'
|
|
8
8
|
import {ToastContainer} from '../components'
|
|
9
9
|
import LoginFormProvider from './LoginFormProvider'
|
|
10
|
+
import {ReactNode} from 'react'
|
|
11
|
+
import {isDevelopment} from '../constants'
|
|
10
12
|
|
|
11
|
-
export default function Providers({
|
|
13
|
+
export default function Providers({
|
|
14
|
+
children,
|
|
15
|
+
basename,
|
|
16
|
+
}: {
|
|
17
|
+
children: ReactNode
|
|
18
|
+
basename: string
|
|
19
|
+
}) {
|
|
12
20
|
return (
|
|
13
|
-
<BrowserRouter>
|
|
21
|
+
<BrowserRouter basename={isDevelopment ? 'campx_dev' : basename}>
|
|
14
22
|
<QueryClientProvider>
|
|
15
23
|
<MuiThemeProvider>
|
|
16
24
|
<DialogProvider>
|