|
1 | 1 | import Button from '@atlaskit/button'; |
2 | | -import LoadingButton from '@atlaskit/button/loading-button'; |
3 | 2 | import Form, { ErrorMessage, Field, FormFooter, FormHeader, RequiredAsterisk } from '@atlaskit/form'; |
4 | 3 | import Page from '@atlaskit/page'; |
5 | 4 | import Select, { components } from '@atlaskit/select'; |
@@ -27,20 +26,23 @@ import { |
27 | 26 | CommonEditorViewState, |
28 | 27 | emptyCommonEditorState, |
29 | 28 | } from '../AbstractIssueEditorPage'; |
| 29 | +import { CreateIssueButton } from './actions/CreateIssueButton'; |
30 | 30 | import { Panel } from './Panel'; |
31 | 31 |
|
32 | 32 | type Emit = CommonEditorPageEmit; |
33 | 33 | type Accept = CommonEditorPageAccept | CreateIssueData; |
34 | 34 | interface ViewState extends CommonEditorViewState, CreateIssueData { |
35 | 35 | createdIssue: IssueKeyAndSite<DetailedSiteInfo>; |
36 | 36 | formKey: string; |
| 37 | + onCreateAction: 'createAndView' | 'createAndStartWork' | 'createAndGenerateCode'; |
37 | 38 | } |
38 | 39 |
|
39 | 40 | const emptyState: ViewState = { |
40 | 41 | ...emptyCommonEditorState, |
41 | 42 | ...emptyCreateIssueData, |
42 | 43 | createdIssue: { key: '', siteDetails: emptySiteInfo }, |
43 | 44 | formKey: v4(), |
| 45 | + onCreateAction: 'createAndView', |
44 | 46 | }; |
45 | 47 |
|
46 | 48 | const fallbackTimerDuration = 5000; // 5 seconds |
@@ -108,6 +110,7 @@ export default class CreateIssuePage extends AbstractIssueEditorPage<Emit, Accep |
108 | 110 | private attachingInProgress = false; |
109 | 111 | private initialFieldValues: FieldValues = {}; |
110 | 112 | private suggestionFallbackTimer: NodeJS.Timeout | null = null; |
| 113 | + private formRef = React.createRef<HTMLFormElement>(); |
111 | 114 |
|
112 | 115 | getProjectKey(): string { |
113 | 116 | return this.state.fieldValues['project'].key; |
@@ -236,6 +239,15 @@ export default class CreateIssuePage extends AbstractIssueEditorPage<Emit, Accep |
236 | 239 | }); |
237 | 240 | break; |
238 | 241 | } |
| 242 | + case 'createIssueWithAction': { |
| 243 | + handled = true; |
| 244 | + |
| 245 | + this.setState({ onCreateAction: e.action }, () => { |
| 246 | + this.formRef.current?.requestSubmit(); |
| 247 | + this.setState({ onCreateAction: 'createAndView' }); |
| 248 | + }); |
| 249 | + break; |
| 250 | + } |
239 | 251 | } |
240 | 252 | } |
241 | 253 |
|
@@ -300,6 +312,7 @@ export default class CreateIssuePage extends AbstractIssueEditorPage<Emit, Accep |
300 | 312 | action: 'createIssue', |
301 | 313 | site: this.state.siteDetails, |
302 | 314 | issueData: this.state.fieldValues, |
| 315 | + onCreateAction: this.state.onCreateAction, |
303 | 316 | }); |
304 | 317 |
|
305 | 318 | return undefined; |
@@ -506,7 +519,7 @@ export default class CreateIssuePage extends AbstractIssueEditorPage<Emit, Accep |
506 | 519 | <Form name="create-issue" key={this.state.formKey} onSubmit={this.handleSubmit}> |
507 | 520 | {(frmArgs: any) => { |
508 | 521 | return ( |
509 | | - <form {...frmArgs.formProps}> |
| 522 | + <form {...frmArgs.formProps} ref={this.formRef}> |
510 | 523 | <FormHeader title={this.formHeader()}> |
511 | 524 | <p> |
512 | 525 | Required fields are marked with an asterisk <RequiredAsterisk /> |
@@ -544,15 +557,18 @@ export default class CreateIssuePage extends AbstractIssueEditorPage<Emit, Accep |
544 | 557 | </Panel> |
545 | 558 | )} |
546 | 559 | <FormFooter actions={{}}> |
547 | | - <LoadingButton |
| 560 | + <CreateIssueButton |
548 | 561 | type="submit" |
549 | | - spacing="compact" |
| 562 | + name="Create" |
550 | 563 | className="ac-button" |
551 | | - isDisabled={this.state.isSomethingLoading} |
552 | | - isLoading={this.state.loadingField === 'submitButton'} |
| 564 | + disabled={this.state.isSomethingLoading} |
| 565 | + isLoading={ |
| 566 | + this.state.isSomethingLoading && |
| 567 | + this.state.loadingField === 'submitButton' |
| 568 | + } |
553 | 569 | > |
554 | 570 | Create |
555 | | - </LoadingButton> |
| 571 | + </CreateIssueButton> |
556 | 572 | </FormFooter> |
557 | 573 | </form> |
558 | 574 | ); |
|
0 commit comments