DEV Community

Kamran Khan
Kamran Khan

Posted on

My dashboard's "recent users" section is the admin table with the buttons turned off

On my dashboard, admins see a "Recent users" section under the stat cards. It is not a new component. It is the same UsersTable the admin Users page uses, rendered with dead handlers:

<UsersTable users={recentUsers} onEdit={() => {}} onDelete={() => {}} />
Enter fullscreen mode Exit fullscreen mode

UsersTable is a dumb component: it takes a list and two callbacks. Hand it real callbacks and you get the admin table. Hand it no-ops and the edit/delete buttons fire into the void, so it renders as a read-only list. Same markup, same columns, zero extra code.

The data comes from the same endpoint too:

client.get('/users', { params: { per_page: 5 } })
Enter fullscreen mode Exit fullscreen mode

One honest note: my backend index() is User::query()->latest()->paginate(15), so it currently ignores per_page and returns the first page of 15, newest first. The param is there for when I wire it up server-side. What matters is that the newest-first ordering makes page one the recent list for free — the "recent users" section is literally the same data the admin page shows, just displayed on the dashboard. And only admins fetch it: the whole section sits behind the isAdmin gate, while regular users get a getting-started card instead.

The point is boring on purpose. The dashboard did not need a second table component, a second fetch shape, or a second set of columns. It needed one dumb component used twice, with the buttons switched off the second time.

This is one of the reuse patterns I bake into my Laravel + React SaaS starter kit — small components with honest props instead of near-duplicate ones: https://kamranofficial.gumroad.com/l/mhekoig

Top comments (0)