diff --git a/src/components/page/ticket/TicketComment.jsx b/src/components/page/ticket/TicketComment.jsx index 53cbb9d..dd259e0 100644 --- a/src/components/page/ticket/TicketComment.jsx +++ b/src/components/page/ticket/TicketComment.jsx @@ -11,7 +11,10 @@ const TicketComment = ({ discussion = false, comment_data = {}, metadata = null, - ticket_id = null + ticket_id = null, + post_url, + edit_callback = null, + callback_value = null }) => { let comment_header = ' wrote' @@ -20,6 +23,8 @@ const TicketComment = ({ let comment_type = '' + let [ editing, setIsEditing ] = useState(false) + try { comment_type = String(metadata.fields.comment_type.choices[Number(comment_data.comment_type)-1].display_name).toLowerCase() @@ -127,9 +132,15 @@ const TicketComment = ({ + { + setIsEditing( true ) + }}> + ) @@ -145,6 +156,23 @@ const TicketComment = ({ return ( metadata &&
+ { editing && + { + setIsEditing(false) + }} + commentCallback={() => { + setIsEditing(false) + edit_callback( callback_value ? false : true ) + }} + /> + } + { ! editing &&

@@ -272,6 +300,7 @@ const TicketComment = ({

+ } { threads &&

diff --git a/src/components/page/ticket/TicketCommentForm.jsx b/src/components/page/ticket/TicketCommentForm.jsx index 5e4c09a..093bdf8 100644 --- a/src/components/page/ticket/TicketCommentForm.jsx +++ b/src/components/page/ticket/TicketCommentForm.jsx @@ -16,15 +16,83 @@ const TicketCommentForm = ({ post_url = null, parent_id = null, ticket_id = null, - commentCallback = null + commentCallback = null, + is_edit = false, + cancelbuttonOnSubmit = null, }) => { - console.log(post_url) + if( String(post_url).includes('?') ) { + console.log('url has qs') + post_url = String(post_url).split('?')[0] + } + + let HTTP_METHOD = 'POST' + + if( is_edit ) { + + post_url += '/' + comment_data['id'] + HTTP_METHOD = 'PATCH' + } + let comment_class = 'comment-type-default comment-form' - const [task_comment, setTaskComment] = useState(false) - const [form_data, setFormData] = useState({}) + let edit_form_data = {} + + if( comment_data && is_edit ) { + + edit_form_data = { + 'body': comment_data['body'], + 'source': comment_data['source'], + } + + } + + + const comment_types = metadata.fields['comment_type'].choices + let comment_type = '' + + console.log(`menu entry click value ${comment_type}`) + + for( let meta_comment_type of comment_types) { + + if( Number(comment_data['comment_type']) === Number(meta_comment_type.value) ) { + comment_type = String(meta_comment_type.display_name).toLowerCase() + } + + } + + + comment_type = String(comment_type).toLowerCase() + + let is_task_comment = false + + let is_solution_comment = false + + let is_notification_comment = false + + + console.log(`menu entry is ${comment_type}`) + + if( comment_type === 'task' ) { + + is_task_comment = true + + }else if( comment_type === 'solution' ) { + + is_solution_comment = true + + }else if( comment_type === 'notification' ) { + + is_notification_comment = true + + } + + + + const [task_comment, setTaskComment] = useState( is_task_comment ) + + const [form_data, setFormData] = useState(edit_form_data) const handleChange = (e) => { @@ -38,7 +106,7 @@ const TicketCommentForm = ({ } - if( ! form_data.comment_type ) { + if( ! form_data.comment_type && ! is_edit ) { for( let comment_type of metadata.fields['comment_type'].choices) { @@ -81,11 +149,17 @@ const TicketCommentForm = ({ const response = await apiFetch( post_url, setFormError, - 'POST', + HTTP_METHOD, form_data ) - if( response.status === 201 ) { + if( + response.status === 201 + || ( + response.status === 200 + && is_edit + ) + ) { commentCallback(); setFormData({}); @@ -103,6 +177,7 @@ const TicketCommentForm = ({ id = 'source' field_data={metadata.fields['source']} onChange={handleChange} + value = {form_data['source']} /> @@ -111,7 +186,7 @@ const TicketCommentForm = ({