@@ -4,7 +4,6 @@ import { toast } from 'react-toastify';
44import { useMutation , useQueryClient } from '@tanstack/react-query' ;
55
66import { ContextNotProvided } from 'src/core/contexts/context' ;
7- import { useDisplayError } from 'src/core/errorHandling/DisplayErrorProvider' ;
87import { useApplicationMetadata } from 'src/features/applicationMetadata/ApplicationMetadataProvider' ;
98import { useHasPendingScans } from 'src/features/attachments/useHasPendingScans' ;
109import { invalidateFormDataQueries } from 'src/features/formData/useFormDataQuery' ;
@@ -18,10 +17,10 @@ import { useOnFormSubmitValidation } from 'src/features/validation/callbacks/onF
1817import { Validation } from 'src/features/validation/validationContext' ;
1918import { TaskKeys , useNavigateToTask } from 'src/hooks/useNavigatePage' ;
2019import { doProcessNext } from 'src/queries/queries' ;
21- import { ELEMENT_TYPE , type IActionType , type IProcess } from 'src/types/shared' ;
2220import { isAtLeastVersion } from 'src/utils/versionCompare' ;
2321import type { ApplicationMetadata } from 'src/features/applicationMetadata/types' ;
2422import type { BackendValidationIssue } from 'src/features/validation' ;
23+ import type { IActionType , IProcess , ProblemDetails } from 'src/types/shared' ;
2524import type { HttpClientError } from 'src/utils/network/sharedNetworking' ;
2625
2726interface ProcessNextProps {
@@ -31,15 +30,14 @@ interface ProcessNextProps {
3130export function useProcessNext ( ) {
3231 const reFetchInstanceData = useStrictInstanceRefetch ( ) ;
3332 const language = useCurrentLanguage ( ) ;
34- const { refetch : refetchProcessData } = useProcessQuery ( ) ;
33+ const { data : process , refetch : refetchProcessData } = useProcessQuery ( ) ;
3534 const navigateToTask = useNavigateToTask ( ) ;
3635 const instanceId = useLaxInstanceId ( ) ;
3736 const onFormSubmitValidation = useOnFormSubmitValidation ( ) ;
3837 const updateInitialValidations = useUpdateInitialValidations ( ) ;
3938 const setShowAllBackendErrors = Validation . useSetShowAllBackendErrors ( ) ;
4039 const onSubmitFormValidation = useOnFormSubmitValidation ( ) ;
4140 const applicationMetadata = useApplicationMetadata ( ) ;
42- const displayError = useDisplayError ( ) ;
4341 const queryClient = useQueryClient ( ) ;
4442 const hasPendingScans = useHasPendingScans ( ) ;
4543
@@ -93,17 +91,20 @@ export function useProcessNext() {
9391 }
9492 }
9593 } ,
96- onError : async ( error : HttpClientError ) => {
94+ onError : async ( error : HttpClientError < ProblemDetails | undefined > ) => {
9795 window . logError ( 'Process next failed:\n' , error ) ;
98- const { data : process } = await refetchProcessData ( ) ;
99- const currentTask = process ?. currentTask ;
100- const isCurrentTaskServiceTask = currentTask && currentTask . elementType === ELEMENT_TYPE . SERVICE_TASK ;
96+ const { data : newProcess } = await refetchProcessData ( ) ;
97+ const newCurrentTask = newProcess ?. currentTask ;
10198
102- if ( isCurrentTaskServiceTask ) {
103- navigateToTask ( currentTask . elementId ) ;
104- } else {
105- displayError ( error ) ;
99+ if ( newCurrentTask ?. elementId && newCurrentTask ?. elementId !== process ?. currentTask ?. elementId ) {
100+ await reFetchInstanceData ( ) ;
101+ navigateToTask ( newCurrentTask . elementId ) ;
106102 }
103+
104+ toast ( < Lang id = { error . response ?. data ?. detail ?? error . message ?? 'process_error.submit_error_please_retry' } /> , {
105+ type : 'error' ,
106+ autoClose : false ,
107+ } ) ;
107108 } ,
108109 } ) ;
109110
0 commit comments