File tree Expand file tree Collapse file tree
src/providers/SurveyProvider Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " @equinor/amplify-component-lib" ,
3- "version" : " 12.0.5 " ,
3+ "version" : " 12.0.6 " ,
44 "description" : " Frontend Typescript components for the Amplify team" ,
55 "main" : " dist/index.js" ,
66 "types" : " dist/index.d.ts" ,
5252 },
5353 "devDependencies" : {
5454 "@equinor/eds-icons" : " ^0.22.0" ,
55- "@equinor/subsurface-app-management" : " 5.4.6 " ,
55+ "@equinor/subsurface-app-management" : " 5.4.7 " ,
5656 "@eslint/js" : " ^9.22.0" ,
5757 "@faker-js/faker" : " ^9.6.0" ,
5858 "@storybook/addon-coverage" : " ^2.0.0" ,
114114 "@equinor/eds-core-react" : " 0.44.0" ,
115115 "@equinor/eds-data-grid-react" : " ^0.7.5" ,
116116 "@equinor/eds-icons" : " *" ,
117- "@equinor/subsurface-app-management" : " ^5.4.6 " ,
117+ "@equinor/subsurface-app-management" : " ^5.4.7 " ,
118118 "@tanstack/react-query" : " *" ,
119119 "@tanstack/react-router" : " *" ,
120120 "@tiptap/core" : " ^3.1.0" ,
Original file line number Diff line number Diff line change 77 * - Please do NOT modify this file.
88 */
99
10- const PACKAGE_VERSION = '2.13.3 '
10+ const PACKAGE_VERSION = '2.13.6 '
1111const INTEGRITY_CHECKSUM = '4db4a41e972cec1b64cc569c66952d82'
1212const IS_MOCKED_RESPONSE = Symbol ( 'isMockedResponse' )
1313const activeClientIds = new Set ( )
Original file line number Diff line number Diff line change @@ -32,11 +32,14 @@ export const SurveyDialog: FC = () => {
3232 if ( ! currentAnswer ) return ;
3333
3434 setIsAnswering ( true ) ;
35- await answerQuestion ( {
36- ...currentAnswer ,
37- selectedOptionIds : currentAnswer ?. selectedOptionIds ?? [ ] ,
38- } ) ;
39- setIsAnswering ( false ) ;
35+ try {
36+ await answerQuestion ( {
37+ ...currentAnswer ,
38+ selectedOptionIds : currentAnswer ?. selectedOptionIds ?? [ ] ,
39+ } ) ;
40+ } finally {
41+ setIsAnswering ( false ) ;
42+ }
4043 } ;
4144
4245 const disabledNextAction = ( ) => {
Original file line number Diff line number Diff line change @@ -59,6 +59,12 @@ const surveyHandlers = [
5959 } ;
6060 return HttpResponse . json ( answerId ) ;
6161 } ) ,
62+ http . put (
63+ '*/api/v1/surveys/:surveyResponseId/responses/me/finalize' ,
64+ async ( ) => {
65+ return HttpResponse . text ( 'OK' ) ;
66+ }
67+ ) ,
6268] ;
6369
6470const standardSurvey : UserSurveyVm = {
Original file line number Diff line number Diff line change @@ -177,3 +177,46 @@ test('Sets activeQuestionIndex to the last unanswered question if some questions
177177 ) ;
178178 await waitFor ( ( ) => expect ( result . current . activeQuestionIndex ) . toBe ( 1 ) ) ;
179179} ) ;
180+
181+ test ( 'Calls show from confetti provider if showConfettiOnComplete: true' , async ( {
182+ worker,
183+ } ) => {
184+ const survey : UserSurveyVm = {
185+ surveyId : {
186+ value : 'some-id' ,
187+ } ,
188+ status : SurveyResponseStatus . IN_PROGRESS ,
189+ surveyType : SurveyType . DEFAULT ,
190+ applicationId : 'some-app' ,
191+ title : 'This is the title' ,
192+ description : '' ,
193+ startAt : '' ,
194+ endAt : '' ,
195+ showConfettiOnComplete : true ,
196+ questions : [
197+ {
198+ questionId : { value : 'id1' } ,
199+ questionText : 'Hei' ,
200+ type : QuestionType . TEXT ,
201+ order : 1 ,
202+ answer : {
203+ answerId : { value : 'id2' } ,
204+ textAnswer : 'Something or other' ,
205+ } ,
206+ } ,
207+ ] ,
208+ } ;
209+ worker . use (
210+ http . get ( '*/api/v1/surveys/applications/:applicationName/me' , ( ) =>
211+ HttpResponse . json ( survey )
212+ )
213+ ) ;
214+
215+ const { result } = renderHook ( ( ) => useSurvey ( ) , { wrapper : TestProviders } ) ;
216+
217+ await waitFor ( ( ) =>
218+ expect ( result . current . activeSurvey ?. surveyId . value ) . toBe (
219+ survey . surveyId . value
220+ )
221+ ) ;
222+ } ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
1313 AnswerQuestionCommandDto ,
1414 useActiveSurvey ,
1515 useAnswerQuestionActiveSurvey ,
16+ useCompleteActiveSurvey ,
1617 useRespondActiveSurvey ,
1718 UserSurveyVm ,
1819} from '@equinor/subsurface-app-management' ;
@@ -63,6 +64,7 @@ export const SurveyProvider: FC<SurveyProviderProps> = ({ children }) => {
6364 const initializedQuestionIndex = useRef < string | undefined > ( undefined ) ;
6465 const { mutateAsync : respondActiveSurvey } = useRespondActiveSurvey ( ) ;
6566 const { mutateAsync : answerQuestion } = useAnswerQuestionActiveSurvey ( ) ;
67+ const { mutate : completeSurvey } = useCompleteActiveSurvey ( ) ;
6668
6769 useEffect ( ( ) => {
6870 if (
@@ -78,7 +80,9 @@ export const SurveyProvider: FC<SurveyProviderProps> = ({ children }) => {
7880 } , [ activeSurvey ] ) ;
7981
8082 const handleCompleteSurvey = ( ) => {
81- if ( ! activeSurvey ) return ;
83+ if ( ! activeSurvey || ! activeSurvey . surveyResponseId ) return ;
84+
85+ completeSurvey ( activeSurvey . surveyResponseId . value ) ;
8286
8387 showToast ( {
8488 variant : 'success' ,
@@ -87,13 +91,15 @@ export const SurveyProvider: FC<SurveyProviderProps> = ({ children }) => {
8791 duration : 5 ,
8892 } ) ;
8993
94+ /* v8 ignore start */
9095 if ( activeSurvey . showConfettiOnComplete ) {
9196 shower ( {
9297 mode : 'shower' ,
9398 shapes : [ 'square' ] ,
9499 duration : 5000 ,
95100 } ) ;
96101 }
102+ /* v8 ignore end */
97103 } ;
98104
99105 const handleAnswerQuestion = async (
You can’t perform that action at this time.
0 commit comments