import { FunctionComponent } from 'react' import dayjs from 'dayjs' import relativeTime from 'dayjs/plugin/relativeTime' import styled from '@emotion/styled' import { ClockIcon, DeviceMobileIcon, MailIcon } from '@heroicons/react/outline' import { TelegramIcon } from './icons' import { abbreviateAddress } from '../utils' import { LinkButton } from './Button' import { Alert } from '../stores/useAlertsStore' dayjs.extend(relativeTime) const StyledDiv = styled.div` font-size: 0.75rem; ` interface AlertItemProps { alert: Alert isLarge?: boolean setOpenAlertModal?: (x) => void setReactivateAlertData?: (x) => void } const AlertItem: FunctionComponent = ({ alert, isLarge = false, setOpenAlertModal, setReactivateAlertData, }) => { const reactivateAlertData = !alert.open ? { acc: alert.acc, alertProvider: alert.alertProvider, collateralRatioThresh: alert.collateralRatioThresh, } : null const handleReactivate = () => { setOpenAlertModal(true) setReactivateAlertData(reactivateAlertData) } return (
{alert.alertProvider === 'sms' ? ( ) : alert.alertProvider === 'mail' ? ( ) : ( )}
{alert.alertProvider === 'sms' ? 'SMS' : alert.alertProvider === 'mail' ? 'E-mail' : 'Telegram'}{' '} below {alert.collateralRatioThresh}% {isLarge ? (
{dayjs(alert.timestamp).fromNow()}
) : null}
Acc: {abbreviateAddress(alert.acc)}
{alert.open ? ( Active ) : (
Triggered{' '} {alert.triggeredTimestamp ? dayjs(alert.triggeredTimestamp).fromNow() : null} {isLarge ? ( handleReactivate()} > Re-activate ) : null}
)}
) } export default AlertItem