-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMessageList.tsx
98 lines (95 loc) · 2.85 KB
/
MessageList.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { Fragment } from "react";
import { useListContext, ReferenceField } from "react-admin";
import { useFormContext } from "react-hook-form";
import {
Divider,
List,
ListItem,
ListItemIcon,
ListItemText,
ListItemAvatar,
} from "@mui/material";
import { NewMessageForm } from "./NewMessageForm";
import { CustomerAvatar } from "../customers/CustomerAvatar";
export const MessageList = () => {
const { data, isLoading } = useListContext();
if (isLoading) return null;
return (
<List sx={{ width: "100%", pt: 0 }}>
{data.map((message) => (
<Fragment key={message.id}>
<ListItem
alignItems="flex-start"
sx={
message.author === "agent" ? { backgroundColor: "#ffffef" } : {}
}
>
<ListItemAvatar>
{message.author === "agent" ? (
<ReferenceField
record={message}
source="agent_id"
reference="agents"
label=""
>
<CustomerAvatar />
</ReferenceField>
) : (
<ReferenceField
record={message}
source="customer_id"
reference="customers"
label=""
>
<CustomerAvatar />
</ReferenceField>
)}
</ListItemAvatar>
<ListItemText
primary={message.message}
secondary={
<>
{message.author === "agent" ? (
<ReferenceField
record={message}
source="agent_id"
reference="agents"
label=""
/>
) : (
<ReferenceField
record={message}
source="customer_id"
reference="customers"
label=""
/>
)}
<{message.email}>
</>
}
sx={{
flexDirection: "column-reverse",
display: "flex",
gap: 0.5,
"& .MuiListItemText-primary": {
whiteSpace: "pre-line",
},
"& .MuiListItemText-secondary span": {
fontWeight: "bold",
},
}}
/>
<ListItemIcon sx={{ fontSize: "14px" }}>
{new Date(message.timestamp).toLocaleString(undefined, {
dateStyle: "medium",
timeStyle: "short",
})}
</ListItemIcon>
</ListItem>
<Divider component="li" />
</Fragment>
))}
<NewMessageForm />
</List>
);
};