52 lines
2.3 KiB
TypeScript
Raw Normal View History

2024-09-01 21:26:07 +02:00
import {Timeline, Tooltip, Typography} from "antd";
import React from "react";
2024-08-23 21:19:34 +02:00
import {Event} from "../../utils/api";
2024-07-30 06:28:00 +02:00
import useBreakpoint from "../../hooks/useBreakpoint";
2024-08-23 21:19:34 +02:00
import {rdapEventDetailTranslation, rdapEventNameTranslation} from "../../utils/functions/rdapTranslation";
2024-08-22 01:44:50 +02:00
import {actionToColor} from "../../utils/functions/actionToColor";
import {actionToIcon} from "../../utils/functions/actionToIcon";
2024-08-23 21:19:34 +02:00
export function EventTimeline({events}: { events: Event[] }) {
2024-07-30 06:28:00 +02:00
const sm = useBreakpoint('sm')
const locale = navigator.language.split('-')[0]
2024-08-20 15:22:14 +02:00
const rdapEventNameTranslated = rdapEventNameTranslation()
const rdapEventDetailTranslated = rdapEventDetailTranslation()
2024-08-23 21:19:34 +02:00
return <>
<Timeline
mode={sm ? "left" : "right"}
items={events.map(e => {
const sameEvents = events.filter(se => se.action === e.action)
2024-09-01 21:26:07 +02:00
const eventName = <Typography.Text style={{color: e.deleted ? 'grey' : 'default'}}>
2024-08-23 21:19:34 +02:00
{e.action in rdapEventNameTranslated ? rdapEventNameTranslated[e.action as keyof typeof rdapEventNameTranslated] : e.action}
</Typography.Text>
const dateStr = <Typography.Text
2024-09-01 21:26:07 +02:00
style={{color: e.deleted ? 'grey' : 'default'}}>{new Date(e.date).toLocaleString(locale)}
2024-08-23 21:19:34 +02:00
</Typography.Text>
const eventDetail = e.action in rdapEventDetailTranslated ? rdapEventDetailTranslated[e.action as keyof typeof rdapEventDetailTranslated] : undefined
const text = sm ? {
children: <Tooltip placement='bottom' title={eventDetail}>
{eventName}&emsp;{dateStr}
</Tooltip>
} : {
label: dateStr,
children: <Tooltip placement='left' title={eventDetail}>{eventName}</Tooltip>,
}
return {
2024-09-01 21:26:07 +02:00
color: e.deleted ? 'grey' : actionToColor(e.action),
2024-08-23 21:19:34 +02:00
dot: actionToIcon(e.action),
pending: new Date(e.date).getTime() > new Date().getTime(),
...text
}
}
2024-08-23 21:19:34 +02:00
)
}
2024-08-23 21:19:34 +02:00
/>
</>
}