All files / client/components/User UserStatusBadge.tsx

0% Statements 0/9
0% Branches 0/4
0% Functions 0/1
0% Lines 0/8

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                                                                                     
import React, { FC } from 'react'
import { Badge } from 'reactstrap'
 
export const STATUS = {
  REGISTERED: 1,
  ACTIVE: 2,
  SUSPENDED: 3,
  DELETED: 4,
  INVITED: 5,
} as const
 
export const STATUS_COLORS = {
  [STATUS.REGISTERED]: 'info',
  [STATUS.ACTIVE]: 'success',
  [STATUS.SUSPENDED]: 'warning',
  [STATUS.DELETED]: 'danger',
  [STATUS.INVITED]: 'info',
} as const
 
export const STATUS_LABELS = {
  [STATUS.REGISTERED]: '承認待ち',
  [STATUS.ACTIVE]: 'Active',
  [STATUS.SUSPENDED]: 'Suspended',
  [STATUS.DELETED]: 'Deleted',
  [STATUS.INVITED]: '招待済み',
} as const
 
interface Props {
  user: {
    status: (typeof STATUS)[keyof typeof STATUS] // FIXME: I want `valueof` to replace this type with `valueof STATUS`
  }
}
 
const UserStatusBadge: FC<Props> = ({ user }) => {
  const status = user.status in Object.values(STATUS) ? user.status : null
  if (status === null) return null
  const color = STATUS_COLORS[status]
 
  return <Badge color={color}>{STATUS_LABELS[status]}</Badge>
}
 
export default UserStatusBadge