@@ -3,39 +3,52 @@ import PixModal from '@1024pix/pix-ui/components/pix-modal';
3
3
import PixTextarea from ' @1024pix/pix-ui/components/pix-textarea' ;
4
4
import { on } from ' @ember/modifier' ;
5
5
import { action } from ' @ember/object' ;
6
+ import { service } from ' @ember/service' ;
6
7
import Component from ' @glimmer/component' ;
7
8
import { tracked } from ' @glimmer/tracking' ;
8
9
import { t } from ' ember-intl' ;
9
10
10
- import focus from ' ../../../modifiers/focus' ;
11
+ import focus from ' ../../../../../ modifiers/focus' ;
11
12
12
13
export default class CertificationIssueReportModal extends Component {
13
- @tracked label = null ;
14
+ @service pixToast;
15
+
16
+ @tracked resolution = null ;
14
17
@tracked errorMessage = null ;
15
18
16
19
@action
17
- resolve () {
20
+ async onSubmit () {
18
21
if (this ._isInvalid ()) {
19
22
this .errorMessage = ' Le motif de résolution doit être renseigné.' ;
20
23
return ;
21
24
}
22
25
23
26
this .errorMessage = null ;
24
- this .args .resolveIssueReport (this .args .issueReport , this .label );
25
- this .args .closeResolveModal ();
27
+
28
+ try {
29
+ await this .args .issueReport .save ({ adapterOptions: { resolutionLabel: this .resolution } });
30
+ await this .args .certification .reload ();
31
+
32
+ this .pixToast .sendSuccessNotification ({ message: ' Le signalement a été résolu.' });
33
+ } catch (error) {
34
+ console .log (' error' , error);
35
+ this .pixToast .sendErrorNotification ({ message: ' Une erreur est survenue :\n ' + error? .errors [0 ]? .detail });
36
+ } finally {
37
+ this .args .toggleResolveModal ();
38
+ }
26
39
}
27
40
28
41
@action
29
- onChangeLabel (event ) {
30
- this .label = event .target .value ;
42
+ onResolutionChange (event ) {
43
+ this .resolution = event .target .value ;
31
44
}
32
45
33
46
get actionName () {
34
47
return this .args .issueReport .isResolved ? ' Modifier la résolution' : ' Résoudre ce signalement' ;
35
48
}
36
49
37
50
_isInvalid () {
38
- return this .args .issueReport .isResolved && ! this .label ? .trim ();
51
+ return this .args .issueReport .isResolved && ! this .resolution ? .trim ();
39
52
}
40
53
41
54
<template >
@@ -47,7 +60,7 @@ export default class CertificationIssueReportModal extends Component {
47
60
type =" text"
48
61
maxLength =" 255"
49
62
@ errorMessage ={{this .errorMessage }}
50
- {{on " change" this . onChangeLabel }}
63
+ {{on " change" this . onResolutionChange }}
51
64
{{focus }}
52
65
>
53
66
<: label >Résolution</: label >
@@ -56,14 +69,13 @@ export default class CertificationIssueReportModal extends Component {
56
69
57
70
<: footer >
58
71
<PixButton
59
- @ type =" submit"
60
- @ size =" small"
72
+ @ variant =" secondary"
61
73
class =" pix-button--background-transparent-light"
62
- {{ on " click " @ toggleResolveModal}}
74
+ @ triggerAction = {{ @ toggleResolveModal }}
63
75
>
64
76
{{t " common.actions.cancel" }}
65
77
</PixButton >
66
- <PixButton @ size = " small " @ triggerAction ={{this .resolve }} >{{this .actionName }} </PixButton >
78
+ <PixButton @ triggerAction ={{this .onSubmit }} >{{this .actionName }} </PixButton >
67
79
</: footer >
68
80
</PixModal >
69
81
</template >
0 commit comments