Skip to content

Commit

Permalink
[Mission] Correction de l'affichage de la modale quand une action est…
Browse files Browse the repository at this point in the history
… enregistrée (#3080)

## Linked issues

- Resolve #3024
- Relatif au 1er commentaire :
#3024 (comment)

----

- [ ] Tests E2E (Cypress)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced mission form functionality to improve user experience during
mission creation and editing.
- **Bug Fixes**
- Fixed an issue where a modal confirmation would incorrectly appear due
to form status not updating properly after submission.
- **Refactor**
- Optimized mission saving logic for better performance and reliability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
louptheron committed Apr 3, 2024
2 parents fd0004c + 6d143de commit 76d7d73
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,52 @@ context('Side Window > Mission Form > Sea Control Edition', () => {
cy.wait(250)
cy.get('.Toastify__toast--success').should('not.exist')
})

/**
* Non-regression test to prevent the modal to be showed when an action is created.
* The `isDirty` field was not reset after a POST request.
*/
it('Should not show an unsaved modal confirmation When an action is created', () => {
// Given
editSideWindowMissionListMissionWithId(34, SeaFrontGroup.MEMN)
cy.intercept('POST', '/api/v1/missions/34', {
body: {
id: 1
},
statusCode: 201
})
cy.intercept('DELETE', '/bff/v1/mission_actions/*', {
body: {
id: 2
},
statusCode: 200
})
cy.intercept('POST', '/bff/v1/mission_actions', {
body: {
id: 1
},
statusCode: 201
}).as('updateAction')
cy.clickButton('Supprimer l’action')
cy.wait(500)

// When
cy.clickButton('Ajouter')
cy.clickButton('Ajouter un contrôle à la débarque')

// eslint-disable-next-line @typescript-eslint/no-unused-expressions
cy.get('input[placeholder="Rechercher un navire..."]').type('pheno').wait(250)
cy.contains('mark', 'PHENO').click()
cy.get('#port').parent().click({ force: true })
cy.get('.rs-search-box-input').type('saintmalo{enter}', { force: true })
// Should select the right port
cy.get('.Field-Select').contains('Saint-Malo (FRSML)')
cy.fill('Saisi par', 'Marlin')
cy.wait('@updateAction')
cy.wait(500)

// Then
cy.clickButton('Fermer')
cy.get('.Component-Dialog').should('not.exist')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const autoSaveMissionAction =
missionActionApi.endpoints.createMissionAction.initiate(missionActionData)
).unwrap()

dispatch(missionFormActions.setIsDraftDirty(false))

return id
}

Expand Down
14 changes: 10 additions & 4 deletions frontend/src/features/Mission/useCases/saveMission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const saveMission =
monitorenvMissionApi.endpoints.createMission.initiate(newMission)
).unwrap()

initIsDraftDirtyAndListenToEvents()

return {
...nextMainFormValues,
createdAtUtc: createdMission.createdAtUtc,
Expand All @@ -35,10 +37,7 @@ export const saveMission =
const nextMission = getUpdatedMissionFromMissionMainFormValues(missionId, nextMainFormValues)
const updatedMission = await dispatch(monitorenvMissionApi.endpoints.updateMission.initiate(nextMission)).unwrap()

dispatch(missionFormActions.setIsDraftDirty(false))
setTimeout(() => {
dispatch(missionFormActions.setIsListeningToEvents(true))
}, 500)
initIsDraftDirtyAndListenToEvents()

return {
...nextMainFormValues,
Expand All @@ -54,4 +53,11 @@ export const saveMission =

return nextMainFormValues
}

function initIsDraftDirtyAndListenToEvents() {
dispatch(missionFormActions.setIsDraftDirty(false))
setTimeout(() => {
dispatch(missionFormActions.setIsListeningToEvents(true))
}, 500)
}
}

0 comments on commit 76d7d73

Please sign in to comment.