Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import { memo } from 'react'; import { Badge, BadgeColor, BadgeHue, type BadgeProps } from '@allshares/studio-design-system'; import { assert } from '@amalia/ext/typescript'; import { UserRole, type UserContract } from '@amalia/tenants/users/types'; import { UserRoleLabel } from './UserRoleLabel'; export type UserRoleBadgeProps = Omit<BadgeProps, 'children' | 'variant'> & { readonly role: UserRole; readonly adminScopeId: UserContract['adminScopeId'] | null; }; export const UserRoleBadgeVariantRecord: Record<UserRole, BadgeProps['variant']> = { [UserRole.ADMIN]: BadgeHue.CYAN, [UserRole.READ_ONLY_ADMIN]: BadgeHue.CYAN, [UserRole.SCOPED_ADMIN]: BadgeHue.CYAN, [UserRole.SCOPED_READ_ONLY_ADMIN]: BadgeHue.CYAN, [UserRole.FINANCE]: BadgeHue.BROWN, [UserRole.MANAGER]: BadgeHue.MAGENTA, [UserRole.READ_ONLY_MANAGER]: BadgeHue.MAGENTA, [UserRole.EMPLOYEE]: BadgeColor.PRIMARY, [UserRole.READ_ONLY_EMPLOYEE]: BadgeColor.PRIMARY, } as const; export const UserRoleBadge = memo(function UserRoleBadge({ role, adminScopeId, size = 'medium', ...props }: UserRoleBadgeProps) { assert(role in UserRoleBadgeVariantRecord, `Invalid role: ${role}`); const badgeVariant = UserRoleBadgeVariantRecord[role]; return ( <Badge {...props} size={size} variant={badgeVariant} > <UserRoleLabel adminScopeId={adminScopeId} role={role} /> </Badge> ); }); |