@contember/interface 2.1.0-beta.2 → 2.1.0-rc.2
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/dist/development/src/components/binding/RedirectOnPersist.cjs +19 -10
- package/dist/development/src/components/binding/RedirectOnPersist.cjs.map +1 -1
- package/dist/development/src/components/binding/RedirectOnPersist.js +21 -12
- package/dist/development/src/components/binding/RedirectOnPersist.js.map +1 -1
- package/dist/production/src/components/binding/RedirectOnPersist.cjs +15 -10
- package/dist/production/src/components/binding/RedirectOnPersist.cjs.map +1 -1
- package/dist/production/src/components/binding/RedirectOnPersist.js +17 -12
- package/dist/production/src/components/binding/RedirectOnPersist.js.map +1 -1
- package/dist/types/components/binding/RedirectOnPersist.d.ts +9 -4
- package/dist/types/components/binding/RedirectOnPersist.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/binding/RedirectOnPersist.tsx +25 -12
package/package.json
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import { useEntityPersistSuccess } from '@contember/react-binding'
|
|
2
|
-
import { RequestParameters, useRedirect } from '@contember/react-routing'
|
|
3
|
-
import { RoutingLinkTarget } from '@contember/react-routing'
|
|
1
|
+
import { Component, useEntityPersistSuccess } from '@contember/react-binding'
|
|
2
|
+
import { RequestParameters, RoutingLinkFields, RoutingLinkTarget, useRedirect } from '@contember/react-routing'
|
|
4
3
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (options.successType !== 'justSuccess') {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
redirect(to, parameters)
|
|
12
|
-
})
|
|
13
|
-
return null
|
|
4
|
+
export interface RedirectOnPersistProps {
|
|
5
|
+
to: RoutingLinkTarget
|
|
6
|
+
parameters?: RequestParameters
|
|
14
7
|
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Redirects to the given target after a successful persist. Exposes a static
|
|
11
|
+
* render so the fields referenced by the routing target are registered during
|
|
12
|
+
* the static analysis pass, just like `Link`.
|
|
13
|
+
*/
|
|
14
|
+
export const RedirectOnPersist = Component<RedirectOnPersistProps>(
|
|
15
|
+
({ to, parameters }) => {
|
|
16
|
+
const redirect = useRedirect()
|
|
17
|
+
useEntityPersistSuccess((getEntity, options) => {
|
|
18
|
+
if (options.successType !== 'justSuccess') {
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
redirect(to, parameters)
|
|
22
|
+
})
|
|
23
|
+
return null
|
|
24
|
+
},
|
|
25
|
+
props => <RoutingLinkFields to={props.to} />,
|
|
26
|
+
'RedirectOnPersist',
|
|
27
|
+
)
|