Skip to content

Commit 98b2714

Browse files
Merge pull request #2128 from hpe-dev-incubator/Autofill_email_feedback_widget_#2117
auto_fill_email_issue_on_reload_fix-1
2 parents 59951a6 + 31be8b7 commit 98b2714

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/components/Feedback/FeedbackBody/FeedbackBody.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* eslint-disable react/prop-types */
22
/* eslint-disable max-len */
33
import { Box, Button, TextInput, Text, TextArea, Image } from 'grommet';
4-
import React, { useState } from 'react';
4+
import React, { useState,useContext,useEffect } from 'react';
55
import { FormNextLink, FormPreviousLink } from 'grommet-icons';
6+
import { AppContext } from '../../../providers/AppProvider';
67

78
const defaultBodyStyles = {
89
padding: '10px',
@@ -41,6 +42,13 @@ const FeedbackBody = ({
4142
cancelQuestion();
4243
}
4344
};
45+
const { user }=useContext(AppContext);
46+
useEffect(() => {
47+
if (user?.email) {
48+
// Update the email value in the Formik form
49+
feedbackFromik.setFieldValue('email', user.email);
50+
}
51+
}, [user?.email]);
4452
return (
4553
<Box gap="small" style={{ height: 300, width: 350 }}>
4654
{selQuestion === undefined &&

src/components/Feedback/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ const Feedback = (props) => {
6262
handleButtonClick,
6363
handleSubmit,
6464
isSubmissionSuccess,
65-
emailvalue,
66-
feedbackvalue,
6765
} = props;
6866
useEffect(() => {
6967
if (isSubmissionSuccess !== undefined) {
@@ -78,7 +76,7 @@ const Feedback = (props) => {
7876
}
7977
else{handleSubmit({
8078
message: values.value,
81-
email: values.email,
79+
email: values?.email || '',
8280
proxy: 'hackshack',
8381
});
8482
};
@@ -94,8 +92,8 @@ const Feedback = (props) => {
9492
email: yup.string().email('Invalid email format'),
9593
});
9694
const initialState = {
97-
value: feedbackvalue,
98-
email: emailvalue,
95+
value: '',
96+
email: '',
9997
};
10098
const feedbackFromik = useFormik({
10199
initialValues: initialState,

src/components/Footer/index.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
/* eslint-disable max-len */
22
/* eslint-disable react/jsx-no-undef */
3-
import React, { useContext, useState, useEffect } from 'react';
3+
import React, { useState } from 'react';
44
import { Box, Heading, Anchor } from 'grommet';
55
import axios from 'axios';
66
import { EmailCapture } from '../../containers';
77
import Feedback from '../Feedback/index';
88
import AuthService from '../../services/auth.service';
9-
import { AppContext } from '../../providers/AppProvider';
9+
// import { AppContext } from '../../providers/AppProvider';
1010

1111
const { GATSBY_WORKSHOPCHALLENGE_API_ENDPOINT } = process.env;
1212

1313
export const Footer = () => {
1414
const [isSubmissionSuccess, setIsSubmissionSuccess] = useState(undefined);
15-
const { user } = useContext(AppContext);
16-
const [useremail,setUseremail]=useState(user?.email || '');
17-
useEffect(()=>{
18-
setUseremail(user?.email || '');
19-
},[user?.email]);
2015
const sendEmail = (data) => {
2116
axios({
2217
method: 'POST',
@@ -144,8 +139,6 @@ export const Footer = () => {
144139
headerText="Help us improve the Community"
145140
bodyText="What kind of feedback do you have?"
146141
buttonText="Feedback"
147-
emailvalue= {useremail}
148-
feedbackvalue=' '
149142
handleClose={() => setIsSubmissionSuccess(undefined)}
150143
isSubmissionSuccess={isSubmissionSuccess}
151144
handleSubmit={(data) => {

0 commit comments

Comments
 (0)