@campxdev/shared 0.5.21 → 0.5.22
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/.eslintignore +4 -0
- package/.eslintrc.js +34 -0
- package/.prettierrc +10 -0
- package/exports.ts +7 -6
- package/package.json +64 -50
- package/publish.sh +2 -0
- package/src/assets/images/index.ts +8 -8
- package/src/components/Breadcrumbs.tsx +3 -3
- package/src/components/ChangePassword.tsx +147 -147
- package/src/components/DropDownButton.tsx +167 -163
- package/src/components/ErrorBoundary/ErrorBoundary.tsx +22 -22
- package/src/components/ErrorBoundary/ErrorFallback.tsx +215 -215
- package/src/components/ErrorBoundary/GlobalNetworkLoadingIndicator.tsx +6 -6
- package/src/components/ErrorBoundary/index.tsx +1 -1
- package/src/components/FullScreenLoader.tsx +15 -15
- package/src/components/HookForm/AutoCompleteSearch.tsx +0 -30
- package/src/components/HookForm/RadioGroup.tsx +1 -1
- package/src/components/IconButtons/Icons.tsx +1 -2
- package/src/components/Input/AutoCompleteSearch.tsx +0 -30
- package/src/components/Input/SingleSelect.tsx +0 -15
- package/src/components/Layout/Header/AppHeader.tsx +89 -89
- package/src/components/Layout/Header/AppsMenu.tsx +79 -79
- package/src/components/Layout/Header/CogWheelMenu.tsx +27 -27
- package/src/components/Layout/Header/UserBox.tsx +25 -25
- package/src/components/Layout/Header/applications.ts +79 -79
- package/src/components/Layout/Header/assets/index.ts +10 -10
- package/src/components/Layout/Header/styles.tsx +72 -72
- package/src/components/LayoutWrapper.tsx +6 -6
- package/src/components/LinearProgress.tsx +14 -14
- package/src/components/ListItemButton.tsx +79 -79
- package/src/components/LoginForm.tsx +86 -86
- package/src/components/MenuButton.tsx +88 -88
- package/src/components/ModalButtons/DialogButton.tsx +66 -66
- package/src/components/PageContent.tsx +10 -10
- package/src/components/PageNotFound.tsx +12 -12
- package/src/components/PopupConfirm/ConfirmContextProvider.tsx +28 -28
- package/src/components/PopupConfirm/PopupConfirm.tsx +27 -27
- package/src/components/PopupConfirm/useConfirm.ts +41 -41
- package/src/components/SideMenuHeader.tsx +15 -15
- package/src/components/SideNav.tsx +119 -119
- package/src/components/Spinner.tsx +14 -14
- package/src/components/TableComponent/ReactTable.tsx +256 -256
- package/src/components/TableComponent/RenderTableBody.tsx +56 -56
- package/src/components/TableComponent/index.tsx +171 -171
- package/src/components/TableComponent/react-table-config.d.ts +2 -3
- package/src/components/index.ts +54 -54
- package/src/config/axios.ts +50 -50
- package/src/config/axiosXTenant.ts +57 -0
- package/src/constants/isDevelopment.ts +2 -2
- package/src/contexts/LoginFormProvider.tsx +28 -28
- package/src/contexts/Providers.tsx +40 -40
- package/src/contexts/QueryClientProvider.tsx +15 -15
- package/src/hooks/index.ts +2 -2
- package/src/hooks/useAppInit.ts +23 -23
- package/src/hooks/useAuth.ts +78 -77
- package/src/layouts/Components/DashBoardMenu.tsx +77 -77
- package/src/layouts/Components/icons/index.tsx +32 -32
- package/src/layouts/Components/styles.tsx +23 -23
- package/src/permissions/PageWithPermission.tsx +9 -9
- package/src/permissions/PermissionDeniedPage.tsx +13 -13
- package/src/permissions/PermissionsStore.ts +303 -303
- package/src/shared-state/index.ts +3 -3
- package/src/theme/MuiThemeProvider.tsx +9 -9
- package/src/theme/theme.d.ts +72 -72
- package/src/utils/index.ts +7 -7
- package/src/utils/logout.ts +19 -19
- package/src/utils/withLocalization.tsx +8 -8
- package/src/utils/withRouteWrapper.tsx +20 -20
- package/src/utils/withSuspense.tsx +3 -3
|
@@ -1,186 +1,186 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
alpha,
|
|
3
|
+
Box,
|
|
4
|
+
IconButton,
|
|
5
|
+
ListItemIcon,
|
|
6
|
+
styled,
|
|
7
|
+
Table as MuiTable,
|
|
8
|
+
TableBody,
|
|
9
|
+
TableCell,
|
|
10
|
+
TableContainer,
|
|
11
|
+
TableHead,
|
|
12
|
+
TableRow,
|
|
13
|
+
Typography,
|
|
14
14
|
} from '@mui/material'
|
|
15
15
|
import _ from 'lodash'
|
|
16
|
-
import {useEffect, useState} from 'react'
|
|
16
|
+
import { useEffect, useState } from 'react'
|
|
17
17
|
import Spinner from '../Spinner'
|
|
18
|
-
import {SortAscIcon, SortDescIcon, SortIcon} from './Icons'
|
|
18
|
+
import { SortAscIcon, SortDescIcon, SortIcon } from './Icons'
|
|
19
19
|
import TableFooter from './TableFooter'
|
|
20
20
|
|
|
21
21
|
export interface ColumnProps {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
dataIndex: string
|
|
23
|
+
key: string
|
|
24
|
+
title: any
|
|
25
|
+
render?: (cellData: any, row: any, index: number) => any
|
|
26
|
+
textColor?: string
|
|
27
|
+
sort?: boolean
|
|
28
|
+
width?: string //pixels
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
interface TableProps {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
columns: Array<ColumnProps>
|
|
33
|
+
rowKey?: string
|
|
34
|
+
dataSource?: any[]
|
|
35
|
+
loading?: boolean
|
|
36
|
+
onRowClick?: (row: any) => void
|
|
37
|
+
pagination?: {
|
|
38
|
+
page: number
|
|
39
|
+
limit: number
|
|
40
|
+
totalCount: number
|
|
41
|
+
onChange: (v: number) => void
|
|
42
|
+
onChangeLimit?: (v: number) => void
|
|
43
|
+
}
|
|
44
|
+
onSort?: (sort: any) => void
|
|
45
|
+
dense?: boolean
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
type Order = 'asc' | 'desc' | ''
|
|
49
49
|
type Sort = {}
|
|
50
50
|
|
|
51
51
|
export default function Table({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
columns,
|
|
53
|
+
dataSource,
|
|
54
|
+
onRowClick,
|
|
55
|
+
pagination,
|
|
56
|
+
loading,
|
|
57
|
+
onSort,
|
|
58
|
+
dense = false,
|
|
59
59
|
}: TableProps) {
|
|
60
|
-
|
|
60
|
+
const [sort, setSort] = useState<Sort>({})
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
62
|
+
const handleSortClick = (sortBykey) => {
|
|
63
|
+
setSort((prev) => {
|
|
64
|
+
if (prev[sortBykey]) {
|
|
65
|
+
if (prev[sortBykey] === 'desc') return { ...prev, [sortBykey]: 'asc' }
|
|
66
|
+
if (prev[sortBykey] === 'asc') {
|
|
67
|
+
delete prev[sortBykey]
|
|
68
|
+
return { ...prev }
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
return {
|
|
72
|
+
...prev,
|
|
73
|
+
[sortBykey]: 'desc',
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!onSort) return
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
onSort({
|
|
83
|
+
sortBy: Object.keys(sort).join(','),
|
|
84
|
+
sortOrder: Object.keys(sort)
|
|
85
|
+
.map((item) => sort[item])
|
|
86
|
+
.join(','),
|
|
87
|
+
})
|
|
88
|
+
}, [sort])
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
90
|
+
return (
|
|
91
|
+
<TableContainer>
|
|
92
|
+
<>
|
|
93
|
+
<MuiTable>
|
|
94
|
+
<TableHead>
|
|
95
|
+
<TableRow>
|
|
96
|
+
{columns.map((col, index) => (
|
|
97
|
+
<TableCell
|
|
98
|
+
key={index}
|
|
99
|
+
sx={{
|
|
100
|
+
...(col?.width && {
|
|
101
|
+
width: col?.width,
|
|
102
|
+
}),
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
<>
|
|
106
|
+
<Box>{col.title}</Box>
|
|
107
|
+
</>
|
|
108
|
+
{col.sort && (
|
|
109
|
+
<IconButton onClick={() => handleSortClick(col.dataIndex)}>
|
|
110
|
+
<ListItemIcon>
|
|
111
|
+
{sort[col.dataIndex] === 'asc' ? (
|
|
112
|
+
<SortAscIcon />
|
|
113
|
+
) : sort[col.dataIndex] === 'desc' ? (
|
|
114
|
+
<SortDescIcon />
|
|
115
|
+
) : (
|
|
116
|
+
<SortIcon />
|
|
117
|
+
)}
|
|
118
|
+
</ListItemIcon>
|
|
119
|
+
</IconButton>
|
|
120
|
+
)}
|
|
121
|
+
</TableCell>
|
|
122
|
+
))}
|
|
123
|
+
</TableRow>
|
|
124
|
+
</TableHead>
|
|
125
|
+
{!loading ? (
|
|
126
|
+
<>
|
|
127
|
+
{dataSource?.length ? (
|
|
128
|
+
<TableBody>
|
|
129
|
+
{dataSource?.map((row, index) => (
|
|
130
|
+
<StyledTableRow
|
|
131
|
+
canRowClick={!!onRowClick}
|
|
132
|
+
hover={!!onRowClick}
|
|
133
|
+
key={index}
|
|
134
|
+
onClick={() => {
|
|
135
|
+
return onRowClick && onRowClick(row)
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
{columns.map((col, colIndex) => (
|
|
139
|
+
<TableCell
|
|
140
|
+
sx={{
|
|
141
|
+
color: col.textColor,
|
|
142
|
+
padding: dense ? '10px' : '15px',
|
|
143
|
+
}}
|
|
144
|
+
key={colIndex}
|
|
145
|
+
>
|
|
146
|
+
<>
|
|
147
|
+
{col?.render
|
|
148
|
+
? col.render(row[col.dataIndex], row, index)
|
|
149
|
+
: _.get(row, col.dataIndex)}
|
|
150
|
+
</>
|
|
151
|
+
</TableCell>
|
|
152
|
+
))}
|
|
153
|
+
</StyledTableRow>
|
|
154
|
+
))}
|
|
155
|
+
</TableBody>
|
|
156
|
+
) : (
|
|
157
|
+
<Box>
|
|
158
|
+
{dataSource && (
|
|
159
|
+
<Typography sx={{ padding: '10px' }}>
|
|
160
|
+
No Records Found !..
|
|
161
|
+
</Typography>
|
|
162
|
+
)}
|
|
163
|
+
</Box>
|
|
164
|
+
)}
|
|
165
|
+
</>
|
|
166
|
+
) : (
|
|
167
|
+
<Spinner />
|
|
168
|
+
)}
|
|
169
|
+
</MuiTable>
|
|
170
|
+
</>
|
|
171
|
+
<>
|
|
172
|
+
{pagination && (
|
|
173
|
+
<TableFooter
|
|
174
|
+
page={pagination.page}
|
|
175
|
+
limit={pagination.limit}
|
|
176
|
+
totalCount={pagination.totalCount}
|
|
177
|
+
handlePagination={pagination.onChange}
|
|
178
|
+
handlePageLimit={pagination.onChangeLimit}
|
|
179
|
+
/>
|
|
180
|
+
)}
|
|
181
|
+
</>
|
|
182
|
+
</TableContainer>
|
|
183
|
+
)
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
// const StyledSortButton = styled(IconButton)<{
|
|
@@ -209,13 +209,13 @@ export default function Table({
|
|
|
209
209
|
// }),
|
|
210
210
|
// }))
|
|
211
211
|
|
|
212
|
-
const StyledTableRow = styled(TableRow)<{canRowClick: boolean}>(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
212
|
+
const StyledTableRow = styled(TableRow)<{ canRowClick: boolean }>(
|
|
213
|
+
({ theme, canRowClick }) => ({
|
|
214
|
+
...(canRowClick && {
|
|
215
|
+
cursor: 'pointer',
|
|
216
|
+
'&.MuiTableRow-hover:hover': {
|
|
217
|
+
backgroundColor: alpha('#f2f2f2', 0.4),
|
|
218
|
+
},
|
|
219
|
+
}),
|
|
220
|
+
}),
|
|
221
221
|
)
|
|
@@ -51,9 +51,8 @@ import {
|
|
|
51
51
|
declare module 'react-table' {
|
|
52
52
|
// take this file as-is, or comment out the sections that don't apply to your plugin configuration
|
|
53
53
|
|
|
54
|
-
export interface TableOptions<
|
|
55
|
-
|
|
56
|
-
> extends UseExpandedOptions<D>,
|
|
54
|
+
export interface TableOptions<D extends Record<string, unknown>>
|
|
55
|
+
extends UseExpandedOptions<D>,
|
|
57
56
|
UseFiltersOptions<D>,
|
|
58
57
|
UseGlobalFiltersOptions<D>,
|
|
59
58
|
UseGroupByOptions<D>,
|
package/src/components/index.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import UploadFileDialog from
|
|
2
|
-
import Chips from
|
|
3
|
-
import ImageUpload from
|
|
4
|
-
import FloatingContainer from
|
|
5
|
-
import TabsContainer from
|
|
6
|
-
import { StyledTableContainer } from
|
|
7
|
-
import { SearchBar } from
|
|
8
|
-
import { DrawerButton, DialogButton } from
|
|
9
|
-
import DetailsGrid from
|
|
10
|
-
import AppHeader from
|
|
11
|
-
import MenuButton from
|
|
12
|
-
import StepsHeader from
|
|
13
|
-
import UploadDocument from
|
|
14
|
-
import { Table as StyledTable } from
|
|
15
|
-
import ErrorBoundary from
|
|
16
|
-
import FullScreenLoader from
|
|
17
|
-
import LoginForm from
|
|
18
|
-
import { SideMenuHeader } from
|
|
19
|
-
import SideNav from
|
|
20
|
-
import { ListItemButton } from
|
|
21
|
-
import LayoutWrapper from
|
|
22
|
-
import PageNotFound from
|
|
23
|
-
import ChangePassword from
|
|
24
|
-
import UploadButton from
|
|
25
|
-
import DialogWrapper from
|
|
26
|
-
export { default as Image } from
|
|
27
|
-
export { default as PageHeader } from
|
|
28
|
-
export { PageContent } from
|
|
29
|
-
export { default as ActionButton } from
|
|
30
|
-
export { default as Breadcrumbs } from
|
|
31
|
-
export { default as Table } from
|
|
32
|
-
export { default as Spinner } from
|
|
33
|
-
export { default as AutocompleteSearch } from
|
|
34
|
-
export { FullCalendarWrapper } from
|
|
35
|
-
export { default as JsonPreview } from
|
|
36
|
-
export { default as LabelValue } from
|
|
37
|
-
export { LinearProgress } from
|
|
38
|
-
export { default as MediaRow } from
|
|
39
|
-
export { default as NoDataIllustration } from
|
|
40
|
-
export { default as SwitchButton } from
|
|
41
|
-
export { default as Tabs } from
|
|
42
|
-
export { default as ToastContainer } from
|
|
43
|
-
export { default as Card } from
|
|
44
|
-
export { default as CardsGrid } from
|
|
45
|
-
export { default as DividerHeading } from
|
|
46
|
-
export { default as ReactTable } from
|
|
47
|
-
export { default as TableFooter } from
|
|
48
|
-
export { default as DropDownButton } from
|
|
49
|
-
export { default as useConfirm } from
|
|
1
|
+
import UploadFileDialog from './UploadFileDialog'
|
|
2
|
+
import Chips from './Chips'
|
|
3
|
+
import ImageUpload from './ImageUpload'
|
|
4
|
+
import FloatingContainer from './FloatingContainer'
|
|
5
|
+
import TabsContainer from './Tabs/TabsContainer'
|
|
6
|
+
import { StyledTableContainer } from './StyledTableContainer'
|
|
7
|
+
import { SearchBar } from './SearchBar'
|
|
8
|
+
import { DrawerButton, DialogButton } from './ModalButtons'
|
|
9
|
+
import DetailsGrid from './DetailsGrid'
|
|
10
|
+
import AppHeader from './Layout/Header'
|
|
11
|
+
import MenuButton from './MenuButton'
|
|
12
|
+
import StepsHeader from './StepsHeader'
|
|
13
|
+
import UploadDocument from './UploadDocument'
|
|
14
|
+
import { Table as StyledTable } from './Table'
|
|
15
|
+
import ErrorBoundary from './ErrorBoundary'
|
|
16
|
+
import FullScreenLoader from './FullScreenLoader'
|
|
17
|
+
import LoginForm from './LoginForm'
|
|
18
|
+
import { SideMenuHeader } from './SideMenuHeader'
|
|
19
|
+
import SideNav from './SideNav'
|
|
20
|
+
import { ListItemButton } from './ListItemButton'
|
|
21
|
+
import LayoutWrapper from './LayoutWrapper'
|
|
22
|
+
import PageNotFound from './PageNotFound'
|
|
23
|
+
import ChangePassword from './ChangePassword'
|
|
24
|
+
import UploadButton from './UploadButton'
|
|
25
|
+
import DialogWrapper from './DrawerWrapper/DialogWrapper'
|
|
26
|
+
export { default as Image } from './Image'
|
|
27
|
+
export { default as PageHeader } from './PageHeader'
|
|
28
|
+
export { PageContent } from './PageContent'
|
|
29
|
+
export { default as ActionButton } from './ActionButton'
|
|
30
|
+
export { default as Breadcrumbs } from './Breadcrumbs'
|
|
31
|
+
export { default as Table } from './TableComponent'
|
|
32
|
+
export { default as Spinner } from './Spinner'
|
|
33
|
+
export { default as AutocompleteSearch } from './AutocompleteSearch'
|
|
34
|
+
export { FullCalendarWrapper } from './FullCalendar/FullCalendarWrapper'
|
|
35
|
+
export { default as JsonPreview } from './JsonPreview'
|
|
36
|
+
export { default as LabelValue } from './LabelValue'
|
|
37
|
+
export { LinearProgress } from './LinearProgress'
|
|
38
|
+
export { default as MediaRow } from './MediaRow'
|
|
39
|
+
export { default as NoDataIllustration } from './NoDataIllustration'
|
|
40
|
+
export { default as SwitchButton } from './SwitchButton'
|
|
41
|
+
export { default as Tabs } from './Tabs/Tabs'
|
|
42
|
+
export { default as ToastContainer } from './ToastContainer'
|
|
43
|
+
export { default as Card } from './Card'
|
|
44
|
+
export { default as CardsGrid } from './CardsGrid'
|
|
45
|
+
export { default as DividerHeading } from './DividerHeading'
|
|
46
|
+
export { default as ReactTable } from './TableComponent/ReactTable'
|
|
47
|
+
export { default as TableFooter } from './TableComponent/TableFooter'
|
|
48
|
+
export { default as DropDownButton } from './DropDownButton'
|
|
49
|
+
export { default as useConfirm } from './PopupConfirm/useConfirm'
|
|
50
50
|
export {
|
|
51
51
|
UploadFileDialog,
|
|
52
52
|
Chips,
|
|
@@ -74,9 +74,9 @@ export {
|
|
|
74
74
|
ChangePassword,
|
|
75
75
|
UploadButton,
|
|
76
76
|
DialogWrapper,
|
|
77
|
-
}
|
|
77
|
+
}
|
|
78
78
|
|
|
79
|
-
export * from
|
|
80
|
-
export * from
|
|
81
|
-
export * from
|
|
82
|
-
export * from
|
|
79
|
+
export * from './UploadButton/types'
|
|
80
|
+
export * from './HookForm'
|
|
81
|
+
export * from './Input'
|
|
82
|
+
export * from './IconButtons'
|
package/src/config/axios.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
1
|
import Axios from 'axios'
|
|
2
2
|
import _ from 'lodash'
|
|
3
|
-
import {toast} from 'react-toastify'
|
|
3
|
+
import { toast } from 'react-toastify'
|
|
4
4
|
import Cookies from 'js-cookie'
|
|
5
|
-
import {NetworkStore} from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
|
|
6
|
-
import {isDevelopment} from '../constants'
|
|
5
|
+
import { NetworkStore } from '../components/ErrorBoundary/GlobalNetworkLoadingIndicator'
|
|
6
|
+
import { isDevelopment } from '../constants'
|
|
7
7
|
|
|
8
8
|
const sessionKey = Cookies.get('campx_session_key')
|
|
9
9
|
const clientId = window.location.pathname.split('/')[1] ?? 'campx_dev'
|
|
10
10
|
|
|
11
|
-
const formatParams = (params) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
export const formatParams = (params) => {
|
|
12
|
+
return Object.fromEntries(
|
|
13
|
+
Object.entries(params ?? {})?.map((i) => [
|
|
14
|
+
i[0],
|
|
15
|
+
i[1] === '__empty__' ? '' : i[1],
|
|
16
|
+
]),
|
|
17
|
+
)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
let axios = Axios.create({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
baseURL: process.env.REACT_APP_API_HOST,
|
|
22
|
+
withCredentials: true,
|
|
23
|
+
headers: {
|
|
24
|
+
'x-tenant-id': isDevelopment ? 'campx_dev' : clientId,
|
|
25
|
+
...(isDevelopment &&
|
|
26
|
+
sessionKey && {
|
|
27
|
+
campx_session_key: sessionKey,
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
axios.interceptors.request.use(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
function (config) {
|
|
34
|
+
const params = formatParams(config?.params)
|
|
35
|
+
NetworkStore.update((s) => {
|
|
36
|
+
s.loading = true
|
|
37
|
+
})
|
|
38
|
+
return { ...config, params }
|
|
39
|
+
},
|
|
40
|
+
function (error) {
|
|
41
|
+
NetworkStore.update((s) => {
|
|
42
|
+
s.loading = false
|
|
43
|
+
})
|
|
44
|
+
return Promise.reject(error)
|
|
45
|
+
},
|
|
46
46
|
)
|
|
47
47
|
|
|
48
48
|
axios.interceptors.response.use(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
function (response) {
|
|
50
|
+
NetworkStore.update((s) => {
|
|
51
|
+
s.loading = false
|
|
52
|
+
})
|
|
53
|
+
return response
|
|
54
|
+
},
|
|
55
|
+
function (err) {
|
|
56
|
+
NetworkStore.update((s) => {
|
|
57
|
+
s.loading = false
|
|
58
|
+
})
|
|
59
|
+
return Promise.reject(err)
|
|
60
|
+
},
|
|
61
61
|
)
|
|
62
62
|
|
|
63
63
|
export default axios
|
|
64
64
|
|
|
65
65
|
export const axiosErrorToast = (error: any, fallback?: string) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
const fallbackMessage = fallback ?? 'Something went wrong.'
|
|
67
|
+
const errorMessage =
|
|
68
|
+
typeof error?.response?.data?.message !== 'string'
|
|
69
|
+
? error?.response?.data?.message?.join('\n') ?? fallbackMessage
|
|
70
|
+
: error?.response?.data?.message
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
return toast.error(errorMessage)
|
|
73
73
|
}
|