Skip to content

Commit

Permalink
Merge pull request #183 from brunomous/feature/custom-resource-render
Browse files Browse the repository at this point in the history
Add page prop to DefaultRoute
  • Loading branch information
andreneto97 authored Aug 21, 2024
2 parents 3b919e1 + 286ed18 commit b19055a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const AuthFormSubmodule = (props: AuthFormSubmoduleProps) => {
const [formData, setFormData] = useState<Record<string, unknown>>({});

const searchParams = new URLSearchParams(window.location.search);
const passcode = '';
const passcode = searchParams?.get('token');

const { post, patch, put } = useDataProvider();
const { doLogin, isPending: isLoadingSignIn } = useAuth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
SxProps,
} from '@mui/material';
import EditIcon from '@mui/icons-material/Edit';
import DeleteIcon from '@mui/icons-material/Edit';
import DeleteIcon from '@mui/icons-material/Delete';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import AddIcon from '@mui/icons-material/Add';
import useDataProvider, { useQuery } from '@concepta/react-data-provider';
Expand Down
38 changes: 22 additions & 16 deletions packages/react-navigation/src/components/DefaultRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { ModuleProps } from '@concepta/react-material-ui/dist/modules/crud';
type DefaultRouteProps = {
resource: string;
name: string;
module: ModuleProps;
module?: ModuleProps;
page?: ReactNode;
items: DrawerItemProps[];
renderAppBar?: (
menuItems: DrawerItemProps[],
Expand All @@ -20,6 +21,7 @@ const DefaultRoute = ({
resource,
name,
module,
page,
items,
renderAppBar,
}: DefaultRouteProps) => {
Expand All @@ -33,31 +35,35 @@ const DefaultRoute = ({
},
}));

let renderedChildren = null;

if (page) {
renderedChildren = page;
}

if (module) {
renderedChildren = (
<CrudModule
{...module}
resource={resource}
title={name}
navigate={navigate}
/>
);
}

if (renderAppBar) {
return (
<ProtectedRoute>
{renderAppBar(
menuItems,
<CrudModule
{...module}
resource={resource}
title={name}
navigate={navigate}
/>,
)}
{renderAppBar(menuItems, renderedChildren)}
</ProtectedRoute>
);
}

return (
<ProtectedRoute>
<AppBarContainer menuItems={menuItems}>
<CrudModule
{...module}
resource={resource}
title={name}
navigate={navigate}
/>
{renderedChildren}
</AppBarContainer>
</ProtectedRoute>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/react-navigation/src/components/Resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ type ResourceProps = {
id: string;
name: string;
icon: ReactNode;
module: Partial<ModuleProps>;
module?: Partial<ModuleProps>;
page?: ReactNode;
};

const Resource = ({ id }: ResourceProps) => {
Expand Down
1 change: 1 addition & 0 deletions packages/react-navigation/src/components/RoutesRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const RoutesRoot = ({ routes, items, renderAppBar }: RoutesRootProps) => {
name={child.props.name}
items={items}
module={child.props.module}
page={child.props.page}
/>
}
/>
Expand Down

0 comments on commit b19055a

Please sign in to comment.