11import Navigation from "@/components/navigation" ;
22import styles from "./page.module.css" ;
3- import Actor from "@/components/actor" ;
4- import { ActorPartsFragment } from "@team-plain/typescript-sdk" ;
5- import Avatar from "@/components/avatar" ;
6-
7- function getFullname ( actor ) {
8- switch ( actor . __typename ) {
9- case "CustomerActor" : {
10- return actor . customer . fullName ;
11- }
12- case "UserActor" : {
13- return actor . user . fullName ;
14- }
15- case "MachineUserActor" : {
16- return actor . user . fullName ;
17- }
18- }
19- }
3+ import { getActorFullName } from "@/lib/getActorFullName" ;
4+ import { getFormattedDate } from "@/lib/getFormattedDate" ;
5+ import { getPriority } from "@/lib/getPriority" ;
6+ import { fetchThreadTimelineEntries } from "@/lib/fetchThreadTimelineEntries" ;
7+ import { plainClient } from "@/lib/plainClient" ;
208
219export default async function ThreadPage ( {
2210 params,
2311} : {
2412 params : { threadId : string } ;
2513} ) {
26- const apiKey = process . env . PLAIN_API_KEY ;
27- if ( ! apiKey ) {
28- throw new Error ( "Please set the `PLAIN_API_KEY` environment variable" ) ;
29- }
14+ const threadId = params . threadId ;
15+
16+ const { data } = await fetchThreadTimelineEntries ( {
17+ threadId,
18+ first : 100 ,
19+ } ) ;
3020
31- const data = await fetch ( "https://core-api.uk.plain.com/graphql/v1" , {
32- method : "POST" ,
33- body : JSON . stringify ( {
34- query : `{
35- thread(threadId: "th_01J299WQGA3VNQ4FDECV7JK6MC") {
36- title
37- description
38- priority
39- status
40- createdAt {
41- iso8601
42- }
43- createdBy {
44- __typename
45- ... on UserActor {
46- user {
47- fullName
48- }
49- }
50- ... on CustomerActor {
51- customer {
52- fullName
53- }
54- }
55- ... on MachineUserActor {
56- machineUser {
57- fullName
58- }
59- }
60- }
61- updatedAt {
62- iso8601
63- }
64- timelineEntries {
65- edges {
66- node {
67- id
68- timestamp {
69- iso8601
70- }
71- actor {
72- __typename
73- ... on UserActor {
74- user {
75- fullName
76- }
77- }
78- ... on CustomerActor {
79- customer {
80- fullName
81- }
82- }
83- ... on MachineUserActor {
84- machineUser {
85- fullName
86- }
87- }
88- }
89- entry {
90- __typename
91- ... on CustomEntry {
92- title
93- components {
94- __typename
95- ... on ComponentText {
96- text
97- }
98- }
99- }
100- ... on ChatEntry {
101- chatId
102- text
103- }
104- }
105- }
106- }
107- }
108- }
109- }` ,
110- } ) ,
111- headers : {
112- "Content-Type" : "application/json" ,
113- "Plain-Workspace-Id" : "w_01J28VHKDK5PV3DJSZAA01XGAN" ,
114- Authorization : `Bearer ${ process . env . PLAIN_API_KEY } ` ,
115- } ,
116- } )
117- . then ( ( res ) => res . json ( ) )
21+ if ( ! data ) {
22+ return null ;
23+ }
11824
119- const thread = data . data . thread ;
25+ const thread = data . thread ;
12026 const timelineEntries = thread . timelineEntries ;
27+
12128 return (
12229 < >
12330 < Navigation hasBackButton title = { thread . title } />
@@ -139,14 +46,14 @@ export default async function ThreadPage({
13946 < div className = { styles . message } key = { entry . id } >
14047 < div className = { styles . entryHeader } >
14148 < div className = { styles . avatar } >
142- { getFullname ( entry . actor ) [ 0 ] . toUpperCase ( ) }
49+ { getActorFullName ( entry . actor ) [ 0 ] . toUpperCase ( ) }
14350 </ div >
14451 < div >
14552 < div className = { styles . actor } >
146- { getFullname ( entry . actor ) }
53+ { getActorFullName ( entry . actor ) }
14754 </ div >
14855 < div className = { styles . timestamp } >
149- { entry . timestamp . iso8601 }
56+ { getFormattedDate ( entry . timestamp . iso8601 ) }
15057 </ div >
15158 </ div >
15259 </ div >
@@ -163,7 +70,7 @@ export default async function ThreadPage({
16370 ) ;
16471 }
16572
166- return < div key = { `comp_ ${ idx } ` } > TODO </ div > ;
73+ return null ;
16774 } ) }
16875 { entry . entry . __typename === "ChatEntry" && (
16976 < div > { entry . entry . text } </ div >
@@ -174,10 +81,35 @@ export default async function ThreadPage({
17481 </ div >
17582
17683 < div className = { styles . threadInfo } >
177- < div className = { styles . threadInfoProp } > Created by:</ div >
178- < div > { getFullname ( thread . createdBy ) } </ div >
179- < div className = { styles . threadInfoProp } > Created at:</ div >
180- < div > { thread . createdAt . iso8601 } </ div >
84+ < div className = { styles . title } > { thread . title } </ div >
85+ < div className = { styles . description } > { thread . description } </ div >
86+
87+ < div className = { styles . threadInfoGrid } >
88+ < div className = { styles . threadInfoProp } > Opened by:</ div >
89+ < div className = { styles . threadInfoDesc } >
90+ { getActorFullName ( thread . createdBy ) }
91+ </ div >
92+
93+ < div className = { styles . threadInfoProp } > Opened:</ div >
94+ < div className = { styles . threadInfoDesc } >
95+ { getFormattedDate ( thread . createdAt . iso8601 ) }
96+ </ div >
97+
98+ < div className = { styles . threadInfoProp } > Last activity:</ div >
99+ < div className = { styles . threadInfoDesc } >
100+ { getFormattedDate ( thread . updatedAt . iso8601 ) }
101+ </ div >
102+
103+ < div className = { styles . threadInfoProp } > Status:</ div >
104+ < div className = { styles . threadInfoDesc } >
105+ In { thread . status . toLowerCase ( ) } queue
106+ </ div >
107+
108+ < div className = { styles . threadInfoProp } > Priority:</ div >
109+ < div className = { styles . threadInfoDesc } >
110+ { getPriority ( thread . priority ) }
111+ </ div >
112+ </ div >
181113 </ div >
182114 </ main >
183115 </ >
0 commit comments