@@ -2,6 +2,7 @@ import React from 'react';
2
2
import FileUploadComponent from '../../components/FileUploadComponent' ;
3
3
import { getCurrentFeedbackForm } from '../flow-context-utils' ;
4
4
import { createOptionalFieldValidator , processOptionalInput } from '../optional-field-utils' ;
5
+ import { validateEmail , isValidEmail } from '../validation-utils' ;
5
6
6
7
/**
7
8
* Creates the feedback conversation flow
@@ -31,13 +32,32 @@ export const createFeedbackFlow = ({
31
32
return {
32
33
feedback : {
33
34
message : "We appreciate your feedback about ACCESS.\n\nFeedback submitted through this form will only be shared within the ACCESS teams. We encourage the sharing of contact information for potential follow-up, but understand that anonymity may be preferred when providing feedback on sensitive issues.\n\nPlease provide your detailed feedback:" ,
34
- function : ( chatState ) => setFeedbackForm ( { ...( feedbackForm || { } ) , feedback : chatState . userInput } ) ,
35
+ function : ( chatState ) => {
36
+ // Clear any previous feedback form state to start fresh
37
+ setFeedbackForm ( {
38
+ feedback : chatState . userInput ,
39
+ // Explicitly clear all other fields to prevent state persistence
40
+ recommendations : undefined ,
41
+ primaryRole : undefined ,
42
+ needsCustomRole : false ,
43
+ customRole : undefined ,
44
+ communityInterest : undefined ,
45
+ upload : undefined ,
46
+ uploadConfirmed : false ,
47
+ uploadedFiles : undefined ,
48
+ wantsContact : undefined ,
49
+ useCustomContactInfo : false ,
50
+ customName : undefined ,
51
+ customEmail : undefined ,
52
+ customAccessId : undefined
53
+ } ) ;
54
+ } ,
35
55
path : "feedback_please_tell_us_more"
36
56
} ,
37
57
feedback_please_tell_us_more : {
38
58
message : "Please detail any recommendations for improvement:" ,
39
59
function : ( chatState ) => setFeedbackForm ( { ...( feedbackForm || { } ) , recommendations : chatState . userInput } ) ,
40
- path : "feedback_primary_role "
60
+ path : "feedback_upload "
41
61
} ,
42
62
feedback_primary_role : {
43
63
message : "What is your primary role pertaining to ACCESS?" ,
@@ -60,7 +80,7 @@ export const createFeedbackFlow = ({
60
80
}
61
81
} ,
62
82
path : ( chatState ) => {
63
- return chatState . userInput === "Other" ? "feedback_custom_role" : "feedback_community_interest " ;
83
+ return chatState . userInput === "Other" ? "feedback_custom_role" : "feedback_contact_choice " ;
64
84
}
65
85
} ,
66
86
feedback_custom_role : {
@@ -69,7 +89,7 @@ export const createFeedbackFlow = ({
69
89
const currentForm = getCurrentFeedbackForm ( ) ;
70
90
setFeedbackForm ( { ...currentForm , customRole : chatState . userInput } ) ;
71
91
} ,
72
- path : "feedback_community_interest "
92
+ path : "feedback_contact_choice "
73
93
} ,
74
94
feedback_community_interest : {
75
95
message : "Are you interested, or potentially interested, in serving the ACCESS community and helping us improve in any of these roles? (This is not a commitment. We'll reach out with more information.) Select all that apply:" ,
@@ -91,7 +111,7 @@ export const createFeedbackFlow = ({
91
111
const currentForm = getCurrentFeedbackForm ( ) ;
92
112
setFeedbackForm ( { ...currentForm , communityInterest : chatState . userInput } ) ;
93
113
} ,
94
- path : "feedback_upload "
114
+ path : "feedback_summary "
95
115
} ,
96
116
feedback_upload : {
97
117
message : "Would you like to upload a screenshot or file to help us better understand your feedback?" ,
@@ -102,7 +122,7 @@ export const createFeedbackFlow = ({
102
122
if ( chatState . userInput === "Yes" ) {
103
123
return "feedback_upload_yes" ;
104
124
} else {
105
- return "feedback_contact_choice " ;
125
+ return "feedback_primary_role " ;
106
126
}
107
127
}
108
128
} ,
@@ -112,7 +132,7 @@ export const createFeedbackFlow = ({
112
132
options : [ "Continue" ] ,
113
133
chatDisabled : true ,
114
134
function : ( chatState ) => setFeedbackForm ( { ...( feedbackForm || { } ) , uploadConfirmed : true } ) ,
115
- path : "feedback_contact_choice "
135
+ path : "feedback_primary_role "
116
136
} ,
117
137
feedback_contact_choice : {
118
138
message : "Would you like to provide your contact information for follow up?" ,
@@ -134,8 +154,14 @@ export const createFeedbackFlow = ({
134
154
return "feedback_contact_confirm" ;
135
155
}
136
156
// Otherwise collect missing info - set flag to use custom info
157
+ // Use the updatedForm from the function above to preserve wantsContact
137
158
const currentForm = getCurrentFeedbackForm ( ) ;
138
- setFeedbackForm ( { ...currentForm , useCustomContactInfo : true } ) ;
159
+ const wantsContact = chatState . userInput === "Include my contact info" ;
160
+ setFeedbackForm ( {
161
+ ...currentForm ,
162
+ useCustomContactInfo : true ,
163
+ wantsContact : wantsContact ? "Yes" : "No"
164
+ } ) ;
139
165
if ( ! userInfo . name ) return "feedback_name" ;
140
166
if ( ! userInfo . email ) return "feedback_email" ;
141
167
if ( ! userInfo . username ) return "feedback_accessid" ;
@@ -163,7 +189,7 @@ export const createFeedbackFlow = ({
163
189
} ,
164
190
path : ( chatState ) => {
165
191
if ( chatState . userInput === "Use this information" ) {
166
- return "feedback_summary " ;
192
+ return "feedback_community_interest " ;
167
193
} else {
168
194
return "feedback_name" ;
169
195
}
@@ -179,6 +205,7 @@ export const createFeedbackFlow = ({
179
205
} ,
180
206
feedback_email : {
181
207
message : "What is your email address?" ,
208
+ validateTextInput : ( email ) => validateEmail ( email ) ,
182
209
function : ( chatState ) => {
183
210
const currentForm = getCurrentFeedbackForm ( ) ;
184
211
setFeedbackForm ( { ...currentForm , customEmail : chatState . userInput } ) ;
@@ -192,7 +219,7 @@ export const createFeedbackFlow = ({
192
219
const currentForm = getCurrentFeedbackForm ( ) ;
193
220
setFeedbackForm ( { ...currentForm , customAccessId : processOptionalInput ( chatState . userInput ) } ) ;
194
221
} ,
195
- path : "feedback_summary "
222
+ path : "feedback_community_interest "
196
223
} ,
197
224
feedback_summary : {
198
225
message : ( chatState ) => {
@@ -229,7 +256,7 @@ export const createFeedbackFlow = ({
229
256
`ACCESS ID: ${ finalAccessId } \n` +
230
257
'' ;
231
258
} else {
232
- contactInfo = `Contact Information: Not provided \n` ;
259
+ contactInfo = `Contact Information: Anonymous submission \n` ;
233
260
}
234
261
235
262
// Format primary role
@@ -238,20 +265,30 @@ export const createFeedbackFlow = ({
238
265
primaryRole = `Other: ${ currentForm . customRole } ` ;
239
266
}
240
267
241
- // Format community interest
242
- let communityInterest = 'Not provided' ;
243
- if ( currentForm . communityInterest && Array . isArray ( currentForm . communityInterest ) ) {
244
- communityInterest = currentForm . communityInterest . join ( ', ' ) ;
245
- } else if ( currentForm . communityInterest ) {
246
- communityInterest = currentForm . communityInterest ;
268
+ // Format community interest - handle timing issue like ACCESS ID (only for non-anonymous)
269
+ let communityInterestLine = '' ;
270
+ if ( currentForm . wantsContact === "Yes" ) {
271
+ let communityInterest = 'Not provided' ;
272
+
273
+ // If coming directly from community interest step, use chatState.userInput
274
+ if ( chatState . prevPath === 'feedback_community_interest' ) {
275
+ communityInterest = chatState . userInput || 'Not provided' ;
276
+ } else if ( currentForm . communityInterest && Array . isArray ( currentForm . communityInterest ) ) {
277
+ communityInterest = currentForm . communityInterest . join ( ', ' ) ;
278
+ } else if ( currentForm . communityInterest ) {
279
+ communityInterest = currentForm . communityInterest ;
280
+ }
281
+
282
+ communityInterestLine = `Community Interest: ${ communityInterest } \n` ;
247
283
}
248
284
249
285
return `Thank you for providing your feedback. Here's a summary:\n\n` +
250
286
contactInfo +
251
287
`Feedback: ${ currentForm . feedback || 'Not provided' } \n` +
252
288
`Recommendations: ${ currentForm . recommendations || 'Not provided' } \n` +
253
289
`Primary Role: ${ primaryRole } \n` +
254
- `Community Interest: ${ communityInterest } ${ fileInfo } \n\n` +
290
+ communityInterestLine +
291
+ `${ fileInfo } \n\n` +
255
292
`Would you like to submit this feedback?` ;
256
293
} ,
257
294
options : [ "Submit Feedback" , "Back to Main Menu" ] ,
@@ -265,7 +302,27 @@ export const createFeedbackFlow = ({
265
302
}
266
303
} ,
267
304
feedback_success : {
268
- message : "Thank you for your feedback! If you provided your contact information, we will follow up with you shortly." ,
305
+ message : ( ) => {
306
+ const currentForm = getCurrentFeedbackForm ( ) ;
307
+ const baseMessage = "Thank you for your feedback!" ;
308
+
309
+ // Determine if they provided a valid email (using same logic as summary)
310
+ let finalEmail ;
311
+ if ( currentForm . wantsContact === "No" ) {
312
+ finalEmail = null ;
313
+ } else if ( currentForm . useCustomContactInfo ) {
314
+ finalEmail = currentForm . customEmail ;
315
+ } else {
316
+ finalEmail = userInfo . email ;
317
+ }
318
+
319
+ // Only add follow-up message if they provided a valid email
320
+ if ( finalEmail && finalEmail . trim ( ) && isValidEmail ( finalEmail ) ) {
321
+ return `${ baseMessage } We will follow up with you shortly.` ;
322
+ }
323
+
324
+ return baseMessage ;
325
+ } ,
269
326
options : [ "Back to Main Menu" ] ,
270
327
chatDisabled : true ,
271
328
path : "start"
0 commit comments