@@ -4,6 +4,7 @@ import Layout from "../../src/components/Layout";
4
4
import propsWithContainer from "../../src/middleware/propsWithContainer" ;
5
5
import { v4 as uuidv4 } from "uuid" ;
6
6
import Router from "next/router" ;
7
+ import absoluteUrl from "next-absolute-url" ;
7
8
8
9
/*
9
10
The end UR question is a page that should be navigated to after a call ends but
@@ -12,122 +13,137 @@ to the event logging system - this is distinct from console logging and concerns
12
13
things to do with the user journey so that journeys can be tracked and we can
13
14
identify potential issues with the service.
14
15
*/
15
- export default function EndUrQuestion ( { correlationId, callId } ) {
16
- let selectedFeedback ;
17
16
18
- const selectFeedbackOption = ( option ) => ( /*event*/ ) => {
19
- selectedFeedback = option ;
20
- } ;
17
+ export const endUrQuestionConstructor = ( { router } ) =>
18
+ function EndUrQuestion ( { correlationId, callId, protocol, host } ) {
19
+ let selectedFeedback ;
20
+ const selectFeedbackOption = ( option ) => ( /*event*/ ) => {
21
+ selectedFeedback = option ;
22
+ } ;
21
23
22
- const onSubmit = async ( event ) => {
23
- await fetchEndpointWithCorrelationId (
24
- "POST" ,
25
- "http://localhost:3001/api/submit-ur-answer" ,
26
- JSON . stringify ( {
27
- "would miss nhs vv" : selectedFeedback ,
28
- } ) ,
29
- correlationId
30
- ) ;
24
+ const onSubmit = async ( event ) => {
25
+ event . preventDefault ( ) ;
26
+ router . push ( `/visits/end?callId=${ callId } ` ) ;
31
27
32
- Router . push ( `/visits/end?callId=${ callId } ` ) ;
33
- event . preventDefault ( ) ;
34
- } ;
35
- const onClickSkip = async ( ) => {
36
- Router . push ( `/visits/end?callId=${ callId } ` ) ;
37
- } ;
28
+ try {
29
+ await fetchEndpointWithCorrelationId (
30
+ "POST" ,
31
+ `${ protocol } //${ host } /api/submit-ur-answer` ,
32
+ JSON . stringify ( {
33
+ "would miss nhs vv" : selectedFeedback ,
34
+ } ) ,
35
+ correlationId
36
+ ) ;
37
+ } catch {
38
+ console . error ( "Could not submit UR answer" ) ;
39
+ }
40
+ } ;
41
+ const onClickSkip = async ( ) => {
42
+ router . push ( `/visits/end?callId=${ callId } ` ) ;
43
+ } ;
38
44
39
- useEffect ( ( ) => {
40
- console . log ( correlationId ) ;
41
- } , [ ] ) ;
45
+ useEffect ( ( ) => {
46
+ console . log ( correlationId ) ;
47
+ } , [ ] ) ;
42
48
43
- return (
44
- < Layout title = "Submit feedback" isBookService = { false } >
45
- < div className = "nhsuk-form-group" >
46
- < form onSubmit = { onSubmit } data-testid = "ur-question-form" >
47
- < div className = "nhsuk-form-group" >
48
- < fieldset className = "nhsuk-fieldset" >
49
- < legend className = "nhsuk-fieldset__legend nhsuk-fieldset__legend--l" >
50
- < h1 className = "nhsuk-fieldset__heading" >
51
- If this service was no longer available would you be
52
- dissappointed/upset?
53
- </ h1 >
54
- </ legend >
49
+ return (
50
+ < Layout title = "Submit feedback" isBookService = { false } >
51
+ < div className = "nhsuk-form-group" >
52
+ < form onSubmit = { onSubmit } data-testid = "ur-question-form" >
53
+ < div className = "nhsuk-form-group nhsuk-u-margin-bottom-5 " >
54
+ < fieldset className = "nhsuk-fieldset" >
55
+ < legend className = "nhsuk-fieldset__legend nhsuk-fieldset__legend--l" >
56
+ < h1 className = "nhsuk-fieldset__heading" >
57
+ If this service was no longer available would you be
58
+ dissappointed/upset?
59
+ </ h1 >
60
+ </ legend >
55
61
56
- < div
57
- data-testid = "ur-question-radio-buttons"
58
- className = "nhsuk-radios"
59
- >
60
- < div className = "nhsuk-radios__item" >
61
- < input
62
- className = "nhsuk-radios__input"
63
- id = "ur-question-radio-yes"
64
- name = "ur-question-radio"
65
- type = "radio"
66
- value = "yes"
67
- data-testid = "ur-question-radio-yes"
68
- onClick = { selectFeedbackOption ( "yes" ) }
69
- />
70
- < label
71
- className = "nhsuk-label nhsuk-radios__label"
72
- htmlFor = "ur-question-radio-yes"
73
- >
74
- Yes
75
- </ label >
76
- </ div >
62
+ < div
63
+ data-testid = "ur-question-radio-buttons"
64
+ className = "nhsuk-radios"
65
+ >
66
+ < div className = "nhsuk-radios__item" >
67
+ < input
68
+ className = "nhsuk-radios__input"
69
+ id = "ur-question-radio-yes"
70
+ name = "ur-question-radio"
71
+ type = "radio"
72
+ value = "yes"
73
+ data-testid = "ur-question-radio-yes"
74
+ onClick = { selectFeedbackOption ( "yes" ) }
75
+ />
76
+ < label
77
+ className = "nhsuk-label nhsuk-radios__label"
78
+ htmlFor = "ur-question-radio-yes"
79
+ >
80
+ Yes
81
+ </ label >
82
+ </ div >
77
83
78
- < div className = "nhsuk-radios__item" >
79
- < input
80
- className = "nhsuk-radios__input"
81
- id = "ur-question-radio-no"
82
- name = "ur-question-radio"
83
- type = "radio"
84
- value = "no"
85
- data-testid = "ur-question-radio-no"
86
- onClick = { selectFeedbackOption ( "no" ) }
87
- />
88
- < label
89
- className = "nhsuk-label nhsuk-radios__label"
90
- htmlFor = "ur-question-radio-no"
91
- >
92
- No
93
- </ label >
84
+ < div className = "nhsuk-radios__item" >
85
+ < input
86
+ className = "nhsuk-radios__input"
87
+ id = "ur-question-radio-no"
88
+ name = "ur-question-radio"
89
+ type = "radio"
90
+ value = "no"
91
+ data-testid = "ur-question-radio-no"
92
+ onClick = { selectFeedbackOption ( "no" ) }
93
+ />
94
+ < label
95
+ className = "nhsuk-label nhsuk-radios__label"
96
+ htmlFor = "ur-question-radio-no"
97
+ >
98
+ No
99
+ </ label >
100
+ </ div >
94
101
</ div >
95
- </ div >
96
- </ fieldset >
97
- </ div >
98
- < button
99
- className = "nhsuk-button"
100
- data-testid = "submit-ur-question-button"
101
- type = "submit"
102
- >
103
- Submit feedback
104
- </ button >
105
- </ form >
102
+ </ fieldset >
103
+ </ div >
106
104
107
- < button
108
- className = "nhsuk-button nhsuk-button--secondary"
109
- onClick = { onClickSkip }
110
- >
111
- Skip
112
- </ button >
113
- </ div >
114
- </ Layout >
115
- ) ;
116
- }
105
+ < button
106
+ className = "nhsuk-button"
107
+ data-testid = "submit-ur-question-button"
108
+ type = "submit"
109
+ >
110
+ Submit feedback
111
+ </ button >
112
+ < button
113
+ className = "nhsuk-button nhsuk-button--secondary nhsuk-u-margin-left-5"
114
+ onClick = { onClickSkip }
115
+ >
116
+ Skip
117
+ </ button >
118
+ </ form >
119
+ </ div >
120
+ </ Layout >
121
+ ) ;
122
+ } ;
123
+
124
+ export default endUrQuestionConstructor ( { router : Router } ) ;
117
125
118
126
export const getServerSideProps = propsWithContainer (
119
- async ( { req : { headers } , res, container, query } ) => {
127
+ async ( { req, res, container, query } ) => {
128
+ const { headers } = req ;
120
129
const { callId } = query ;
130
+
131
+ if ( process . env . ENABLE_UR_QUESTION === "no" ) {
132
+ res . writeHead ( 302 , { Location : `/visits/end?callId=${ callId } ` } ) . end ( ) ;
133
+ return { } ;
134
+ }
135
+
121
136
const userIsAuthenticated = container . getUserIsAuthenticated ( ) ;
122
137
const token = await userIsAuthenticated ( headers . cookie ) ;
123
138
const correlationId = `${ uuidv4 ( ) } -ur-question` ;
139
+ const { protocol, host } = absoluteUrl ( req , "localhost:3001" ) ;
124
140
125
141
if ( token ?. ward || null ) {
126
142
res . writeHead ( 302 , { Location : `/visits/end?callId=${ callId } ` } ) . end ( ) ;
127
143
return { } ;
128
144
} else {
129
145
res . status ( 200 ) ;
130
- return { props : { correlationId, callId } } ;
146
+ return { props : { correlationId, callId, protocol , host } } ;
131
147
}
132
148
}
133
149
) ;
0 commit comments