1
1
/**
2
- * A report popup used to report issues with teams or team members
2
+ * An email popup used to format and send emails for reporting issues
3
+ * and requesting extensions
3
4
*/
4
5
5
6
import React , { useCallback , useState } from "react" ;
7
+ import _ from "lodash" ;
6
8
import { useSelector , useDispatch } from "react-redux" ;
7
9
import { toastr } from "react-redux-toastr" ;
8
- import { closeReport } from "./actions" ;
10
+ import { closeEmailPopup } from "./actions" ;
9
11
import BaseModal from "components/BaseModal" ;
10
12
import TextArea from "components/TextArea" ;
11
13
import Button from "../Button" ;
12
- import { postReport } from "services/teams" ;
14
+ import { postEmail } from "services/teams" ;
13
15
import CenteredSpinner from "components/CenteredSpinner" ;
14
16
15
- function ReportPopup ( ) {
16
- const { isOpen, teamName , teamId , memberHandle } = useSelector (
17
- ( state ) => state . reportPopup
17
+ function EmailPopup ( ) {
18
+ const { isOpen, popupOptions , data } = useSelector (
19
+ ( state ) => state . emailPopup
18
20
) ;
19
21
20
22
const dispatch = useDispatch ( ) ;
21
23
const [ textVal , setTextVal ] = useState ( "" ) ;
22
24
const [ isLoading , setIsLoading ] = useState ( false ) ;
23
25
24
- const submitReport = ( ) => {
26
+ const submitEmail = ( ) => {
25
27
setIsLoading ( true ) ;
26
28
27
- postReport ( teamName , teamId , textVal , memberHandle )
29
+ const postData = _ . merge ( { } , data ) ;
30
+
31
+ _ . set ( postData , popupOptions . textDataField , textVal ) ;
32
+
33
+ postEmail ( postData )
28
34
. then ( ( ) => {
29
35
setIsLoading ( false ) ;
30
36
closeModal ( ) ;
31
- toastr . success ( "Report submitted successfully" ) ;
37
+ toastr . success ( popupOptions . successTitle ) ;
32
38
} )
33
39
. catch ( ( err ) => {
34
40
setIsLoading ( false ) ;
35
41
36
- toastr . error ( "Report failed" , err . message ) ;
42
+ toastr . error ( popupOptions . errorTitle , err . message ) ;
37
43
} ) ;
38
44
} ;
39
45
40
46
const button = (
41
47
< Button
42
- onClick = { ( ) => submitReport ( ) }
48
+ onClick = { submitEmail }
43
49
size = "medium"
44
50
isSubmit
45
51
disabled = { textVal . trim ( ) . length < 1 || isLoading }
@@ -49,17 +55,15 @@ function ReportPopup() {
49
55
) ;
50
56
51
57
const closeModal = useCallback ( ( ) => {
52
- dispatch ( closeReport ( ) ) ;
58
+ dispatch ( closeEmailPopup ( ) ) ;
53
59
setTextVal ( "" ) ;
54
60
} , [ dispatch ] ) ;
55
61
56
62
return (
57
63
< BaseModal
58
64
open = { isOpen }
59
65
onClose = { closeModal }
60
- title = { `Issue Report - ${ teamName } ${
61
- memberHandle ? " - " + memberHandle : ""
62
- } `}
66
+ title = { popupOptions . title }
63
67
button = { button }
64
68
disabled = { isLoading }
65
69
>
@@ -69,11 +73,11 @@ function ReportPopup() {
69
73
< TextArea
70
74
value = { textVal }
71
75
onChange = { setTextVal }
72
- placeholder = "Describe your issue"
76
+ placeholder = { popupOptions . textPlaceholder }
73
77
/>
74
78
) }
75
79
</ BaseModal >
76
80
) ;
77
81
}
78
82
79
- export default ReportPopup ;
83
+ export default EmailPopup ;
0 commit comments