-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathActivityField.tsx
55 lines (42 loc) · 1.64 KB
/
ActivityField.tsx
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
44
45
46
47
48
49
50
51
52
53
54
55
import { useRecordContext, useGetOne } from "react-admin";
import { useLocksContext } from "@react-admin/ra-realtime";
import { Tooltip, Box } from "@mui/material";
import VisibilityIcon from "@mui/icons-material/Visibility";
import LockIcon from "@mui/icons-material/Lock";
import { useTicketReadsContext } from "./TicketReadsContext";
export const ActivityField = () => {
const record = useRecordContext();
const locks = useLocksContext();
const lock = locks.find((lock) => lock.recordId === record?.id);
const reads = useTicketReadsContext();
const read = reads.find((read) => read.ticketId === record?.id);
if (!record) return <PlaceHolder />;
if (lock) return <LockedIcon identity={lock.identity} />;
if (read) return <ReadIcon identity={read.userId} />;
return <PlaceHolder />;
};
ActivityField.defaultProps = {
label: "",
source: "lock",
};
const LockedIcon = ({ identity }: { identity?: string }) => {
const { data: agent, isLoading } = useGetOne("agents", { id: identity });
if (isLoading) return <PlaceHolder />;
if (!agent) return <PlaceHolder />;
return (
<Tooltip title={`Locked by ${agent.firstName} ${agent.lastName}`}>
<LockIcon fontSize="small" color="action" />
</Tooltip>
);
};
const ReadIcon = ({ identity }: { identity?: string }) => {
const { data: agent, isLoading } = useGetOne("agents", { id: identity });
if (isLoading) return <PlaceHolder />;
if (!agent) return <PlaceHolder />;
return (
<Tooltip title={`Read by ${agent.firstName} ${agent.lastName}`}>
<VisibilityIcon fontSize="small" color="action" />
</Tooltip>
);
};
const PlaceHolder = () => <Box width={20} />;