@@ -4,114 +4,115 @@ import { getActorFullName } from "@/lib/getActorFullName";
44import { getFormattedDate } from "@/lib/getFormattedDate" ;
55import { getPriority } from "@/lib/getPriority" ;
66import { fetchThreadTimelineEntries } from "@/lib/fetchThreadTimelineEntries" ;
7- import { plainClient } from "@/lib/plainClient" ;
87
98export default async function ThreadPage ( {
10- params,
9+ params,
1110} : {
12- params : { threadId : string } ;
11+ params : { threadId : string } ;
1312} ) {
14- const threadId = params . threadId ;
13+ const threadId = params . threadId ;
1514
16- const { data } = await fetchThreadTimelineEntries ( {
17- threadId,
18- first : 100 ,
19- } ) ;
15+ const { data } = await fetchThreadTimelineEntries ( {
16+ threadId,
17+ first : 100 ,
18+ } ) ;
2019
21- if ( ! data ) {
22- return null ;
23- }
20+ if ( ! data ) {
21+ return null ;
22+ }
2423
25- const thread = data . thread ;
26- const timelineEntries = thread . timelineEntries ;
24+ const thread = data . thread ;
25+ const timelineEntries = thread . timelineEntries ;
2726
28- return (
29- < >
30- < Navigation hasBackButton title = { thread . title } />
31- < main className = { styles . main } >
32- < div className = { styles . timeline } >
33- { timelineEntries . edges . reverse ( ) . map ( ( e ) => {
34- const entry = e . node ;
35- if (
36- entry . entry . __typename !== "CustomEntry" &&
37- entry . entry . __typename !== "EmailEntry" &&
38- entry . entry . __typename !== "SlackReplyEntry" &&
39- entry . entry . __typename !== "SlackMessageEntry" &&
40- entry . entry . __typename !== "ChatEntry"
41- ) {
42- return null ;
43- }
27+ return (
28+ < >
29+ < Navigation hasBackButton title = { thread . title } />
30+ < main className = { styles . main } >
31+ < div className = { styles . timeline } >
32+ { timelineEntries . edges . reverse ( ) . map ( ( e , idx ) => {
33+ const entry = e . node ;
34+ if (
35+ entry . entry . __typename !== "CustomEntry" &&
36+ entry . entry . __typename !== "EmailEntry" &&
37+ entry . entry . __typename !== "SlackReplyEntry" &&
38+ entry . entry . __typename !== "SlackMessageEntry" &&
39+ entry . entry . __typename !== "ChatEntry"
40+ ) {
41+ return null ;
42+ }
43+ const actorName =
44+ entry . actor . __typename === "MachineUserActor" && idx === 0
45+ ? thread . customer . fullName
46+ : getActorFullName ( entry . actor ) ;
4447
45- return (
46- < div className = { styles . message } key = { entry . id } >
47- < div className = { styles . entryHeader } >
48- < div className = { styles . avatar } >
49- { getActorFullName ( entry . actor ) [ 0 ] . toUpperCase ( ) }
50- </ div >
51- < div >
52- < div className = { styles . actor } >
53- { getActorFullName ( entry . actor ) }
54- </ div >
55- < div className = { styles . timestamp } >
56- { getFormattedDate ( entry . timestamp . iso8601 ) }
57- </ div >
58- </ div >
59- </ div >
60- { entry . entry . __typename === "CustomEntry" &&
61- entry . entry . components . map ( ( component , idx ) => {
62- if ( component . __typename === "ComponentText" ) {
63- return (
64- < div
65- key = { `comp_${ component . text } ` }
66- className = { styles . component }
67- >
68- { component . text }
69- </ div >
70- ) ;
71- }
48+ return (
49+ < div className = { styles . message } key = { entry . id } >
50+ < div className = { styles . entryHeader } >
51+ < div className = { styles . avatar } >
52+ { actorName [ 0 ] . toUpperCase ( ) }
53+ </ div >
54+ < div >
55+ < div className = { styles . actor } > { actorName } </ div >
56+ < div className = { styles . timestamp } >
57+ { getFormattedDate ( entry . timestamp . iso8601 ) }
58+ </ div >
59+ </ div >
60+ </ div >
61+ { entry . entry . __typename === "CustomEntry" &&
62+ entry . entry . components . map ( ( component , idx ) => {
63+ if ( component . __typename === "ComponentText" ) {
64+ return (
65+ < div
66+ key = { `comp_${ component . text } ` }
67+ className = { styles . component }
68+ >
69+ { component . text }
70+ </ div >
71+ ) ;
72+ }
7273
73- return null ;
74- } ) }
75- { entry . entry . __typename === "ChatEntry" && (
76- < div > { entry . entry . text } </ div >
77- ) }
78- </ div >
79- ) ;
80- } ) }
81- </ div >
74+ return null ;
75+ } ) }
76+ { entry . entry . __typename === "ChatEntry" && (
77+ < div > { entry . entry . text } </ div >
78+ ) }
79+ </ div >
80+ ) ;
81+ } ) }
82+ </ div >
8283
83- < div className = { styles . threadInfo } >
84- < div className = { styles . title } > { thread . title } </ div >
85- < div className = { styles . description } > { thread . description } </ div >
84+ < div className = { styles . threadInfo } >
85+ < div className = { styles . title } > { thread . title } </ div >
86+ < div className = { styles . description } > { thread . description } </ div >
8687
87- < div className = { styles . threadInfoGrid } >
88- < div className = { styles . threadInfoProp } > Opened by:</ div >
89- < div className = { styles . threadInfoDesc } >
90- { getActorFullName ( thread . createdBy ) }
91- </ div >
88+ < div className = { styles . threadInfoGrid } >
89+ < div className = { styles . threadInfoProp } > Opened by:</ div >
90+ < div className = { styles . threadInfoDesc } >
91+ { thread . customer . fullName }
92+ </ div >
9293
93- < div className = { styles . threadInfoProp } > Opened:</ div >
94- < div className = { styles . threadInfoDesc } >
95- { getFormattedDate ( thread . createdAt . iso8601 ) }
96- </ div >
94+ < div className = { styles . threadInfoProp } > Opened:</ div >
95+ < div className = { styles . threadInfoDesc } >
96+ { getFormattedDate ( thread . createdAt . iso8601 ) }
97+ </ div >
9798
98- < div className = { styles . threadInfoProp } > Last activity:</ div >
99- < div className = { styles . threadInfoDesc } >
100- { getFormattedDate ( thread . updatedAt . iso8601 ) }
101- </ div >
99+ < div className = { styles . threadInfoProp } > Last activity:</ div >
100+ < div className = { styles . threadInfoDesc } >
101+ { getFormattedDate ( thread . updatedAt . iso8601 ) }
102+ </ div >
102103
103- < div className = { styles . threadInfoProp } > Status:</ div >
104- < div className = { styles . threadInfoDesc } >
105- In { thread . status . toLowerCase ( ) } queue
106- </ div >
104+ < div className = { styles . threadInfoProp } > Status:</ div >
105+ < div className = { styles . threadInfoDesc } >
106+ In { thread . status . toLowerCase ( ) } queue
107+ </ div >
107108
108- < div className = { styles . threadInfoProp } > Priority:</ div >
109- < div className = { styles . threadInfoDesc } >
110- { getPriority ( thread . priority ) }
111- </ div >
112- </ div >
113- </ div >
114- </ main >
115- </ >
116- ) ;
109+ < div className = { styles . threadInfoProp } > Priority:</ div >
110+ < div className = { styles . threadInfoDesc } >
111+ { getPriority ( thread . priority ) }
112+ </ div >
113+ </ div >
114+ </ div >
115+ </ main >
116+ </ >
117+ ) ;
117118}
0 commit comments