Skip to content

Commit

Permalink
feat: typage du thunk switchtab
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeperrault committed Jun 24, 2024
1 parent 1e56ddd commit d4270da
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions frontend/src/domain/use_cases/missions/switchTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,33 @@ import { sideWindowActions } from '../../../features/SideWindow/slice'
import { getIdTyped } from '../../../utils/getIdTyped'
import { getMissionPageRoute } from '../../../utils/routes'

export const switchTab = (path: string) => async (dispatch, getState) => {
const { missions } = getState().missionForms
import type { HomeAppThunk } from '@store/index'

const routeParams = getMissionPageRoute(path)
const id = getIdTyped(routeParams?.params.id)
export const switchTab =
(path: string): HomeAppThunk =>
async (dispatch, getState) => {
const { missions } = getState().missionForms

// if we want to switch to mission list
if (!id) {
await dispatch(sideWindowActions.setCurrentPath(path))
await dispatch(missionActions.resetSelectedMissionIdOnMap())
await dispatch(missionFormsActions.resetActiveMissionId())
const routeParams = getMissionPageRoute(path)
const id = getIdTyped(routeParams?.params.id)

return
}
// if we want to switch to mission list
if (!id) {
dispatch(sideWindowActions.setCurrentPath(path))
dispatch(missionActions.resetSelectedMissionIdOnMap())
dispatch(missionFormsActions.resetActiveMissionId())

return
}

await dispatch(missionFormsActions.setActiveMissionId(id))
await dispatch(missionActions.setSelectedMissionIdOnMap(id))
dispatch(missionFormsActions.setActiveMissionId(id))
dispatch(missionActions.setSelectedMissionIdOnMap(id))

// since we are switching to another mission, we need to update the attached reportings store
// because it's the form who listen to this store
await dispatch(
attachReportingToMissionSliceActions.setAttachedReportings(missions[id]?.missionForm?.attachedReportings || [])
)
dispatch(sideWindowActions.setCurrentPath(path))

await dispatch(sideWindowActions.setCurrentPath(path))
}
// since we are switching to another mission, we need to update the attached reportings store
// because it's the form who listen to this store
dispatch(
attachReportingToMissionSliceActions.setAttachedReportings(missions[id]?.missionForm?.attachedReportings || [])

Check warning on line 35 in frontend/src/domain/use_cases/missions/switchTab.ts

View workflow job for this annotation

GitHub Actions / Run frontend unit tests

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
)
}

0 comments on commit d4270da

Please sign in to comment.