Skip to content

Commit

Permalink
feat: redirect to first resource if dashboard doesnt exist (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
foyarash authored Mar 21, 2024
1 parent 2325ddd commit f6ba512
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-chicken-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": minor
---

feat: redirect to first resource if dashboard doesnt exist
20 changes: 17 additions & 3 deletions packages/next-admin/src/components/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
export type DashboardProps = {};
"use client";
import { useConfig } from "../context/ConfigContext";
import { useRouterInternal } from "../hooks/useRouterInternal";
import { ModelName } from "../types";

const Dashboard = ({}: DashboardProps) => {
return <div>Dashboard</div>;
export type DashboardProps = {
resources: ModelName[];
};

const Dashboard = ({ resources }: DashboardProps) => {
const { basePath } = useConfig();
const { router } = useRouterInternal();

router.replace({
pathname: `${basePath}/${resources[0]}`,
});

return null;
};

export default Dashboard;
2 changes: 1 addition & 1 deletion packages/next-admin/src/components/NextAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function NextAdmin({

if (resources) {
if (dashboard && typeof dashboard === "function") return dashboard();
return dashboard || <Dashboard />;
return dashboard || <Dashboard resources={resources} />;
}
};

Expand Down

0 comments on commit f6ba512

Please sign in to comment.