Skip to content

Commit

Permalink
[Mission] fix reopen mission
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Oct 23, 2023
1 parent bee8c33 commit 73f4f38
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ context('Mission', () => {
it('A new mission with control and surveillance can be closed with all required values', () => {
// Given
cy.get('*[data-cy="add-mission"]').click()
cy.clickButton(' Enregistrer et clôturer')
cy.clickButton('Enregistrer et clôturer')
cy.wait(100)

cy.get('*[data-cy="mission-errors"]').should('exist')
Expand All @@ -24,6 +24,7 @@ context('Mission', () => {
cy.fill('Type de mission', ['Air'])
cy.get('*[data-cy="add-control-unit"]').click()
cy.get('.rs-picker-search-bar-input').type('Cross{enter}')
cy.fill("Contact de l'unité 1", 'contact').scrollIntoView()
cy.fill('Ouvert par', 'PCF').scrollIntoView()
cy.fill('Clôturé par', 'PCF').scrollIntoView()

Expand All @@ -32,7 +33,7 @@ context('Mission', () => {
// we add a control
cy.clickButton('Ajouter')
cy.clickButton('Ajouter des contrôles')
cy.clickButton(' Enregistrer et clôturer')
cy.clickButton('Enregistrer et clôturer')
cy.wait(100)

cy.get('*[data-cy="mission-errors"]').should('exist')
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/features/missions/MissionForm/MissionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,28 @@ export function MissionForm({ id, isAlreadyClosed, isNewMission, selectedMission
}

const closeMission = async () => {
await setFieldValue('isClosed', true)
validateForm().then(async errors => {
await setFieldValue('isClosed', false)
validateForm({ ...values, isClosed: true }).then(async errors => {
if (_.isEmpty(errors)) {
handleSubmit()
} else {
await setFieldValue('isClosed', false)
setShouldValidateOnChange(true)
await setFieldValue('isClosed', true)

return handleSubmit()
}

return setShouldValidateOnChange(true)
})
}

const reopenMission = () => {
validateForm({ ...values, isClosed: false }).then(errors => {
validateForm({ ...values, isClosed: false }).then(async errors => {
if (_.isEmpty(errors)) {
await setFieldValue('isClosed', false)
if (dirty) {
return setIsReopenModalOpen(true)
}

return validateReopenMission()
}
setFieldValue('isClosed', true)

return setShouldValidateOnChange(true)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ export const updateTheme =
export const updateSubThemes =
(setFieldValue: (field: string, value: any) => void) => (value: string, actionIndex: number, themeIndex: number) => {
const subThemesPath = `envActions[${actionIndex}].themes.${themeIndex}.subThemes`

const protectedSpeciesPath = `envActions[${actionIndex}].themes.${themeIndex}.protectedSpecies`
setFieldValue(subThemesPath, value)
if (!value || value?.length === 0) {
setFieldValue(protectedSpeciesPath, value)
}
}
export const updateProtectedSpecies =
(setFieldValue: (field: string, value: any) => void) => (value: string, actionIndex: number, themeIndex: number) => {
Expand Down

0 comments on commit 73f4f38

Please sign in to comment.