diff --git a/frontend/src/features/Reporting/useCases/getVesselReportings.ts b/frontend/src/features/Reporting/useCases/getVesselReportings.ts index c4e645536b..84f43d7b70 100644 --- a/frontend/src/features/Reporting/useCases/getVesselReportings.ts +++ b/frontend/src/features/Reporting/useCases/getVesselReportings.ts @@ -6,40 +6,44 @@ import { removeError } from '../../../domain/shared_slices/Global' import { displayOrLogError } from '../../../domain/use_cases/error/displayOrLogError' import { mainWindowReportingActions } from '../mainWindowReporting.slice' -export const getVesselReportings = (isLoaderShowed: boolean) => async (dispatch, getState) => { - const { selectedVesselIdentity } = getState().vessel - const { archivedReportingsFromDate, isLoadingReporting } = getState().reporting - if (!selectedVesselIdentity || isLoadingReporting) { - return - } +import type { MainAppThunk } from '@store' - if (isLoaderShowed) { - dispatch(displayedErrorActions.unset(DisplayedErrorKey.VESSEL_SIDEBAR_ERROR)) - dispatch(mainWindowReportingActions.loadReporting()) - } +export const getVesselReportings = + (isLoaderShowed: boolean): MainAppThunk> => + async (dispatch, getState) => { + const { selectedVesselIdentity } = getState().vessel + const { archivedReportingsFromDate, isLoadingReporting } = getState().mainWindowReporting + if (!selectedVesselIdentity || isLoadingReporting) { + return + } + + if (isLoaderShowed) { + dispatch(displayedErrorActions.unset(DisplayedErrorKey.VESSEL_SIDEBAR_ERROR)) + dispatch(mainWindowReportingActions.loadReporting()) + } - try { - const nextSelectedVesselReportings = await getVesselReportingsFromAPI( - selectedVesselIdentity, - archivedReportingsFromDate - ) - dispatch( - mainWindowReportingActions.setSelectedVesselReportings({ - selectedVesselReportings: nextSelectedVesselReportings, - vesselIdentity: selectedVesselIdentity - }) - ) + try { + const nextSelectedVesselReportings = await getVesselReportingsFromAPI( + selectedVesselIdentity, + archivedReportingsFromDate + ) + dispatch( + mainWindowReportingActions.setSelectedVesselReportings({ + selectedVesselReportings: nextSelectedVesselReportings, + vesselIdentity: selectedVesselIdentity + }) + ) - dispatch(removeError()) - } catch (error) { - dispatch( - displayOrLogError( - error as Error, - () => getVesselReportings(isLoaderShowed), - isLoaderShowed, - DisplayedErrorKey.VESSEL_SIDEBAR_ERROR + dispatch(removeError()) + } catch (error) { + dispatch( + displayOrLogError( + error as Error, + () => getVesselReportings(isLoaderShowed), + isLoaderShowed, + DisplayedErrorKey.VESSEL_SIDEBAR_ERROR + ) ) - ) - dispatch(mainWindowReportingActions.resetSelectedVesselReportings()) + dispatch(mainWindowReportingActions.resetSelectedVesselReportings()) + } } -}