Skip to content

Commit

Permalink
[Tech] clean front-end properties sent to the backend for controlUnit…
Browse files Browse the repository at this point in the history
…, controlUnitResource and Administration
  • Loading branch information
claire2212 authored and maximeperrault committed Jul 1, 2024
1 parent a4c2028 commit 8c12ae0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Accent, Button, DataTable, FormikCheckbox, FormikTextInput } from '@mtes-mct/monitor-ui'
import { skipToken } from '@reduxjs/toolkit/dist/query'
import { Formik } from 'formik'
import { omit } from 'lodash'
import { useCallback } from 'react'
import { useNavigate, useParams } from 'react-router'
import styled from 'styled-components'
Expand Down Expand Up @@ -39,7 +40,10 @@ export function AdministrationForm() {

const submit = useCallback(
async (administrationFormValues: AdministrationFormValues) => {
const administrationData = administrationFormValues as Administration.NewAdministrationData
const administrationData = omit(administrationFormValues, [
'controlUnitIds',
'controlUnits'
]) as Administration.NewAdministrationData

if (isNew) {
await dispatch(administrationsAPI.endpoints.createAdministration.initiate(administrationData))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// import styled from 'styled-components'

import { Accent, Button, ControlUnit, Icon, THEME } from '@mtes-mct/monitor-ui'
import { omit } from 'lodash'
import { useCallback, useState } from 'react'
import styled from 'styled-components'

Expand Down Expand Up @@ -109,12 +110,22 @@ export function ControlUnitResourceList({ controlUnit }: ControlUnitResourceList
: controlUnitResourceFormValues.name
}

const controlUnitValuesToExclude = ['controlUnit', 'station']

if (isNewControlUnitResourceFormOpen) {
await createControlUnitResource(
controlledControlUnitResourceFormValues as ControlUnit.NewControlUnitResourceData
omit(
controlledControlUnitResourceFormValues,
controlUnitValuesToExclude
) as ControlUnit.NewControlUnitResourceData
)
} else {
await updateControlUnitResource(controlledControlUnitResourceFormValues as ControlUnit.ControlUnitResourceData)
await updateControlUnitResource(
omit(
controlledControlUnitResourceFormValues,
controlUnitValuesToExclude
) as ControlUnit.ControlUnitResourceData
)
}

closeForm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@mtes-mct/monitor-ui'
import { skipToken } from '@reduxjs/toolkit/dist/query'
import { Formik } from 'formik'
import { omit } from 'lodash'
import { sortBy } from 'lodash/fp'
import { useCallback, useMemo } from 'react'
import { useNavigate, useParams } from 'react-router'
Expand Down Expand Up @@ -78,7 +79,14 @@ export function ControlUnitForm() {

const submit = useCallback(
async (controlUnitFormValues: ControlUnitFormValues) => {
const controlUnitData = controlUnitFormValues as ControlUnit.NewControlUnitData
const controlUnitData = omit(controlUnitFormValues, [
'administration',
'controlUnitContactIds',
'controlUnitContacts',
'controlUnitResourceIds',
'controlUnitResources',
'departmentArea'
]) as ControlUnit.NewControlUnitData

if (isNew) {
await dispatch(controlUnitsAPI.endpoints.createControlUnit.initiate(controlUnitData))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Station } from '../../../../domain/entities/station'

export function getStationDataFromStationFormValues(baseFormValues: StationFormValues): Station.StationData {
return {
...omit(['coordinates'], baseFormValues),
...omit(['coordinates', 'controlUnitResourceIds', 'controlUnitResources'], baseFormValues),
latitude: baseFormValues.coordinates![0],
longitude: baseFormValues.coordinates![1]
} as Station.StationData
Expand Down

0 comments on commit 8c12ae0

Please sign in to comment.