@@ -2,8 +2,9 @@ import * as React from 'react';
2
2
import { SolutionInfo } from '../../models/solution' ;
3
3
import { ModuleInfo } from '../../models/module' ;
4
4
import useStickyState from '../../hooks/useStickyState' ;
5
- import { useState } from 'react' ;
5
+ import { useContext , useEffect , useState } from 'react' ;
6
6
import { validateEmail } from '../ContactUsSlideover/ContactUsSlideover' ;
7
+ import UserDataContext from '../../context/UserDataContext/UserDataContext' ;
7
8
8
9
export default function ModuleFeedback ( {
9
10
markdownData,
@@ -16,22 +17,31 @@ export default function ModuleFeedback({
16
17
'' ,
17
18
'module_contact_form_message'
18
19
) ;
19
- const [ email , setEmail ] = useStickyState ( '' , 'contact_form_email ') ;
20
+ const [ email , setEmail ] = useState ( ' ') ;
20
21
const [ showSuccess , setShowSuccess ] = useState ( false ) ;
21
22
22
- const emailErrorMsg =
23
- showErrors && email !== '' && ! validateEmail ( email )
23
+ const { firebaseUser } = useContext ( UserDataContext ) ;
24
+ useEffect ( ( ) => {
25
+ if ( email === '' && firebaseUser ?. email ) setEmail ( firebaseUser . email ) ;
26
+ } , [ firebaseUser ?. email ] ) ;
27
+
28
+ const emailErrorMsg = showErrors
29
+ ? email === ''
30
+ ? 'This field is required.'
31
+ : ! validateEmail ( email )
24
32
? 'Please enter a valid email address.'
25
- : null ;
33
+ : null
34
+ : null ;
26
35
27
36
const handleSubmit = async e => {
28
37
e . preventDefault ( ) ;
29
38
30
39
setShowErrors ( true ) ;
31
40
if ( message === '' ) return ;
41
+ if ( email === '' || ! validateEmail ( email ) ) return ;
32
42
33
43
let data = new FormData ( ) ;
34
- data . append ( 'email' , email || 'Not Given' ) ;
44
+ data . append ( 'email' , email ) ;
35
45
data . append ( 'location' , markdownData . title ) ;
36
46
data . append ( 'url' , window . location . href ) ;
37
47
data . append ( 'topic' , 'Module Feedback Form' ) ;
@@ -109,7 +119,7 @@ export default function ModuleFeedback({
109
119
value = { email }
110
120
formNoValidate = { true }
111
121
onChange = { e => setEmail ( e . target . value ) }
112
- placeholder = "Email Address (Optional) "
122
+ placeholder = "Email Address"
113
123
/>
114
124
{ emailErrorMsg && (
115
125
< div className = "absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none" >
0 commit comments