Skip to content

Commit

Permalink
Merge pull request #3572 from LiteFarmOrg/LF-4567-allow-custom-tasks-…
Browse files Browse the repository at this point in the history
…with-animals-to-be-editable-on-complete

LF-4567 Allow custom tasks with animals to be editable on complete
  • Loading branch information
Duncan-Brain authored Dec 6, 2024
2 parents a0e2dc3 + 4c12ca4 commit 5749aed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
39 changes: 20 additions & 19 deletions packages/webapp/src/components/Task/TaskComplete/StepOne.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,26 @@ export default function PureCompleteStepOne({
</div>
) : null}

{taskType &&
taskComponents[taskType]({
setValue,
getValues,
watch,
control,
register,
reset,
getFieldState,
formState: { errors, isValid },
errors,
system,
products,
farm,
task: selectedTask,
disabled: !changesRequired,
isModified: changesRequired,
locations: selectedTask.locations,
})}
{taskType && taskComponents[taskType]
? taskComponents[taskType]({
setValue,
getValues,
watch,
control,
register,
reset,
getFieldState,
formState: { errors, isValid },
errors,
system,
products,
farm,
task: selectedTask,
disabled: !changesRequired,
isModified: changesRequired,
locations: selectedTask.locations,
})
: null}
</Form>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/components/Task/TaskComplete/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function PureTaskComplete({
isFieldWork && persistedFormData?.field_work_task?.field_work_task_type.value === 'OTHER';

// Won't send task type details if need_changes is false
if (persistedFormData?.need_changes && !isOtherFieldWork) {
if (!data.isCustomTaskType && persistedFormData?.need_changes && !isOtherFieldWork) {
data.taskData[task_type_name] = getObjectInnerValues(persistedFormData[task_type_name]);
} else if (isOtherFieldWork) {
data.taskData[task_type_name] = { ...persistedFormData[task_type_name] };
Expand Down
4 changes: 3 additions & 1 deletion packages/webapp/src/containers/Task/TaskReadOnly/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function TaskReadOnly({ history, match, location }) {
const [isTaskTypeCustom, setIsTaskTypeCustom] = useState(false);
const [isHarvest, setIsHarvest] = useState(undefined);
const [wageAtMoment, setWageAtMoment] = useState(undefined);
const [hasAnimals, setHasAnimals] = useState(false);

useEffect(() => {
if (task === undefined) {
Expand All @@ -64,6 +65,7 @@ function TaskReadOnly({ history, match, location }) {
setIsTaskTypeCustom(!!task.taskType.farm_id);
setIsHarvest(isTaskType(task.taskType, 'HARVEST_TASK'));
setWageAtMoment(task.wage_at_moment);
setHasAnimals(task.animals?.length || task.animal_batches?.length);
}
}, [task, history]);

Expand All @@ -74,7 +76,7 @@ function TaskReadOnly({ history, match, location }) {
const onComplete = () => {
if (isHarvest) {
history.push(`/tasks/${task_id}/complete_harvest_quantity`, location?.state);
} else if (isTaskTypeCustom) {
} else if (isTaskTypeCustom && !hasAnimals) {
dispatch(setFormData({ task_id, taskType: task.taskType }));
history.push(`/tasks/${task_id}/complete`, location?.state);
} else {
Expand Down

0 comments on commit 5749aed

Please sign in to comment.