Skip to content

Commit

Permalink
feat(component): Enable replying to comment
Browse files Browse the repository at this point in the history
ref: #18 #34
  • Loading branch information
jon-nfc committed Dec 11, 2024
1 parent 955ebae commit 37c08b2
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/components/page/ticket/TicketComment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const TicketComment = ({
callback_value = null
}) => {

if( String(post_url).includes('?') ) {
console.log('url has qs')
post_url = String(post_url).split('?')[0]
}

let comment_header = ' wrote'

let comment_class = 'comment comment-type-default'
Expand Down Expand Up @@ -86,15 +91,17 @@ const TicketComment = ({
</div>
)

const [threads_url, setThreadsURL] = useState(comment_data._urls.threads ? String(comment_data._urls.threads).split('api/v2')[1] : null)


const [ threads, setThreads ] = useState(null)
const [ reload, setRelaod ] = useState(false)

useEffect(() => {

if( comment_data._urls.threads ) {
if( threads_url ) {
apiFetch(
String(comment_data._urls.threads).split('api/v2')[1] + '?page[size]=500',
threads_url + '?page[size]=500',
(data) => {
setThreads(data)
},
Expand All @@ -105,7 +112,7 @@ const TicketComment = ({

setRelaod(false)
}
},[ reload ])
},[ reload, threads_url ])


if( comment_type === 'action' ) {
Expand Down Expand Up @@ -139,9 +146,19 @@ const TicketComment = ({

const header_icons = (
<div id="icons">
<IconLoader
{comment_data['parent'] == null &&
<span style={{
cursor: 'pointer'
}} onClick={(e) => {
setThreads( {
results: []
} )
}}>
<IconLoader
name={'reply'}
/>
</span>
}
<span style={{
cursor: 'pointer'
}} onClick={(e) => {
Expand Down Expand Up @@ -335,11 +352,13 @@ const TicketComment = ({
<li className="replies">
<TicketCommentForm
metadata={metadata}
post_url = {comment_data['_urls']['threads']}
post_url = {post_url + '/' + comment_data['id'] + '/threads'}
ticket_id={ticket_id}
parent_id = {threads.results[0].parent}
parent_id = {comment_data['id'] ? comment_data['id'] : threads.results[0].parent}
commentCallback={() => {
setRelaod(true)

setThreadsURL(post_url + '/' + comment_data['id'] + '/threads')
}}
/>
</li>
Expand Down

0 comments on commit 37c08b2

Please sign in to comment.