Skip to content

Commit

Permalink
Fix slice name in getVesselReportings() use case
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Oct 8, 2024
1 parent 01e9daf commit b85b78c
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions frontend/src/features/Reporting/useCases/getVesselReportings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Promise<void>> =>
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())
}
}
}

0 comments on commit b85b78c

Please sign in to comment.