Skip to content

Commit

Permalink
feat(ticket): Add initial ticket comment form
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Oct 6, 2024
1 parent 2eb5751 commit bec4361
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 18 deletions.
20 changes: 19 additions & 1 deletion src/components/form/Textfield.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const TextField = ({
id = null,
label = null,
required = false,
type = 'text',
value = '',
onChange = null
}) => {
Expand All @@ -23,10 +24,27 @@ const TextField = ({
onChange={onChange}
placeholder={helptext}
required={required}
type="text"
type={type}
value={value}
/>
)
if( type === 'datetime-local') {

field = (
<input
className="common-field"
format="%Y-%m-%dT%H:%M"
id={id}
key={id}
onChange={onChange}
// placeholder={helptext}
required={required}
type={type}
// value={value}
/>
)

}

if( fieldset == true ) {

Expand Down
207 changes: 207 additions & 0 deletions src/components/page/ticket/Comment.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import FieldData from "../../../functions/FieldData"
import TextArea from "../../form/Textarea"
import { Form } from "react-router-dom"
import Select from "../../form/Select"
import TextField from "../../form/Textfield"



const TicketCommentForm = ({
discussion = false,
comment_data = {},
metadata = null,
post_url = null,
task_comment = false
}) => {

console.log(post_url)
let comment_class = 'comment-type-default comment-form'

let action_keyword = 'POST'

if( 'PUT' in metadata.actions ) {

action_keyword = 'PUT'

}

return (
metadata && <div className="">
<div className={comment_class}>

<Form
onSubmit={async e => {
e.preventDefault();
}
}
>

<div style={{lineHeight: '30px'}}>
<fieldset className={comment_class}>
<span>
<Select
choices={metadata.actions[action_keyword]['source'].choices}
id = 'source'
label = {metadata.actions[action_keyword]['source'].label}
helptext = {metadata.actions[action_keyword]['source'].help_text}
// error_text = {form_error && form_error[field_key]}
required = {metadata.actions[action_keyword]['source'].required}
// value={1}
// onChange={handleChange}
/>
</span>
</fieldset>
{task_comment && <fieldset className={comment_class}>
<span>
<Select
choices={metadata.actions[action_keyword]['status'].choices}
id = 'status'
label = {metadata.actions[action_keyword]['status'].label}
helptext = {metadata.actions[action_keyword]['status'].help_text}
// error_text = {form_error && form_error[field_key]}
required = {metadata.actions[action_keyword]['status'].required}
value={1}
// onChange={handleChange}
/>
</span>
</fieldset>}
{task_comment && <fieldset className={comment_class}>
<span>
<Select
choices={metadata.actions[action_keyword]['responsible_user'].choices}
id = 'responsible_user'
label = {metadata.actions[action_keyword]['responsible_user'].label}
helptext = {metadata.actions[action_keyword]['responsible_user'].help_text}
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[action_keyword]['responsible_user'].required}
// value={1}
// onChange={handleChange}
/>
</span>
</fieldset>}
{task_comment && <fieldset className={comment_class}>
<span>
<Select
choices={metadata.actions[action_keyword]['responsible_team'].choices}
id = 'responsible_team'
label = {metadata.actions[action_keyword]['responsible_team'].label}
helptext = {metadata.actions[action_keyword]['responsible_team'].help_text}
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[action_keyword]['responsible_user'].required}
// value={1}
// onChange={handleChange}
/>
</span>
</fieldset>}
{ true && <fieldset className={comment_class}>
<span>
<Select
choices={metadata.actions[action_keyword]['category'].choices}
id = 'category'
label = {metadata.actions[action_keyword]['category'].label}
helptext = {metadata.actions[action_keyword]['category'].help_text}
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[action_keyword]['responsible_user'].required}
// value={1}
// onChange={handleChange}
/>
<FieldData
metadata={metadata}
field_name='category'
data={comment_data}
/>
</span>
</fieldset>}
</div>

<hr />
<TextArea
required = {true}
class_name='fieldset-tester'
/>

<hr />

<div>

{ task_comment && <fieldset className={comment_class}>
<span>
<TextField
id = 'planned_start_date'
label = {metadata.actions[action_keyword]['planned_start_date'].label}
helptext = {metadata.actions[action_keyword]['planned_start_date'].help_text}
type='datetime-local'
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[meta_action][field_key].required}
// value={value}
// onChange={handleChange}
/>
</span>
</fieldset>}

{ task_comment && <fieldset className={comment_class}>
<span>
<TextField
id = 'planned_finish_date'
label = {metadata.actions[action_keyword]['planned_finish_date'].label}
helptext = {metadata.actions[action_keyword]['planned_finish_date'].help_text}
type='datetime-local'
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[meta_action][field_key].required}
// value={value}
// onChange={handleChange}
/>
</span>
</fieldset>}

{ task_comment && <fieldset className={comment_class}>
<span>
<TextField
id = 'real_start_date'
label = {metadata.actions[action_keyword]['real_start_date'].label}
helptext = {metadata.actions[action_keyword]['real_start_date'].help_text}
type='datetime-local'
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[meta_action][field_key].required}
// value={value}
// onChange={handleChange}
/>
</span>
</fieldset>}

{ task_comment && <fieldset className={comment_class}>
<span>
<TextField
id = 'real_start_date'
label = {metadata.actions[action_keyword]['real_finish_date'].label}
helptext = {metadata.actions[action_keyword]['real_finish_date'].help_text}
type='datetime-local'
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[meta_action][field_key].required}
// value={value}
// onChange={handleChange}
/>
</span>
</fieldset>}

</div>

<div style={{
// backgroundColor: '#ff0000',
display: 'block',
padding: '0px',
margin: 'auto',
marginRight: '5px',
marginBottom: '5px',
width: 'fit-content'
}}>
<button className="form common-field" type="submit">Comment</button>
</div>

</Form>
</div>
</div>
);
}

export default TicketCommentForm;
10 changes: 6 additions & 4 deletions src/components/page/ticket/Comments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import IconLoader from "../../IconLoader"
import FieldData from "../../../functions/FieldData"
import { useEffect, useState } from "react"
import { apiFetch } from "../../../hooks/apiFetch"
import TicketComment from "./Comment"
import TicketCommentForm from "./Comment"



Expand Down Expand Up @@ -290,17 +290,19 @@ const TicketComments = ({
<li className="replies">
<TicketComments
comment_data={comment}
discussion = {true}
metadata={metadata}
/>
</li>
))}
<li className="replies">
<TicketComment />
<TicketCommentForm
metadata={metadata}
post_url = {comment_data['_urls']['threads']}
/>
</li>
</ul>
</div>}


</div>
);
}
Expand Down
Loading

0 comments on commit bec4361

Please sign in to comment.