import {MessageInstance, MessageType} from "antd/lib/message/interface"; import {AxiosError, AxiosResponse} from "axios"; import {t} from "ttag"; import {Avatar} from "antd"; import { BankOutlined, ClockCircleOutlined, DeleteOutlined, DollarOutlined, IdcardOutlined, LockOutlined, ReloadOutlined, ShareAltOutlined, SignatureOutlined, SyncOutlined, ToolOutlined, UnlockOutlined, UserOutlined } from "@ant-design/icons"; import {Domain, Entity, EventAction} from "./api"; import vCard from "vcf"; import React from "react"; export const roleToAvatar = (e: { roles: string[] }) => : e.roles.includes('registrar') ? : e.roles.includes('technical') ? : e.roles.includes('administrative') ? : e.roles.includes('billing') ? : }/> export const rolesToColor = (roles: string[]) => roles.includes('registrant') ? 'green' : roles.includes('administrative') ? 'blue' : roles.includes('technical') ? 'orange' : roles.includes('registrar') ? 'purple' : roles.includes('sponsor') ? 'magenta' : roles.includes('billing') ? 'cyan' : 'default' export const actionToColor = (a: EventAction) => a === 'registration' ? 'green' : a === 'reregistration' ? 'cyan' : a === 'expiration' ? 'red' : a === 'deletion' ? 'magenta' : a === 'transfer' ? 'orange' : a === 'last changed' ? 'blue' : a === 'registrar expiration' ? 'red' : a === 'reinstantiation' ? 'purple' : a === 'enum validation expiration' ? 'red' : 'default' export const actionToIcon = (a: EventAction) => a === 'registration' ? : a === 'expiration' ? : a === 'transfer' ? : a === 'last changed' ? : a === 'deletion' ? : a === 'reregistration' ? : a === 'locked' ? : a === 'unlocked' ? : a === 'registrar expiration' ? : a === 'enum validation expiration' ? : a === 'reinstantiation' ? : undefined export const entityToName = (e: { entity: Entity }): string => { const jCard = vCard.fromJSON(e.entity.jCard) let name = e.entity.handle if (jCard.data.fn && !Array.isArray(jCard.data.fn) && jCard.data.fn.valueOf() !== '') name = jCard.data.fn.valueOf() return name } export const sortDomainEntities = (domain: Domain) => domain.entities.sort((e1, e2) => { const p = (r: string[]) => r.includes('registrant') ? 5 : r.includes('administrative') ? 4 : r.includes('billing') ? 3 : r.includes('registrar') ? 2 : 1 return p(e2.roles) - p(e1.roles) }) export function showErrorAPI(e: AxiosError, messageApi: MessageInstance): MessageType | undefined { const response = e.response as AxiosResponse const data = response.data if ('message' in data) { return messageApi.error(data.message as string) } if (!('detail' in data)) return const detail = data.detail as string if (response.status === 429) { const duration = response.headers['retry-after'] return messageApi.error(t`Please retry after ${duration} seconds`) } if (response.status.toString()[0] === '4') { return messageApi.warning(detail !== '' ? detail : t`An error occurred`) } return messageApi.error(detail !== '' ? detail : t`An error occurred`) }