-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from Dias999/feature/packages_structure
Feature/packages structure
- Loading branch information
Showing
8 changed files
with
241 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
packages/react-navigation/src/components/ChildRoutes.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import React, { Children, ReactElement, ReactNode } from 'react'; | ||
import { useRoutes } from 'react-router-dom'; | ||
import { | ||
DrawerItemProps, | ||
AuthModuleProps, | ||
DrawerProps, | ||
NavbarProps, | ||
} from '@concepta/react-material-ui/'; | ||
|
||
import DefaultRoute from './DefaultRoute'; | ||
import AuthRoute from './AuthRoute'; | ||
|
||
export type AuthModule = { | ||
signIn?: AuthModuleProps; | ||
signUp?: AuthModuleProps; | ||
forgotPassword?: AuthModuleProps; | ||
resetPassword?: AuthModuleProps; | ||
}; | ||
|
||
type ChildRoutesProps = { | ||
children: ReactElement[]; | ||
useNavigateFilter?: boolean; | ||
authModuleProps?: AuthModule; | ||
drawerProps?: DrawerProps; | ||
navbarProps?: NavbarProps; | ||
renderAppBar?: ( | ||
menuItems: DrawerItemProps[], | ||
children: ReactNode, | ||
) => ReactNode; | ||
renderSignIn?: (home: string) => ReactNode; | ||
renderSignUp?: (home: string) => ReactNode; | ||
renderForgotPassword?: (home: string) => ReactNode; | ||
renderResetPassword?: (home: string) => ReactNode; | ||
}; | ||
|
||
const ChildRoutes = ({ | ||
children, | ||
useNavigateFilter, | ||
authModuleProps, | ||
drawerProps, | ||
navbarProps, | ||
renderAppBar, | ||
renderSignIn, | ||
renderSignUp, | ||
renderForgotPassword, | ||
renderResetPassword, | ||
}: ChildRoutesProps) => { | ||
const items = Children.map(children, (child) => { | ||
// This validation is needed so `showDrawerItem` | ||
// can be `true` by default | ||
if ( | ||
child.props.showDrawerItem !== undefined && | ||
!child.props.showDrawerItem | ||
) { | ||
return null; | ||
} | ||
|
||
return { | ||
id: child.props.id, | ||
text: child.props.name, | ||
icon: child.props.icon, | ||
}; | ||
}).filter((item) => !!item); | ||
|
||
const home = children[0].props.id; | ||
|
||
const routesChildren = useRoutes([ | ||
{ | ||
path: 'sign-in', | ||
element: renderSignIn ? ( | ||
renderSignIn(home) | ||
) : ( | ||
<AuthRoute | ||
home={home} | ||
moduleProps={authModuleProps?.signIn} | ||
route="signIn" | ||
/> | ||
), | ||
}, | ||
{ | ||
path: 'sign-up', | ||
element: renderSignUp ? ( | ||
renderSignUp(home) | ||
) : ( | ||
<AuthRoute | ||
home={home} | ||
moduleProps={authModuleProps?.signUp} | ||
route="signUp" | ||
/> | ||
), | ||
}, | ||
{ | ||
path: 'forgot-password', | ||
element: renderForgotPassword ? ( | ||
renderForgotPassword(home) | ||
) : ( | ||
<AuthRoute | ||
home={home} | ||
moduleProps={authModuleProps?.forgotPassword} | ||
route={'forgotPassword'} | ||
/> | ||
), | ||
}, | ||
{ | ||
path: 'reset-password', | ||
element: renderResetPassword ? ( | ||
renderResetPassword(home) | ||
) : ( | ||
<AuthRoute | ||
home={home} | ||
moduleProps={authModuleProps?.resetPassword} | ||
route="resetPassword" | ||
/> | ||
), | ||
}, | ||
...Children.map(children, (child) => ({ | ||
path: child.props.id, | ||
element: ( | ||
<DefaultRoute | ||
renderAppBar={renderAppBar} | ||
isUnprotected={child.props.isUnprotected} | ||
useNavigateFilter={useNavigateFilter} | ||
resource={child.props.id} | ||
name={child.props.name} | ||
showAppBar={child.props.showAppBar} | ||
module={child.props.module} | ||
page={child.props.page} | ||
items={items} | ||
drawerProps={drawerProps} | ||
navbarProps={navbarProps} | ||
/> | ||
), | ||
})), | ||
]); | ||
|
||
return routesChildren; | ||
}; | ||
|
||
export default ChildRoutes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import Router from './components/Router'; | ||
import ChildRoutes from './components/ChildRoutes'; | ||
import Resource from './components/Resource'; | ||
|
||
export { Router, Resource }; | ||
export { Router, ChildRoutes, Resource }; |
Oops, something went wrong.