admin_ruspet/src/components/ui/StatusBadge.tsx

32 lines
884 B
TypeScript

import { Badge, type BadgeProps } from '@mantine/core'
import { APPROVAL_STATUS, DECISION_STATUS, REVOCATION_STATUS, STEP_STATUS, TASK_STATUS, USER_STATUS } from './statuses'
const MAPS = {
approval: APPROVAL_STATUS,
task: TASK_STATUS,
user: USER_STATUS,
step: STEP_STATUS,
decision: DECISION_STATUS,
revocation: REVOCATION_STATUS,
}
interface Props {
kind: keyof typeof MAPS
status: string
size?: BadgeProps['size']
}
export function StatusBadge({ kind, status, size = 'md' }: Props) {
const meta = MAPS[kind][status]
return (
<Badge variant="dot" color={meta?.color ?? 'gray'} size={size}>
{meta?.label ?? status}
</Badge>
)
}
export function userStatusOf(u: { is_blocked?: boolean; is_fired?: boolean }) {
if (u.is_fired) return 'fired'
if (u.is_blocked) return 'blocked'
return 'active'
}