diff --git a/packages/webapp/src/containers/Task/saga.js b/packages/webapp/src/containers/Task/saga.js index c1d7166867..af8e1a162b 100644 --- a/packages/webapp/src/containers/Task/saga.js +++ b/packages/webapp/src/containers/Task/saga.js @@ -84,7 +84,7 @@ import { } from '../../util/siteMapConstants'; import { setFormData } from '../hooks/useHookFormPersist/hookFormPersistSlice'; import { formatSoilAmendmentProductToDBStructure, getSubtaskName } from '../../util/task'; -import { getEndpoint, getMovementTaskBody } from './sagaUtils'; +import { formatAnimalIdsForReqBody, getEndpoint, getMovementTaskBody } from './sagaUtils'; const taskTypeEndpoint = [ 'cleaning_task', @@ -420,6 +420,13 @@ export const getPostTaskBody = (data, endpoint, managementPlanWithCurrentLocatio .planting_management_plan_id, })); delete data['show_wild_crop']; + if (data.animalIds) { + // Format animalIds for the request body + const { related_animal_ids, related_batch_ids } = formatAnimalIdsForReqBody(data.animalIds); + data.related_animal_ids = related_animal_ids; + data.related_batch_ids = related_batch_ids; + delete data['animalIds']; + } }), ); }; diff --git a/packages/webapp/src/containers/Task/sagaUtils.js b/packages/webapp/src/containers/Task/sagaUtils.js index 7cd93758fa..be66723c09 100644 --- a/packages/webapp/src/containers/Task/sagaUtils.js +++ b/packages/webapp/src/containers/Task/sagaUtils.js @@ -43,13 +43,6 @@ export const formatAnimalIdsForReqBody = (ids) => { return { related_animal_ids: animalIds, related_batch_ids: batchIds }; }; -export const formatAnimalTask = (data, endpoint) => { - const { animalIds, managementPlans, ...formattedData } = getPostTaskBody(data, endpoint); - - // Remove managementPlans from the data and format animalIds for the request body - return { ...formattedData, ...formatAnimalIdsForReqBody(animalIds) }; -}; - export const formatMovementTask = (movementTask) => { if (!movementTask || !('purpose' in movementTask)) { return { animal_movement_task: {} }; @@ -64,6 +57,7 @@ export const formatMovementTask = (movementTask) => { }; export const getMovementTaskBody = (data, endpoint) => { - const { movement_task, ...formattedData } = formatAnimalTask(data, endpoint); + const { movement_task, managementPlans, ...formattedData } = getPostTaskBody(data, endpoint); + // Remove managementPlans from the data return { ...formattedData, ...formatMovementTask(movement_task) }; };