@@ -3,7 +3,12 @@ import React from 'react'
3
3
4
4
import type { AvailableRoutes } from '@redwoodjs/router'
5
5
6
- type RegularSetProps = {
6
+ type SetProps < P > = ( P extends React . FC ? React . ComponentProps < P > : unknown ) & {
7
+ /**
8
+ * A react component that the children of the Set will be wrapped
9
+ * in (typically a Layout component)
10
+ */
11
+ wrap ?: P
7
12
/**
8
13
*`Routes` nested in a `<Set>` with `private` specified require
9
14
* authentication. When a user is not authenticated and attempts to visit
@@ -18,38 +23,6 @@ type RegularSetProps = {
18
23
* @deprecated Please use `<PrivateSet>` instead and specify this prop there
19
24
*/
20
25
unauthenticated ?: keyof AvailableRoutes
21
- }
22
-
23
- /**
24
- * A set containing public `<Route />`s
25
- */
26
- export function Set < WrapperProps > (
27
- props : CommonSetProps < WrapperProps > & RegularSetProps ,
28
- ) {
29
- // @MARK : Virtual Component, this is actually never rendered
30
- // See analyzeRoutes in utils.tsx, inside the isSetNode block
31
- return < > { props . children } </ >
32
- }
33
-
34
- type CommonSetProps < P > = ( P extends React . FC < any >
35
- ? React . ComponentProps < P >
36
- : P extends React . FC < any > [ ]
37
- ? React . ComponentProps < P [ 0 ] > &
38
- React . ComponentProps < P [ 1 ] > &
39
- React . ComponentProps < P [ 2 ] > &
40
- React . ComponentProps < P [ 3 ] > &
41
- React . ComponentProps < P [ 4 ] > &
42
- React . ComponentProps < P [ 5 ] > &
43
- React . ComponentProps < P [ 6 ] > &
44
- React . ComponentProps < P [ 7 ] > &
45
- React . ComponentProps < P [ 8 ] > &
46
- React . ComponentProps < P [ 9 ] >
47
- : unknown ) & {
48
- /**
49
- * A React component, or an array of React components, that the children of
50
- * the Set will be wrapped in (typically a Layout component and/or a context)
51
- */
52
- wrap ?: P
53
26
/**
54
27
* Route is permitted when authenticated and user has any of the provided
55
28
* roles such as "admin" or ["admin", "editor"]
@@ -63,13 +36,22 @@ type CommonSetProps<P> = (P extends React.FC<any>
63
36
whileLoadingPage ?: ( ) => ReactElement | null
64
37
}
65
38
39
+ /**
40
+ * A set containing public `<Route />`s
41
+ */
42
+ export function Set < WrapperProps > ( props : SetProps < WrapperProps > ) {
43
+ // @MARK : Virtual Component, this is actually never rendered
44
+ // See analyzeRoutes in utils.tsx, inside the isSetNode block
45
+ return < > { props . children } </ >
46
+ }
47
+
48
+ type PrivateSetProps < P > = Omit < SetProps < P > , 'private' | 'unauthenticated' > & {
49
+ /** The page name where a user will be redirected when not authenticated */
50
+ unauthenticated : keyof AvailableRoutes
51
+ }
52
+
66
53
/** @deprecated Please use `<PrivateSet>` instead */
67
- export function Private < WrapperProps > (
68
- props : CommonSetProps < WrapperProps > & {
69
- /** The page name where a user will be redirected when not authenticated */
70
- unauthenticated : keyof AvailableRoutes
71
- } ,
72
- ) {
54
+ export function Private < WrapperProps > ( props : PrivateSetProps < WrapperProps > ) {
73
55
// @MARK Virtual Component, this is actually never rendered
74
56
// See analyzeRoutes in utils.tsx, inside the isSetNode block
75
57
return < > { props . children } </ >
@@ -78,20 +60,15 @@ export function Private<WrapperProps>(
78
60
/**
79
61
* A set containing private `<Route />`s that require authentication to access
80
62
*/
81
- export function PrivateSet < WrapperProps > (
82
- props : CommonSetProps < WrapperProps > & {
83
- /** The page name where a user will be redirected when not authenticated */
84
- unauthenticated : keyof AvailableRoutes
85
- } ,
86
- ) {
63
+ export function PrivateSet < WrapperProps > ( props : PrivateSetProps < WrapperProps > ) {
87
64
// @MARK Virtual Component, this is actually never rendered
88
65
// See analyzeRoutes in utils.tsx, inside the isSetNode block
89
66
return < > { props . children } </ >
90
67
}
91
68
92
69
export const isSetNode = (
93
70
node : ReactNode ,
94
- ) : node is ReactElement < CommonSetProps < any > & RegularSetProps > => {
71
+ ) : node is ReactElement < SetProps < any > > => {
95
72
return (
96
73
React . isValidElement ( node ) &&
97
74
( node . type === Set || node . type === PrivateSet || node . type === Private ) &&
@@ -102,15 +79,13 @@ export const isSetNode = (
102
79
103
80
export const isPrivateSetNode = (
104
81
node : ReactNode ,
105
- ) : node is ReactElement <
106
- CommonSetProps < unknown > & { unauthenticated : keyof AvailableRoutes }
107
- > => {
82
+ ) : node is ReactElement < PrivateSetProps < unknown > > => {
108
83
return React . isValidElement ( node ) && node . type === PrivateSet
109
84
}
110
85
111
86
// Only identifies <Private> nodes, not <Set private> nodes
112
87
export const isPrivateNode = (
113
88
node : ReactNode ,
114
- ) : node is ReactElement < CommonSetProps < any > & RegularSetProps > => {
89
+ ) : node is ReactElement < SetProps < any > > => {
115
90
return React . isValidElement ( node ) && node . type === Private
116
91
}
0 commit comments