2024-08-21 02:01:20 +02:00
|
|
|
import {Timeline, Tooltip, Typography} from "antd";
|
2024-07-29 18:41:36 +02:00
|
|
|
import React from "react";
|
2024-08-21 02:01:20 +02:00
|
|
|
import {Domain} from "../../utils/api";
|
2024-07-30 06:28:00 +02:00
|
|
|
import useBreakpoint from "../../hooks/useBreakpoint";
|
2024-08-20 17:32:58 +02:00
|
|
|
import {rdapEventDetailTranslation, rdapEventNameTranslation} from "./rdapTranslation";
|
2024-08-22 01:44:50 +02:00
|
|
|
import {actionToColor} from "../../utils/functions/actionToColor";
|
|
|
|
|
import {actionToIcon} from "../../utils/functions/actionToIcon";
|
2024-08-03 02:21:11 +02:00
|
|
|
|
2024-07-29 18:41:36 +02:00
|
|
|
export function EventTimeline({domain}: { domain: Domain }) {
|
2024-07-30 06:28:00 +02:00
|
|
|
const sm = useBreakpoint('sm')
|
2024-07-29 18:41:36 +02:00
|
|
|
|
|
|
|
|
const locale = navigator.language.split('-')[0]
|
2024-08-20 15:22:14 +02:00
|
|
|
const rdapEventNameTranslated = rdapEventNameTranslation()
|
|
|
|
|
const rdapEventDetailTranslated = rdapEventDetailTranslation()
|
2024-07-29 18:41:36 +02:00
|
|
|
|
2024-08-18 18:13:23 +02:00
|
|
|
const domainEvents = domain.events.sort((e1, e2) => new Date(e2.date).getTime() - new Date(e1.date).getTime())
|
|
|
|
|
|
2024-07-29 18:41:36 +02:00
|
|
|
return <Timeline
|
2024-07-30 06:28:00 +02:00
|
|
|
mode={sm ? "left" : "right"}
|
2024-08-21 02:01:20 +02:00
|
|
|
items={domainEvents.map(e => {
|
|
|
|
|
const sameEvents = domainEvents.filter(se => se.action === e.action)
|
|
|
|
|
const isRelevant = !(sameEvents.length > 1 && sameEvents.indexOf(e) !== 0)
|
|
|
|
|
|
|
|
|
|
const eventName = <Typography.Text style={{color: isRelevant ? 'default' : 'grey'}}>
|
|
|
|
|
{e.action in rdapEventNameTranslated ? rdapEventNameTranslated[e.action as keyof typeof rdapEventNameTranslated] : e.action}
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
|
|
|
|
|
const dateStr = <Typography.Text
|
|
|
|
|
style={{color: isRelevant ? 'default' : 'grey'}}>{new Date(e.date).toLocaleString(locale)}
|
|
|
|
|
</Typography.Text>
|
2024-07-29 18:41:36 +02:00
|
|
|
|
2024-08-21 02:01:20 +02:00
|
|
|
const eventDetail = e.action in rdapEventDetailTranslated ? rdapEventDetailTranslated[e.action as keyof typeof rdapEventDetailTranslated] : undefined
|
2024-07-30 06:28:00 +02:00
|
|
|
|
2024-08-18 18:13:23 +02:00
|
|
|
const text = sm ? {
|
2024-08-20 15:22:14 +02:00
|
|
|
children: <Tooltip placement='bottom' title={eventDetail}>
|
|
|
|
|
{eventName} {dateStr}
|
|
|
|
|
</Tooltip>
|
2024-08-18 18:13:23 +02:00
|
|
|
} : {
|
|
|
|
|
label: dateStr,
|
2024-08-20 15:22:14 +02:00
|
|
|
children: <Tooltip placement='left' title={eventDetail}>{eventName}</Tooltip>,
|
2024-08-18 18:13:23 +02:00
|
|
|
}
|
2024-07-30 06:28:00 +02:00
|
|
|
|
2024-08-18 18:13:23 +02:00
|
|
|
return {
|
2024-08-21 02:01:20 +02:00
|
|
|
color: isRelevant ? actionToColor(e.action) : 'grey',
|
|
|
|
|
dot: actionToIcon(e.action),
|
|
|
|
|
pending: new Date(e.date).getTime() > new Date().getTime(),
|
2024-08-18 18:13:23 +02:00
|
|
|
...text
|
2024-07-29 18:41:36 +02:00
|
|
|
}
|
2024-08-18 18:13:23 +02:00
|
|
|
}
|
|
|
|
|
)
|
2024-07-29 18:41:36 +02:00
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
}
|