@campxdev/shared 0.3.3 → 0.3.5
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/ErrorBoundary/ErrorBoundary.tsx +15 -2
- package/src/components/ErrorBoundary/ErrorFallback.tsx +1 -1
- package/src/components/PageContent.tsx +13 -10
- package/src/components/PopupConfirm/ConfirmContextProvider.tsx +33 -15
- package/src/components/PopupConfirm/useConfirm.ts +41 -41
- package/src/utils/index.ts +6 -5
- package/src/utils/withLocalization.tsx +11 -0
package/package.json
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
|
+
import {ReactNode} from 'react'
|
|
1
2
|
import {ErrorBoundary as ReactErrorBoundary} from 'react-error-boundary'
|
|
2
3
|
import {QueryErrorResetBoundary} from 'react-query'
|
|
4
|
+
import {useLocation} from 'react-router-dom'
|
|
3
5
|
import ErrorFallback from './ErrorFallback'
|
|
4
6
|
|
|
5
|
-
export default function ErrorBoundary({
|
|
7
|
+
export default function ErrorBoundary({
|
|
8
|
+
children,
|
|
9
|
+
resetKey,
|
|
10
|
+
}: {
|
|
11
|
+
children: ReactNode
|
|
12
|
+
resetKey?: string
|
|
13
|
+
}) {
|
|
14
|
+
const location = useLocation()
|
|
6
15
|
return (
|
|
7
16
|
<QueryErrorResetBoundary>
|
|
8
17
|
{({reset}) => (
|
|
9
|
-
<ReactErrorBoundary
|
|
18
|
+
<ReactErrorBoundary
|
|
19
|
+
key={resetKey ?? location?.pathname}
|
|
20
|
+
fallbackRender={ErrorFallback}
|
|
21
|
+
onReset={reset}
|
|
22
|
+
>
|
|
10
23
|
{children}
|
|
11
24
|
</ReactErrorBoundary>
|
|
12
25
|
)}
|
|
@@ -23,7 +23,7 @@ export default function ErrorFallback({error, resetErrorBoundary}) {
|
|
|
23
23
|
return (
|
|
24
24
|
<Box sx={{marginTop: '16px', padding: '16px'}}>
|
|
25
25
|
<StyledAlert severity='error'>
|
|
26
|
-
{error?.message}
|
|
26
|
+
{error?.response?.data?.message ?? error?.message}
|
|
27
27
|
<Button
|
|
28
28
|
className='retryBtn'
|
|
29
29
|
onClick={() => resetErrorBoundary()}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import styled from '
|
|
1
|
+
import {Box, styled} from '@mui/material'
|
|
2
|
+
import ErrorBoundary from './ErrorBoundary'
|
|
2
3
|
|
|
3
|
-
const StyledPageContent = styled
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const StyledPageContent = styled(Box)(() => ({
|
|
5
|
+
paddingLeft: '25px',
|
|
6
|
+
paddingRight: '25px',
|
|
7
|
+
marginTop: '16px',
|
|
8
|
+
paddingBottom: '3rem',
|
|
9
|
+
}))
|
|
9
10
|
|
|
10
11
|
export function PageContent(props) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
return (
|
|
13
|
+
<StyledPageContent style={props.style}>
|
|
14
|
+
<ErrorBoundary>{props.children}</ErrorBoundary>
|
|
15
|
+
</StyledPageContent>
|
|
16
|
+
)
|
|
14
17
|
}
|
|
@@ -1,22 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {createContext, ReactNode, useState} from 'react'
|
|
2
2
|
import PopupConfirm from './PopupConfirm'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
interface ConfirmContextProps {
|
|
5
|
+
confirm: {
|
|
6
|
+
prompt: ReactNode
|
|
7
|
+
isOpen: boolean
|
|
8
|
+
proceed: () => void
|
|
9
|
+
cancel: () => void
|
|
10
|
+
}
|
|
11
|
+
setConfirm: any
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ConfirmContext = createContext<ConfirmContextProps>({
|
|
15
|
+
confirm: {
|
|
16
|
+
cancel: () => {},
|
|
17
|
+
proceed: () => {},
|
|
18
|
+
prompt: 'Are you sure?',
|
|
19
|
+
isOpen: false,
|
|
20
|
+
},
|
|
21
|
+
setConfirm: () => {},
|
|
22
|
+
})
|
|
5
23
|
|
|
6
|
-
const ConfirmContextProvider = ({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
24
|
+
const ConfirmContextProvider = ({children}) => {
|
|
25
|
+
const [confirm, setConfirm] = useState({
|
|
26
|
+
prompt: '',
|
|
27
|
+
isOpen: false,
|
|
28
|
+
proceed: null,
|
|
29
|
+
cancel: null,
|
|
30
|
+
})
|
|
13
31
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
32
|
+
return (
|
|
33
|
+
<ConfirmContext.Provider value={{confirm, setConfirm}}>
|
|
34
|
+
{children}
|
|
35
|
+
<PopupConfirm />
|
|
36
|
+
</ConfirmContext.Provider>
|
|
37
|
+
)
|
|
20
38
|
}
|
|
21
39
|
|
|
22
40
|
export default ConfirmContextProvider
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { useContext, useEffect, useState
|
|
2
|
-
import {
|
|
1
|
+
import {ReactNode, useContext, useEffect, useState} from 'react'
|
|
2
|
+
import {ConfirmContext} from './ConfirmContextProvider'
|
|
3
3
|
|
|
4
4
|
export default function useConfirm(): {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
isConfirmed: (prompt?: string) => Promise<boolean>
|
|
6
|
+
prompt?: ReactNode
|
|
7
|
+
isOpen?: boolean
|
|
8
|
+
proceed?: () => void
|
|
9
|
+
cancel?: () => void
|
|
10
10
|
} {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const {confirm, setConfirm} = useContext(ConfirmContext)
|
|
12
|
+
const [needsCleanup, setNeedsCleanup] = useState(false)
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
14
|
+
const isConfirmed = (prompt) => {
|
|
15
|
+
setNeedsCleanup(true)
|
|
16
|
+
const promise = new Promise((resolve, reject) => {
|
|
17
|
+
setConfirm({
|
|
18
|
+
prompt,
|
|
19
|
+
isOpen: true,
|
|
20
|
+
proceed: resolve,
|
|
21
|
+
cancel: reject,
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
return promise.then(
|
|
25
|
+
() => {
|
|
26
|
+
setConfirm({...confirm, isOpen: false})
|
|
27
|
+
return true
|
|
28
|
+
},
|
|
29
|
+
() => {
|
|
30
|
+
setConfirm({...confirm, isOpen: false})
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
return () => {
|
|
38
|
+
if (confirm.cancel && needsCleanup) {
|
|
39
|
+
confirm.cancel()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, [confirm, needsCleanup])
|
|
43
|
+
return {
|
|
44
|
+
...confirm,
|
|
45
|
+
isConfirmed,
|
|
46
|
+
}
|
|
47
47
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export {default as getUrlParams} from './getUrlParams'
|
|
2
|
+
export {default as arrayPadEnd} from './arrayPadEnd'
|
|
3
|
+
export {default as romanize} from './romanize'
|
|
4
4
|
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
5
|
+
export {default as withRouteWrapper} from './withRouteWrapper'
|
|
6
|
+
export {default as withSuspense} from './withSuspense'
|
|
7
|
+
export {default as withLocalization} from './withLocalization'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {LocalizationProvider} from '@mui/x-date-pickers'
|
|
2
|
+
import {AdapterMoment} from '@mui/x-date-pickers/AdapterMoment'
|
|
3
|
+
import {ReactNode} from 'react'
|
|
4
|
+
|
|
5
|
+
export default function withLocalization(component: ReactNode) {
|
|
6
|
+
return (
|
|
7
|
+
<LocalizationProvider dateAdapter={AdapterMoment}>
|
|
8
|
+
{component}
|
|
9
|
+
</LocalizationProvider>
|
|
10
|
+
)
|
|
11
|
+
}
|