Skip to content

Commit

Permalink
fix: save data before logout on firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Jul 9, 2024
1 parent 45904d1 commit 34c60fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/pages/Collect/CollectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
} from 'api/06-survey-units'
import type { StateData } from 'model/StateData'
import { Orchestrator } from 'shared/components/Orchestrator/Orchestrator'
import type { LunaticGetReferentiel, Nomenclature } from 'shared/components/Orchestrator/utils/lunaticType'
import type {
LunaticGetReferentiel,
Nomenclature,
} from 'shared/components/Orchestrator/utils/lunaticType'
import { showToast } from 'shared/toast/Toast'
import { collectRoute } from './route'

Expand All @@ -31,7 +34,7 @@ export function CollectPage() {
data: LunaticData['COLLECTED']
onSuccess?: () => void
}) =>
mutationUpdateDataStateData.mutate(
mutationUpdateDataStateData.mutateAsync(
{
id: surveyUnitId,
data: { data: params.data, stateData: params.stateData }, //Waiting for API to accept request with undefined data
Expand All @@ -56,6 +59,7 @@ export function CollectPage() {
"Une erreur est survenue lors de l'enregistrement de vos modifications. ",
})
},

}
)

Expand Down
7 changes: 4 additions & 3 deletions src/shared/components/Orchestrator/Orchestrator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export namespace OrchestratorProps {
stateData: StateData
data: LunaticData['COLLECTED']
onSuccess?: () => void
}) => void
}) => Promise<void>
getDepositProof: () => Promise<void>
}
}
Expand Down Expand Up @@ -179,19 +179,20 @@ export function Orchestrator(props: OrchestratorProps) {
})
})

useAddPreLogoutAction(() => {
useAddPreLogoutAction(async () => {
if (mode !== 'collect') return

const { updateDataAndStateData } = props

const data = getChangedData()

updateDataAndStateData({
return updateDataAndStateData({
stateData: getCurrentStateData(),
data: isObjectEmpty(data.COLLECTED ?? {}) ? undefined : data.COLLECTED,
onSuccess: resetChangedData,
})
})

// Persist data and stateData when page change in "collect" mode
useUpdateEffect(() => {
if (mode !== 'collect') return
Expand Down

0 comments on commit 34c60fe

Please sign in to comment.