@@ -8,17 +8,18 @@ import IconLoader from "../../IconLoader"
88import { secondsToTime } from "../../../layout/Ticket"
99import Section from "../../Section"
1010import TicketCommentForm from "./TicketCommentForm"
11+ import TicketComments from "./TicketComments"
1112
1213
1314
1415const TicketComment = ( {
15- discussion = false ,
1616 comment_data = { } ,
1717 metadata = null ,
1818 ticket_id = null ,
1919 post_url,
2020 edit_callback = null ,
21- callback_value = null
21+ callback_value = null ,
22+ parent_comment = null ,
2223} ) => {
2324
2425 if ( String ( post_url ) . includes ( '?' ) ) {
@@ -30,7 +31,7 @@ const TicketComment = ({
3031
3132 const [ comment_page_data , setCommentPageData ] = useState ( comment_data )
3233
33- const [ reload , setReload ] = useState ( false )
34+ const [ start_thread , setStartThread ] = useState ( false )
3435
3536 let comment_header = ' wrote'
3637
@@ -114,20 +115,21 @@ const TicketComment = ({
114115
115116 useEffect ( ( ) => {
116117
117- if ( comment_page_data ) {
118+ if ( comment_page_data . _urls . threads && ! parent_comment ) {
118119 apiFetch (
119- `${ post_url + '/ threads?page[size]=500' } ` ,
120+ `${ comment_page_data . _urls . threads } ?page[size]=500` ,
120121 ( data ) => {
121122 setThreads ( data )
122123 } ,
123124 undefined ,
124125 undefined ,
125126 false
126127 )
127-
128- setReload ( false )
129128 }
130- } , [ reload ] )
129+ } , [
130+ comment_page_data . _urls . threads ,
131+ parent_comment ,
132+ ] )
131133
132134
133135
@@ -141,7 +143,7 @@ const TicketComment = ({
141143 )
142144 . then ( ( result ) => {
143145
144- if ( result . status == 200 ) {
146+ if ( result . status === 200 ) {
145147
146148 if ( result . api_metadata !== null ) {
147149
@@ -193,9 +195,9 @@ const TicketComment = ({
193195 < span style = { {
194196 cursor : 'pointer'
195197 } } onClick = { ( e ) => {
196- setThreads ( {
197- results : [ ]
198- } )
198+ if ( threads . results . length === 0 ) {
199+ setStartThread ( ( start_thread ? false : true ) )
200+ }
199201 } } >
200202 < IconLoader
201203 name = { 'reply' }
@@ -242,6 +244,7 @@ const TicketComment = ({
242244 comment_data = { comment_page_data }
243245 metadata = { comment_metadata }
244246 post_url = { post_url }
247+ parent_id = { parent_comment }
245248 ticket_id = { ticket_id }
246249 is_edit = { true }
247250 cancelbuttonOnSubmit = { ( e ) => {
@@ -265,7 +268,6 @@ const TicketComment = ({
265268 </ h4 >
266269 ) }
267270 >
268-
269271 < div className = "comment row" >
270272
271273 { comment_page_data . source &&
@@ -391,7 +393,8 @@ const TicketComment = ({
391393
392394 </ Section >
393395 }
394- { threads ?. results [ 0 ] ?. parent &&
396+
397+ { ( ( threads ? ( threads . results . length > 0 ) : false ) || start_thread ) &&
395398 < div
396399 className = "replies"
397400 style = { {
@@ -411,46 +414,12 @@ const TicketComment = ({
411414 width = '20px'
412415 />
413416 </ h3 >
414- < ul
415- className = "replies"
416- style = { {
417- paddingLeft : '1.6rem'
418- } }
419- >
420- { threads . results &&
421- threads . results . map ( ( comment , index ) => (
422- < li
423- className = "replies"
424- id = { comment . id }
425- key = { 'comment-reply-' + comment . id }
426- >
427- < TicketComment
428- comment_data = { comment }
429- discussion = { true }
430- metadata = { comment_metadata }
431- edit_callback = { ( ) => {
432- setReload ( true )
433- } }
434- />
435- </ li >
436- ) ) }
437- < li
438- className = "replies"
439- key = { 'comment-reply-form-' + comment_page_data . id }
440- >
441- < TicketCommentForm
442- metadata = { comment_metadata }
443- post_url = { `${ post_url } /threads` }
444- ticket_id = { ticket_id }
445- parent_id = { comment_page_data [ 'id' ] ? comment_page_data [ 'id' ] : threads . results [ 0 ] . parent }
446- commentCallback = { ( response ) => {
447-
448- setCommentPageData ( response . api_page_data ) ;
449-
450- } }
451- />
452- </ li >
453- </ ul >
417+ < TicketComments
418+ comment_metadata = { metadata }
419+ comments_url = { comment_page_data . _urls . threads }
420+ ticket_id = { ticket_id }
421+ parent_comment = { comment_page_data . id }
422+ />
454423 </ div > }
455424 </ div >
456425 ) ;
0 commit comments