@@ -7,13 +7,19 @@ import { Button } from "@/components/ui/button";
77import { permit } from "@/features/authentication/server" ;
88import type { RoutePermission } from "@/features/authentication/types" ;
99import { GrammaticalCase , declineNoun } from "@/features/polish" ;
10- import { getManagingResourceLabel } from "@/features/resources" ;
11- import type { RoutableResource } from "@/features/resources/types" ;
10+ import {
11+ getManagingResourceLabel ,
12+ getResourceMetadata ,
13+ } from "@/features/resources" ;
14+ import type {
15+ DisplayableResource ,
16+ RoutableResource ,
17+ } from "@/features/resources/types" ;
1218import { cn } from "@/lib/utils" ;
1319import { toTitleCase } from "@/utils" ;
1420
1521export async function DashboardButton ( {
16- icon : Icon ,
22+ icon,
1723 variant = "default" ,
1824 className,
1925 href : hrefOverride ,
@@ -22,27 +28,28 @@ export async function DashboardButton({
2228 longLabel = false ,
2329 preserveCase = false ,
2430} : VariantProps < typeof Button > & {
25- icon : LucideIcon ;
2631 className ?: string ;
2732} & (
2833 | {
2934 href ?: Route ;
3035 label ?: string ;
31- resource : RoutableResource ;
36+ icon ?: LucideIcon ;
37+ resource : RoutableResource & DisplayableResource ;
3238 longLabel ?: boolean ;
3339 preserveCase ?: boolean ;
3440 }
3541 | {
3642 href : Route & RoutePermission ;
3743 label : string ;
44+ icon : LucideIcon ;
3845 resource ?: never ;
3946 longLabel ?: never ;
4047 preserveCase ?: never ;
4148 }
4249 ) ) {
43- const [ route , label ] =
50+ const [ route , label , Icon ] =
4451 resource == null
45- ? [ hrefOverride , labelOverride ]
52+ ? [ hrefOverride , labelOverride , icon ]
4653 : [
4754 `/${ resource } ` as const ,
4855 longLabel
@@ -52,7 +59,13 @@ export async function DashboardButton({
5259 case : GrammaticalCase . Nominative ,
5360 plural : true ,
5461 } ) ) ,
62+ icon ?? getResourceMetadata ( resource ) . icon ,
5563 ] ;
64+ if ( Icon == null ) {
65+ throw new Error (
66+ `Displayable resource ${ resource ?? route } has no icon defined in metadata` ,
67+ ) ;
68+ }
5669
5770 const hasPermission = await permit ( route ) ;
5871 if ( ! hasPermission ) {
0 commit comments