@@ -5,66 +5,115 @@ import Col from "react-bootstrap/Col";
55import Card from "react-bootstrap/Card" ;
66import Form from "react-bootstrap/Form" ;
77import ToggleButton from "react-bootstrap/ToggleButton" ;
8+ import { IntelligentQuestionSelector } from "../search/IntelligentQuestionSelector" ;
9+ import Button from "react-bootstrap/Button" ;
10+ import API from "../../api" ;
11+ import Alert from "react-bootstrap/Alert" ;
812
913export class CreateTicketForm extends React . Component {
1014
1115 constructor ( ) {
1216 super ( ) ;
1317 this . state = {
18+ name : "" ,
19+ description : "" ,
1420 relateToForm : false ,
1521 relateToFormVersion : false ,
1622 relateToQuestion : false
1723 }
24+ this . onChangeSetState = this . onChangeSetState . bind ( this ) ;
25+ this . onSubmitProject = this . onSubmitProject . bind ( this ) ;
26+ this . errorMessage = this . errorMessage . bind ( this ) ;
27+ this . questionSelectorRef = React . createRef ( ) ;
1828 }
1929
20- render ( ) {
2130
31+ onChangeSetState ( e ) {
32+ const { name, value} = e . target ;
33+ this . setState ( prevState => ( { ...prevState , [ name ] : value } ) ) ;
34+ }
35+
36+ onSubmitProject ( e ) {
37+ e . preventDefault ( ) ;
38+ API . post ( "/rest/ticket" , {
39+ projectName : this . props . projectName ,
40+ recordContextUri : this . props . contextUri ,
41+ name : this . state . name ,
42+ description : this . state . description ,
43+ relateToForm : this . state . relateToForm ,
44+ relateToFormVersion : this . state . relateToFormVersion ,
45+ relateToQuestion : this . state . relateToQuestion ,
46+ questionOriginPath : this . questionSelectorRef ?. current ?. state . activeQuestionOriginPath ,
47+ } ) . then ( ( response ) => {
48+ this . ticketForm . reset ( ) ;
49+ this . setState ( {
50+ showError : false ,
51+ showSuccess : true ,
52+ ticketLink : response . data ,
53+ relateToForm : false ,
54+ relateToFormVersion : false ,
55+ relateToQuestion : false
56+ } ) ;
57+ } ) . catch ( ( error ) => {
58+ console . log ( error )
59+ this . setState ( { showError : true , showSuccess : false } ) ; // todo: improve handling individual messages
60+ }
61+ ) ;
62+ }
63+
64+ render ( ) {
2265 return < Card >
2366 < ListGroup variant = "flush" >
2467 < ListGroup . Item >
2568 < div >
2669 < Row >
2770 < Col >
2871 < div >
29- < Form . Group controlId = "ticketName" >
30- < Form . Label > Name</ Form . Label >
31- < Form . Control type = "text" placeholder = "ticket name" />
32- </ Form . Group >
33- < Form . Group controlId = "ticketName" >
34- < Form . Label > Description</ Form . Label >
35- < Form . Control as = "textarea"
36- placeholder = "ticket description"
37- name = "ticketDescription" rows = { 3 }
38- onChange = { this . onChangeSetState } />
39- </ Form . Group >
40- < ToggleButton variant = "light" style = { { marginBottom : "0" } } type = "checkbox"
41- checked = { this . state . relateToForm }
42- value = "1"
43- onChange = { e => this . setState ( { relateToForm : e . currentTarget . checked } ) } >
44- { ' ' } Relate to form
45- </ ToggleButton >
46- { ' ' }
47- < ToggleButton variant = "light" style = { { marginBottom : "0" } } type = "checkbox"
48- checked = { this . state . relateToFormVersion }
49- value = "1"
50- onChange = { e => this . setState ( { relateToFormVersion : e . currentTarget . checked } ) } >
51- { ' ' } Relate to form version
52- </ ToggleButton >
53- { ' ' }
54- < ToggleButton variant = "light" style = { { marginBottom : "0" } } type = "checkbox"
55- checked = { this . state . relateToQuestion }
56- value = "1"
57- onChange = { e => this . setState ( { relateToQuestion : e . currentTarget . checked } ) } >
58- { ' ' } Relate to question (origin path)
59- </ ToggleButton >
60- < br />
61- { /*<Form.Group controlId="questionOrigin">*/ }
62- { /* <Form.Label>Question-Origin</Form.Label>*/ }
63- { /* <Form.Control as="text"*/ }
64- { /* placeholder={"question origin path"}*/ }
65- { /* name="questionOriginPath" // TODO: DAG select*/ }
66- { /* onChange={this.onChangeSetState}/>*/ }
67- { /*</Form.Group>*/ }
72+ < Form onSubmit = { this . onSubmitProject } ref = { form => this . ticketForm = form } >
73+ < Form . Group controlId = "nameControl" >
74+ < Form . Label > Name</ Form . Label >
75+ < Form . Control type = "text"
76+ placeholder = "ticket name"
77+ name = "name"
78+ onChange = { this . onChangeSetState } />
79+ </ Form . Group >
80+ < Form . Group controlId = "descriptionControl" >
81+ < Form . Label > Description</ Form . Label >
82+ < Form . Control as = "textarea"
83+ placeholder = "ticket description"
84+ name = "description" rows = { 3 }
85+ onChange = { this . onChangeSetState } />
86+ </ Form . Group >
87+ < ToggleButton variant = "light" style = { { marginBottom : "0" } } type = "checkbox"
88+ checked = { this . state . relateToForm }
89+ value = "1"
90+ onChange = { e => this . setState ( { relateToForm : e . currentTarget . checked } ) } >
91+ { ' ' } Relate to form
92+ </ ToggleButton >
93+ { ' ' }
94+ < ToggleButton variant = "light" style = { { marginBottom : "0" } } type = "checkbox"
95+ checked = { this . state . relateToFormVersion }
96+ value = "1"
97+ onChange = { e => this . setState ( { relateToFormVersion : e . currentTarget . checked } ) } >
98+ { ' ' } Relate to form version
99+ </ ToggleButton >
100+ { ' ' }
101+ < ToggleButton variant = "light" style = { { marginBottom : "0" } } type = "checkbox"
102+ checked = { this . state . relateToQuestion }
103+ value = "1"
104+ onChange = { e => this . setState ( { relateToQuestion : e . currentTarget . checked } ) } >
105+ { ' ' } Relate to question (origin path)
106+ </ ToggleButton >
107+ { this . state . relateToQuestion ?
108+ < IntelligentQuestionSelector projectName = { this . props . projectName }
109+ ref = { this . questionSelectorRef } /> : < div /> }
110+ < br />
111+ < Button variant = "primary" type = "submit" >
112+ Submit
113+ </ Button >
114+ { this . state . showError === true && this . errorMessage ( ) }
115+ { this . state . showSuccess === true && this . successMessage ( ) }
116+ </ Form >
68117 </ div >
69118 </ Col >
70119 </ Row >
@@ -74,4 +123,24 @@ export class CreateTicketForm extends React.Component {
74123 </ Card > ;
75124 }
76125
126+ errorMessage ( ) {
127+ return < div >
128+ < br />
129+ < Alert variant = "danger" onClose = { ( ) => this . setState ( { showError : false } ) } dismissible >
130+ < Alert . Heading > Warning!</ Alert . Heading >
131+ < p > Creating project was not successful.</ p >
132+ </ Alert >
133+ </ div >
134+ }
135+
136+ successMessage ( ) {
137+ return < div >
138+ < br />
139+ < Alert variant = "success" onClose = { ( ) => this . setState ( { showSuccess : false } ) } dismissible >
140+ < Alert . Heading > Success!</ Alert . Heading >
141+ Creating ticket was successful. < a target = { "_blank" } href = { this . state . ticketLink } > ticket link</ a >
142+ </ Alert >
143+ </ div >
144+ }
145+
77146}
0 commit comments