Skip to content

Commit

Permalink
[Review] code review
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed May 23, 2023
1 parent 966b98d commit c3b4b5d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
15 changes: 6 additions & 9 deletions frontend/src/features/missions/MissionForm/ActionsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,19 @@ export function ActionsForm({ currentActionIndex, form, remove, setCurrentAction
})
})
)
if (envActions?.length === 0) {
setCurrentActionIndex(0)
}

setCurrentActionIndex(0)
}

const handleAddControlAction = () => {
unshift(actionFactory({ actionType: ActionTypeEnum.CONTROL }))
if (envActions?.length === 0) {
setCurrentActionIndex(0)
}

setCurrentActionIndex(0)
}
const handleAddNoteAction = () => {
unshift(actionFactory({ actionType: ActionTypeEnum.NOTE }))
if (envActions?.length === 0) {
setCurrentActionIndex(0)
}

setCurrentActionIndex(0)
}
const handleSelectAction = id => () => setCurrentActionIndex(envActions && envActions.findIndex(a => a.id === id))
const handleRemoveAction = id => e => {
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/features/missions/MissionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function Mission() {

const missionFormikValues = useMemo(() => {
if (!id) {
return missionFactory(undefined)
return missionFactory()
}

return missionFactory(missionToEdit)
Expand Down Expand Up @@ -62,11 +62,9 @@ export function Mission() {
validateOnMount={false}
validationSchema={MissionSchema}
>
{() => (
<FormikForm>
<MissionForm id={id} mission={missionToEdit} setShouldValidateOnChange={setShouldValidateOnChange} />
</FormikForm>
)}
<FormikForm>
<MissionForm id={id} mission={missionToEdit} setShouldValidateOnChange={setShouldValidateOnChange} />
</FormikForm>
</Formik>
</EditMissionWrapper>
)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/features/missions/Missions.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const actionFactory = ({
}
}

export const missionFactory = (mission: Mission | undefined): Mission | NewMission => {
export const missionFactory = (mission?: Mission | undefined): Mission | NewMission => {
let formattedMission = {
closedBy: '',
controlUnits: [controlUnitFactory()],
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/hooks/useSyncFormValuesWithRedux.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useFormikContext } from 'formik'
import _ from 'lodash'
import { useEffect, useMemo } from 'react'
import { useDispatch } from 'react-redux'

import { setIsFormDirty } from '../domain/shared_slices/MissionsState'
import { useAppDispatch } from './useAppDispatch'

export const useSyncFormValuesWithRedux = (setFormValues: (values) => void) => {
import type { ActionCreatorWithPayload } from '@reduxjs/toolkit'

export const useSyncFormValuesWithRedux = (setFormValues: ActionCreatorWithPayload<any, string>) => {
const { dirty, values } = useFormikContext()
const dispatch = useDispatch()
const dispatch = useAppDispatch()

const dispatchFormUpdate = useMemo(() => {
const throttled = newValues => {
Expand Down

0 comments on commit c3b4b5d

Please sign in to comment.