From ae14dce906f7fbd273340e0cb656e6ca3e3f1906 Mon Sep 17 00:00:00 2001 From: Duncan-Brain Date: Tue, 3 Dec 2024 20:46:05 -0500 Subject: [PATCH 1/8] LF-4541 Add custom locations switch, remove option from TaskAllLocations --- .../containers/Task/TaskLocations/index.jsx | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/webapp/src/containers/Task/TaskLocations/index.jsx b/packages/webapp/src/containers/Task/TaskLocations/index.jsx index ad80080f0e..442a8f6906 100644 --- a/packages/webapp/src/containers/Task/TaskLocations/index.jsx +++ b/packages/webapp/src/containers/Task/TaskLocations/index.jsx @@ -52,7 +52,7 @@ export default function TaskLocationsSwitch({ history, match, location }) { } if (isCustomLocation) { - return ; + return ; } return ; @@ -166,7 +166,40 @@ function TaskAnimalLocations({ history, location }) { ); } -function TaskAllLocations({ history, location, optionalLocation }) { +function TaskCustomLocations({ history, location }) { + const dispatch = useDispatch(); + const locations = useSelector(locationsSelector); + const readOnlyPinCoordinates = useReadOnlyPinCoordinates(); + const activeAndCurrentManagementPlansByLocationIds = + useActiveAndCurrentManagementPlanTilesByLocationIds(locations); + const wildManagementPlanTiles = useCurrentWildManagementPlanTiles(); + + const onContinue = (formData) => { + const hasLocationManagementPlans = formData.locations.some( + ({ location_id }) => activeAndCurrentManagementPlansByLocationIds[location_id]?.length, + ); + const hasWildManagementPlans = formData.show_wild_crop && wildManagementPlanTiles.length; + const hasManagementPlans = hasLocationManagementPlans || hasWildManagementPlans; + if (!readOnlyPinCoordinates?.length || !hasManagementPlans) { + dispatch(setManagementPlansData([])); + return history.push('/add_task/task_animal_selection', location?.state); + } + history.push('/add_task/task_crops', location?.state); + }; + + return ( + + ); +} + +function TaskAllLocations({ history, location }) { const dispatch = useDispatch(); const locations = useSelector(locationsSelector); const persistedFormData = useSelector(hookFormPersistSelector); @@ -200,7 +233,6 @@ function TaskAllLocations({ history, location, optionalLocation }) { onContinue={onContinue} readOnlyPinCoordinates={readOnlyPinCoordinates} location={location} - optionalLocation={optionalLocation} /> ); } From 4afd64a9b590a1289e9417c5a462a768590a7c3b Mon Sep 17 00:00:00 2001 From: Duncan-Brain Date: Tue, 3 Dec 2024 20:48:15 -0500 Subject: [PATCH 2/8] LF-4541 Add logic for choosing onContinue path on inventory --- .../src/containers/Task/TaskAnimalInventory/index.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/webapp/src/containers/Task/TaskAnimalInventory/index.jsx b/packages/webapp/src/containers/Task/TaskAnimalInventory/index.jsx index 97cba122c1..4bda9c9f6c 100644 --- a/packages/webapp/src/containers/Task/TaskAnimalInventory/index.jsx +++ b/packages/webapp/src/containers/Task/TaskAnimalInventory/index.jsx @@ -17,15 +17,21 @@ import PureTaskAnimalInventory from '../../../components/Task/TaskAnimalInventor import { HookFormPersistProvider } from '../../hooks/useHookFormPersist/HookFormPersistProvider'; import { useTheme } from '@mui/styles'; import { useMediaQuery } from '@mui/material'; +import { useIsTaskType } from '../useIsTaskType'; function TaskAnimalInventory({ history, location }) { + const isCustomTask = useIsTaskType('CUSTOM_TASK'); + const onGoBack = () => { history.back(); }; const onContinue = () => { - history.push('/add_task/task_locations', location?.state); + isCustomTask + ? history.push('/add_task/task_details', location?.state) + : history.push('/add_task/task_locations', location?.state); }; + const theme = useTheme(); const isDesktop = useMediaQuery(theme.breakpoints.up('lg')); @@ -36,6 +42,7 @@ function TaskAnimalInventory({ history, location }) { onContinue={onContinue} history={history} isDesktop={isDesktop} + isRequired={!isCustomTask} /> ); From 8d75998144c9a69aec36e0671fe342b6d360c9d2 Mon Sep 17 00:00:00 2001 From: Duncan-Brain Date: Tue, 3 Dec 2024 20:49:39 -0500 Subject: [PATCH 3/8] LF-4541 Add custom task crops selection --- .../src/containers/Task/TaskCrops/index.jsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/webapp/src/containers/Task/TaskCrops/index.jsx b/packages/webapp/src/containers/Task/TaskCrops/index.jsx index 9401eba387..c54c84061e 100644 --- a/packages/webapp/src/containers/Task/TaskCrops/index.jsx +++ b/packages/webapp/src/containers/Task/TaskCrops/index.jsx @@ -11,10 +11,15 @@ import { useIsTaskType } from '../useIsTaskType'; export default function ManagementPlanSelector({ history, match, location }) { const isTransplantTask = useIsTaskType('TRANSPLANT_TASK'); + const isCustomTask = useIsTaskType('CUSTOM_TASK'); if (isTransplantTask) return ( ); + if (isCustomTask) + return ( + + ); return ; } @@ -35,6 +40,18 @@ function TransplantManagementPlansSelector({ history, match, location }) { ); } +function CustomTaskManagementPlansSelector({ history, match, location }) { + const onContinuePath = '/add_task/task_animal_selection'; + return ( + + ); +} + function TaskCrops({ history, match, From 01d2584563effd6dcde501f8e3eed498e7b8316f Mon Sep 17 00:00:00 2001 From: Duncan-Brain Date: Tue, 3 Dec 2024 21:00:18 -0500 Subject: [PATCH 4/8] LF-4541 Continue on to task details if no animals exist on farm --- packages/webapp/src/containers/Task/TaskCrops/index.jsx | 4 +++- .../webapp/src/containers/Task/TaskLocations/index.jsx | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/webapp/src/containers/Task/TaskCrops/index.jsx b/packages/webapp/src/containers/Task/TaskCrops/index.jsx index c54c84061e..cabe6c1ddd 100644 --- a/packages/webapp/src/containers/Task/TaskCrops/index.jsx +++ b/packages/webapp/src/containers/Task/TaskCrops/index.jsx @@ -8,6 +8,7 @@ import { } from './useManagementPlanTilesByLocationIds'; import { cropLocationsSelector } from '../../locationSlice'; import { useIsTaskType } from '../useIsTaskType'; +import useAnimalInventory from '../../Animals/Inventory/useAnimalInventory'; export default function ManagementPlanSelector({ history, match, location }) { const isTransplantTask = useIsTaskType('TRANSPLANT_TASK'); @@ -41,7 +42,8 @@ function TransplantManagementPlansSelector({ history, match, location }) { } function CustomTaskManagementPlansSelector({ history, match, location }) { - const onContinuePath = '/add_task/task_animal_selection'; + const animalsExistOnFarm = useAnimalInventory().inventory.length > 0; + const onContinuePath = animalsExistOnFarm ? '/add_task/task_animal_selection' : undefined; return ( 0; const onContinue = (formData) => { const hasLocationManagementPlans = formData.locations.some( @@ -182,7 +184,10 @@ function TaskCustomLocations({ history, location }) { const hasManagementPlans = hasLocationManagementPlans || hasWildManagementPlans; if (!readOnlyPinCoordinates?.length || !hasManagementPlans) { dispatch(setManagementPlansData([])); - return history.push('/add_task/task_animal_selection', location?.state); + if (animalsExistOnFarm) { + return history.push('/add_task/task_animal_selection', location?.state); + } + return history.push('/add_task/task_details', location?.state); } history.push('/add_task/task_crops', location?.state); }; From aadd59baa2929d1a7f4e07d0e9e2922f3e66e6ee Mon Sep 17 00:00:00 2001 From: Duncan-Brain Date: Wed, 4 Dec 2024 10:55:52 -0500 Subject: [PATCH 5/8] LF-4541 Add animals existence to useInventory and refactor use of it --- .../src/containers/Animals/Inventory/useAnimalInventory.tsx | 4 +++- packages/webapp/src/containers/Task/TaskCrops/index.jsx | 2 +- packages/webapp/src/containers/Task/TaskLocations/index.jsx | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/webapp/src/containers/Animals/Inventory/useAnimalInventory.tsx b/packages/webapp/src/containers/Animals/Inventory/useAnimalInventory.tsx index b2f8275929..5ce12bf298 100644 --- a/packages/webapp/src/containers/Animals/Inventory/useAnimalInventory.tsx +++ b/packages/webapp/src/containers/Animals/Inventory/useAnimalInventory.tsx @@ -304,7 +304,9 @@ const useAnimalInventory = () => { defaultAnimalTypes, ]); - return { inventory, isLoading }; + const animalsExistOnFarm = inventory.length > 0; + + return { inventory, animalsExistOnFarm, isLoading }; }; export default useAnimalInventory; diff --git a/packages/webapp/src/containers/Task/TaskCrops/index.jsx b/packages/webapp/src/containers/Task/TaskCrops/index.jsx index cabe6c1ddd..6126109677 100644 --- a/packages/webapp/src/containers/Task/TaskCrops/index.jsx +++ b/packages/webapp/src/containers/Task/TaskCrops/index.jsx @@ -42,7 +42,7 @@ function TransplantManagementPlansSelector({ history, match, location }) { } function CustomTaskManagementPlansSelector({ history, match, location }) { - const animalsExistOnFarm = useAnimalInventory().inventory.length > 0; + const { animalsExistOnFarm } = useAnimalInventory(); const onContinuePath = animalsExistOnFarm ? '/add_task/task_animal_selection' : undefined; return ( 0; + const { animalsExistOnFarm } = useAnimalInventory(); const onContinue = (formData) => { const hasLocationManagementPlans = formData.locations.some( From 54a53abb3c2b7b1a8206d98cea6f52c7e3753ee2 Mon Sep 17 00:00:00 2001 From: Duncan-Brain Date: Wed, 4 Dec 2024 18:37:34 -0500 Subject: [PATCH 6/8] LF-4541 Add correct progress for custom task only --- .../Task/PureTaskAssignment/index.jsx | 3 ++- .../components/Task/PureTaskCrops/index.jsx | 7 +++--- .../components/Task/PureTaskDetails/index.jsx | 6 +++-- .../Task/TaskAnimalInventory/index.jsx | 2 +- .../src/components/Task/TaskDate/index.jsx | 3 +-- .../components/Task/TaskLocations/index.jsx | 2 +- .../Task/TaskAnimalInventory/index.jsx | 3 +++ .../containers/Task/TaskAssignment/index.jsx | 6 ++++- .../src/containers/Task/TaskCrops/index.jsx | 6 +++++ .../src/containers/Task/TaskDate/index.jsx | 6 ++++- .../containers/Task/TaskLocations/index.jsx | 6 +++++ .../webapp/src/containers/Task/constants.js | 13 +++++++++++ packages/webapp/src/containers/Task/util.js | 22 +++++++++++++++++++ 13 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 packages/webapp/src/containers/Task/util.js diff --git a/packages/webapp/src/components/Task/PureTaskAssignment/index.jsx b/packages/webapp/src/components/Task/PureTaskAssignment/index.jsx index df6b7d906e..aaf4c46dcc 100644 --- a/packages/webapp/src/components/Task/PureTaskAssignment/index.jsx +++ b/packages/webapp/src/components/Task/PureTaskAssignment/index.jsx @@ -31,6 +31,7 @@ const PureTaskAssignment = ({ handleSubmit, getValues, additionalContent, + progress = 86, }) => { const { t } = useTranslation(); const wageOverride = watch(WAGE_OVERRIDE); @@ -109,7 +110,7 @@ const PureTaskAssignment = ({ onCancel={historyCancel} title={t('ADD_TASK.ADD_A_TASK')} cancelModalTitle={t('ADD_TASK.CANCEL')} - value={86} + value={progress} /> { @@ -111,8 +112,8 @@ const PureTaskCrops = ({ .map((management_plan) => management_plan.management_plan_id) .filter((management_plan_id) => managementPlanIds.includes(management_plan_id)) : getValues(MANAGEMENT_PLANS)?.length - ? [getValues(MANAGEMENT_PLANS)?.[0]?.management_plan_id] - : [], + ? [getValues(MANAGEMENT_PLANS)?.[0]?.management_plan_id] + : [], ); const onSelectManagementPlan = (management_plan_id) => { @@ -249,7 +250,7 @@ const PureTaskCrops = ({ onCancel={historyCancel} title={t('ADD_TASK.ADD_A_TASK')} cancelModalTitle={t('ADD_TASK.CANCEL')} - value={57} + value={progress} />
{t('ADD_TASK.AFFECT_PLANS')}
diff --git a/packages/webapp/src/components/Task/PureTaskDetails/index.jsx b/packages/webapp/src/components/Task/PureTaskDetails/index.jsx index 657328925f..867882ad62 100644 --- a/packages/webapp/src/components/Task/PureTaskDetails/index.jsx +++ b/packages/webapp/src/components/Task/PureTaskDetails/index.jsx @@ -15,6 +15,7 @@ import PureIrrigationTask from '../PureIrrigationTask'; import PureSoilAmendmentTask from '../SoilAmendmentTask'; import PureMovementTask from '../MovementTask'; import { defaultValues as soilAmendmentProductDefaultValues } from '../AddSoilAmendmentProducts'; +import { getProgress } from '../../../containers/Task/util'; export default function PureTaskDetails({ handleGoBack, @@ -32,10 +33,11 @@ export default function PureTaskDetails({ }) { const { t } = useTranslation(); const taskType = selectedTaskType.task_translation_key; - const taskName = selectedTaskType.task_name; const isCustomType = !!selectedTaskType.farm_id; const isHarvest = isTaskType(selectedTaskType, 'HARVEST_TASK'); const isIrrigationTask = isTaskType(selectedTaskType, 'IRRIGATION_TASK'); + const isCustomTask = isTaskType(selectedTaskType, 'CUSTOM_TASK'); + const progress = isCustomTask ? getProgress('CUSTOM_TASK', 'task_details') : isHarvest ? 67 : 71; const defaults = { CLEANING_TASK: { cleaning_task: { agent_used: false } }, @@ -134,7 +136,7 @@ export default function PureTaskDetails({ onCancel={historyCancel} title={t('ADD_TASK.ADD_A_TASK')} cancelModalTitle={t('ADD_TASK.CANCEL')} - value={isHarvest ? 67 : 71} + value={progress} />
{ const locationIdsSet = new Set(locations.map(({ location_id }) => location_id)); diff --git a/packages/webapp/src/containers/Task/TaskAnimalInventory/index.jsx b/packages/webapp/src/containers/Task/TaskAnimalInventory/index.jsx index 4bda9c9f6c..e4a675c393 100644 --- a/packages/webapp/src/containers/Task/TaskAnimalInventory/index.jsx +++ b/packages/webapp/src/containers/Task/TaskAnimalInventory/index.jsx @@ -18,9 +18,11 @@ import { HookFormPersistProvider } from '../../hooks/useHookFormPersist/HookForm import { useTheme } from '@mui/styles'; import { useMediaQuery } from '@mui/material'; import { useIsTaskType } from '../useIsTaskType'; +import { getProgress } from '../util'; function TaskAnimalInventory({ history, location }) { const isCustomTask = useIsTaskType('CUSTOM_TASK'); + const progress = isCustomTask ? getProgress('CUSTOM_TASK', 'task_animal_selection') : undefined; const onGoBack = () => { history.back(); @@ -43,6 +45,7 @@ function TaskAnimalInventory({ history, location }) { history={history} isDesktop={isDesktop} isRequired={!isCustomTask} + progress={progress} /> ); diff --git a/packages/webapp/src/containers/Task/TaskAssignment/index.jsx b/packages/webapp/src/containers/Task/TaskAssignment/index.jsx index a3cd81c759..068583e250 100644 --- a/packages/webapp/src/containers/Task/TaskAssignment/index.jsx +++ b/packages/webapp/src/containers/Task/TaskAssignment/index.jsx @@ -19,6 +19,8 @@ import { ASSIGNEE, ALREADY_COMPLETED, } from '../../../components/Task/AssignTask/constants'; +import { getProgress } from '../util'; +import { useIsTaskType } from '../useIsTaskType'; export default function TaskManagement({ history, match, location }) { const userFarms = useSelector(userFarmEntitiesSelector); @@ -31,7 +33,8 @@ export default function TaskManagement({ history, match, location }) { const persistedFormData = useSelector(hookFormPersistSelector); const [isFarmWorker] = useState(userFarm.role_id === 3); const worker = users[userFarm.user_id]; - + const isCustomTask = useIsTaskType('CUSTOM_TASK'); + const progress = isCustomTask ? getProgress('CUSTOM_TASK', 'task_assignment') : undefined; const [showCannotCreateModal, setShowCannotCreateModal] = useState(false); const defaultAssignee = useMemo(() => { @@ -184,6 +187,7 @@ export default function TaskManagement({ history, match, location }) { override={override} {...taskAssignForm} additionalContent={taskCompleted} + progress={progress} /> {showCannotCreateModal && ( diff --git a/packages/webapp/src/containers/Task/TaskCrops/index.jsx b/packages/webapp/src/containers/Task/TaskCrops/index.jsx index 6126109677..ccef35d2a3 100644 --- a/packages/webapp/src/containers/Task/TaskCrops/index.jsx +++ b/packages/webapp/src/containers/Task/TaskCrops/index.jsx @@ -9,6 +9,7 @@ import { import { cropLocationsSelector } from '../../locationSlice'; import { useIsTaskType } from '../useIsTaskType'; import useAnimalInventory from '../../Animals/Inventory/useAnimalInventory'; +import { getProgress } from '../util'; export default function ManagementPlanSelector({ history, match, location }) { const isTransplantTask = useIsTaskType('TRANSPLANT_TASK'); @@ -44,12 +45,15 @@ function TransplantManagementPlansSelector({ history, match, location }) { function CustomTaskManagementPlansSelector({ history, match, location }) { const { animalsExistOnFarm } = useAnimalInventory(); const onContinuePath = animalsExistOnFarm ? '/add_task/task_animal_selection' : undefined; + const progress = getProgress('CUSTOM_TASK', 'task_crops'); + return ( ); } @@ -61,6 +65,7 @@ function TaskCrops({ onContinuePath = '/add_task/task_details', locations, location, + progress, }) { const persistedPaths = [goBackPath, onContinuePath]; const handleGoBack = () => { @@ -95,6 +100,7 @@ function TaskCrops({ isRequired={isRequired} wildManagementPlanTiles={showWildCrops ? wildManagementPlanTiles : undefined} defaultManagementPlanId={location?.state?.management_plan_id ?? null} + progress={progress} history={history} location={location} /> diff --git a/packages/webapp/src/containers/Task/TaskDate/index.jsx b/packages/webapp/src/containers/Task/TaskDate/index.jsx index c570dd83a5..416b86bd08 100644 --- a/packages/webapp/src/containers/Task/TaskDate/index.jsx +++ b/packages/webapp/src/containers/Task/TaskDate/index.jsx @@ -4,6 +4,7 @@ import { HookFormPersistProvider } from '../../hooks/useHookFormPersist/HookForm import { useIsTaskType } from '../useIsTaskType'; import { useSelector } from 'react-redux'; import { tasksByManagementPlanIdSelector } from '../../taskSlice'; +import { getProgress } from '../util'; function TaskDate({ history, match, location }) { const onGoBack = () => { @@ -11,6 +12,7 @@ function TaskDate({ history, match, location }) { }; const isTransplantTask = useIsTaskType('TRANSPLANT_TASK'); const isMovementTask = useIsTaskType('MOVEMENT_TASK'); + const isCustomTask = useIsTaskType('CUSTOM_TASK'); const tasks = location.state.management_plan_id ? useSelector(tasksByManagementPlanIdSelector(location.state.management_plan_id)) @@ -73,9 +75,11 @@ function TaskDate({ history, match, location }) { history.push(getNextStepPath(), location?.state); }; + const progress = isCustomTask ? getProgress('CUSTOM_TASK', 'task_date') : undefined; + return ( - + ); } diff --git a/packages/webapp/src/containers/Task/TaskLocations/index.jsx b/packages/webapp/src/containers/Task/TaskLocations/index.jsx index d9c2067388..98504b7a44 100644 --- a/packages/webapp/src/containers/Task/TaskLocations/index.jsx +++ b/packages/webapp/src/containers/Task/TaskLocations/index.jsx @@ -23,6 +23,7 @@ import { useReadOnlyPinCoordinates } from '../useReadOnlyPinCoordinates'; import { useMaxZoom } from '../../Map/useMaxZoom'; import { managementPlanSelector } from '../../managementPlanSlice'; import useAnimalInventory from '../../Animals/Inventory/useAnimalInventory'; +import { getProgress } from '../util'; export default function TaskLocationsSwitch({ history, match, location }) { const isHarvestLocation = useIsTaskType('HARVEST_TASK'); @@ -192,6 +193,8 @@ function TaskCustomLocations({ history, location }) { history.push('/add_task/task_crops', location?.state); }; + const progress = getProgress('CUSTOM_TASK', 'task_locations'); + return ( ); } @@ -252,6 +256,7 @@ function TaskLocations({ location, isAnimalTask = false, optionalLocation, + progress, }) { const { grid_points } = useSelector(userFarmSelector); const { maxZoomRef, getMaxZoom, maxZoom } = useMaxZoom(); @@ -279,6 +284,7 @@ function TaskLocations({ targetsWildCrop={managementPlan?.crop_management_plan?.is_wild ?? false} isAnimalTask={isAnimalTask} optionalLocation={optionalLocation} + progress={progress} /> ); diff --git a/packages/webapp/src/containers/Task/constants.js b/packages/webapp/src/containers/Task/constants.js index 23104a7be4..dd077190d2 100644 --- a/packages/webapp/src/containers/Task/constants.js +++ b/packages/webapp/src/containers/Task/constants.js @@ -31,3 +31,16 @@ export const TASK_TYPE_PRODUCT_MAP = { }; export const ANIMAL_TASKS = ['MOVEMENT_TASK']; + +export const TASK_STEPS = { + CUSTOM_TASK: { + task_type_selection: 1, + task_date: 2, + task_locations: 3, + task_crops: 4, + task_animal_selection: 5, + task_details: 6, + task_assignment: 7, + end: 8, + }, +}; diff --git a/packages/webapp/src/containers/Task/util.js b/packages/webapp/src/containers/Task/util.js new file mode 100644 index 0000000000..d4d4e3b227 --- /dev/null +++ b/packages/webapp/src/containers/Task/util.js @@ -0,0 +1,22 @@ +/* + * Copyright 2024 LiteFarm.org + * This file is part of LiteFarm. + * + * LiteFarm is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LiteFarm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details, see . + */ + +import { TASK_STEPS } from './constants'; + +export const getProgress = (taskType, stepPath) => { + return TASK_STEPS[taskType] + ? Math.round((100 * TASK_STEPS[taskType][stepPath]) / Object.keys(TASK_STEPS[taskType]).length) + : undefined; +}; From 9a53e30ffb1b418c4dfca8faeb91d58ea23c08c8 Mon Sep 17 00:00:00 2001 From: Duncan-Brain Date: Thu, 5 Dec 2024 13:11:38 -0500 Subject: [PATCH 7/8] LF-4541 Update task animal inventory string --- packages/webapp/public/locales/de/translation.json | 2 +- packages/webapp/public/locales/en/translation.json | 2 +- packages/webapp/public/locales/es/translation.json | 2 +- packages/webapp/public/locales/fr/translation.json | 2 +- packages/webapp/public/locales/hi/translation.json | 2 +- packages/webapp/public/locales/pa/translation.json | 2 +- packages/webapp/public/locales/pt/translation.json | 2 +- .../webapp/src/components/Task/TaskAnimalInventory/index.jsx | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/webapp/public/locales/de/translation.json b/packages/webapp/public/locales/de/translation.json index 92ae3fbbd3..da0b9282a1 100644 --- a/packages/webapp/public/locales/de/translation.json +++ b/packages/webapp/public/locales/de/translation.json @@ -1875,7 +1875,7 @@ "QUANTITY_CANNOT_EXCEED": "Die genutzte Erntemenge darf nicht größer sein als die zu verteilende Menge", "RATE_THIS_TASK": "Bewerten Sie diese Aufgabe", "REMOVE_HARVEST_USE": "Entfernen", - "SELECT_ANIMALS_TO_MOVE": "MISSING", + "SELECT_ANIMALS": "MISSING", "SELECT_DATE": "Wählen Sie das Datum der Aufgabe", "SELECT_TASK_LOCATIONS": "Wählen Sie die Aufgabenstellung(en)", "SELECT_WILD_CROP": "Diese Aufgabe zielt auf eine Wildpflanze ab", diff --git a/packages/webapp/public/locales/en/translation.json b/packages/webapp/public/locales/en/translation.json index 60c4a84ea8..4ea6f5a81c 100644 --- a/packages/webapp/public/locales/en/translation.json +++ b/packages/webapp/public/locales/en/translation.json @@ -2020,7 +2020,7 @@ "QUANTITY_CANNOT_EXCEED": "Harvest quantity used cannot exceed amount to allocate", "RATE_THIS_TASK": "Rate this task", "REMOVE_HARVEST_USE": "Remove", - "SELECT_ANIMALS_TO_MOVE": "Select animals to move", + "SELECT_ANIMALS": "Select animals", "SELECT_DATE": "Select the task date", "SELECT_TASK_LOCATIONS": "Select the task location(s)", "SELECT_WILD_CROP": "This task targets a wild crop", diff --git a/packages/webapp/public/locales/es/translation.json b/packages/webapp/public/locales/es/translation.json index 7e639ff4c4..13ad742725 100644 --- a/packages/webapp/public/locales/es/translation.json +++ b/packages/webapp/public/locales/es/translation.json @@ -2022,7 +2022,7 @@ "QUANTITY_CANNOT_EXCEED": "La cantidad de cosecha utilizada no puede exceder la cantidad a asignar", "RATE_THIS_TASK": "Califica esta tarea", "REMOVE_HARVEST_USE": "Quitar", - "SELECT_ANIMALS_TO_MOVE": "MISSING", + "SELECT_ANIMALS": "MISSING", "SELECT_DATE": "Seleccione la fecha de la tarea", "SELECT_TASK_LOCATIONS": "Seleccione la(s) ubicación(es) de la tarea", "SELECT_WILD_CROP": "Esta tarea se dirige a un cultivo silvestre", diff --git a/packages/webapp/public/locales/fr/translation.json b/packages/webapp/public/locales/fr/translation.json index d243b7ee5a..144167d249 100644 --- a/packages/webapp/public/locales/fr/translation.json +++ b/packages/webapp/public/locales/fr/translation.json @@ -2021,7 +2021,7 @@ "QUANTITY_CANNOT_EXCEED": "La quantité de récolte utilisée ne peut pas dépasser la quantité à allouer", "RATE_THIS_TASK": "Évaluez cette tâche", "REMOVE_HARVEST_USE": "Supprimer", - "SELECT_ANIMALS_TO_MOVE": "MISSING", + "SELECT_ANIMALS": "MISSING", "SELECT_DATE": "Sélectionnez la date de la tâche", "SELECT_TASK_LOCATIONS": "Sélectionnez le(s) emplacement(s) de la tâche", "SELECT_WILD_CROP": "Cette tâche cible une culture sauvage", diff --git a/packages/webapp/public/locales/hi/translation.json b/packages/webapp/public/locales/hi/translation.json index 50cb39c264..314f7cc5c3 100644 --- a/packages/webapp/public/locales/hi/translation.json +++ b/packages/webapp/public/locales/hi/translation.json @@ -1872,7 +1872,7 @@ "QUANTITY_CANNOT_EXCEED": "फसल उपयोग की मात्रा आवंटित राशि से अधिक नहीं हो सकती", "RATE_THIS_TASK": "इस कार्य को रेट करें", "REMOVE_HARVEST_USE": "हटाएं", - "SELECT_ANIMALS_TO_MOVE": "MISSING", + "SELECT_ANIMALS": "MISSING", "SELECT_DATE": "कार्य तिथि चुनें", "SELECT_TASK_LOCATIONS": "कार्य स्थान(ओं) का चयन करें", "SELECT_WILD_CROP": "यह कार्य एक जंगली फसल को लक्षित करता है", diff --git a/packages/webapp/public/locales/pa/translation.json b/packages/webapp/public/locales/pa/translation.json index 64a1566e65..876baeb55f 100644 --- a/packages/webapp/public/locales/pa/translation.json +++ b/packages/webapp/public/locales/pa/translation.json @@ -1872,7 +1872,7 @@ "QUANTITY_CANNOT_EXCEED": "ਵਰਤੇ ਗਏ ਵਾਢੀ ਦੀ ਮਾਤਰਾ ਨਿਰਧਾਰਤ ਕੀਤੀ ਰਕਮ ਤੋਂ ਵੱਧ ਨਹੀਂ ਹੋ ਸਕਦੀ", "RATE_THIS_TASK": "ਇਸ ਕੰਮ ਨੂੰ ਦਰਜਾ ਦਿਓ", "REMOVE_HARVEST_USE": "ਹਟਾਓ", - "SELECT_ANIMALS_TO_MOVE": "MISSING", + "SELECT_ANIMALS": "MISSING", "SELECT_DATE": "ਕੰਮ ਦੀ ਮਿਤੀ ਚੁਣੋ", "SELECT_TASK_LOCATIONS": "ਕੰਮ ਦੇ ਟਿਕਾਣੇ ਚੁਣੋ", "SELECT_WILD_CROP": "ਇਹ ਕੰਮ ਜੰਗਲੀ ਫਸਲ ਨੂੰ ਨਿਸ਼ਾਨਾ ਬਣਾਉਂਦਾ ਹੈ", diff --git a/packages/webapp/public/locales/pt/translation.json b/packages/webapp/public/locales/pt/translation.json index ec5be675d6..4cfda823a8 100644 --- a/packages/webapp/public/locales/pt/translation.json +++ b/packages/webapp/public/locales/pt/translation.json @@ -2021,7 +2021,7 @@ "QUANTITY_CANNOT_EXCEED": "A quantidade de colheita usada não pode exceder a quantidade a ser alocada", "RATE_THIS_TASK": "Avalie esta tarefa", "REMOVE_HARVEST_USE": "Remover", - "SELECT_ANIMALS_TO_MOVE": "MISSING", + "SELECT_ANIMALS": "MISSING", "SELECT_DATE": "Selecionar a data da tarefa", "SELECT_TASK_LOCATIONS": "Selecionar o(s) local(is) da tarefa", "SELECT_WILD_CROP": "Esta tarefa é para um cultivo silvestre", diff --git a/packages/webapp/src/components/Task/TaskAnimalInventory/index.jsx b/packages/webapp/src/components/Task/TaskAnimalInventory/index.jsx index 2d389aa62d..44380a0e03 100644 --- a/packages/webapp/src/components/Task/TaskAnimalInventory/index.jsx +++ b/packages/webapp/src/components/Task/TaskAnimalInventory/index.jsx @@ -100,7 +100,7 @@ export default function PureTaskAnimalInventory({ maxHeight: '24px', }} > - {t('TASK.SELECT_ANIMALS_TO_MOVE')} + {t('TASK.SELECT_ANIMALS')}
Date: Thu, 5 Dec 2024 18:56:37 -0500 Subject: [PATCH 8/8] LF-4541 Add new animals exist hook --- .../Animals/Inventory/useAnimalInventory.tsx | 4 +-- .../Animals/Inventory/useAnimalsExist.tsx | 29 +++++++++++++++++++ .../src/containers/Task/TaskCrops/index.jsx | 4 +-- .../containers/Task/TaskLocations/index.jsx | 4 +-- 4 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 packages/webapp/src/containers/Animals/Inventory/useAnimalsExist.tsx diff --git a/packages/webapp/src/containers/Animals/Inventory/useAnimalInventory.tsx b/packages/webapp/src/containers/Animals/Inventory/useAnimalInventory.tsx index 5ce12bf298..b2f8275929 100644 --- a/packages/webapp/src/containers/Animals/Inventory/useAnimalInventory.tsx +++ b/packages/webapp/src/containers/Animals/Inventory/useAnimalInventory.tsx @@ -304,9 +304,7 @@ const useAnimalInventory = () => { defaultAnimalTypes, ]); - const animalsExistOnFarm = inventory.length > 0; - - return { inventory, animalsExistOnFarm, isLoading }; + return { inventory, isLoading }; }; export default useAnimalInventory; diff --git a/packages/webapp/src/containers/Animals/Inventory/useAnimalsExist.tsx b/packages/webapp/src/containers/Animals/Inventory/useAnimalsExist.tsx new file mode 100644 index 0000000000..91856f97d0 --- /dev/null +++ b/packages/webapp/src/containers/Animals/Inventory/useAnimalsExist.tsx @@ -0,0 +1,29 @@ +/* + * Copyright 2024 LiteFarm.org + * This file is part of LiteFarm. + * + * LiteFarm is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LiteFarm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details, see . + */ +import { useGetAnimalsQuery, useGetAnimalBatchesQuery } from '../../../store/api/apiSlice'; +import useQueries from '../../../hooks/api/useQueries'; + +const useAnimalsExist = () => { + const { data, isLoading } = useQueries([ + { label: 'animals', hook: useGetAnimalsQuery }, + { label: 'animalBatches', hook: useGetAnimalBatchesQuery }, + ]); + + const animalsExistOnFarm = !isLoading && (data.animals.length || data.animalBatches.length); + + return { animalsExistOnFarm }; +}; + +export default useAnimalsExist; diff --git a/packages/webapp/src/containers/Task/TaskCrops/index.jsx b/packages/webapp/src/containers/Task/TaskCrops/index.jsx index ccef35d2a3..6ef979a647 100644 --- a/packages/webapp/src/containers/Task/TaskCrops/index.jsx +++ b/packages/webapp/src/containers/Task/TaskCrops/index.jsx @@ -8,8 +8,8 @@ import { } from './useManagementPlanTilesByLocationIds'; import { cropLocationsSelector } from '../../locationSlice'; import { useIsTaskType } from '../useIsTaskType'; -import useAnimalInventory from '../../Animals/Inventory/useAnimalInventory'; import { getProgress } from '../util'; +import useAnimalsExist from '../../Animals/Inventory/useAnimalsExist'; export default function ManagementPlanSelector({ history, match, location }) { const isTransplantTask = useIsTaskType('TRANSPLANT_TASK'); @@ -43,7 +43,7 @@ function TransplantManagementPlansSelector({ history, match, location }) { } function CustomTaskManagementPlansSelector({ history, match, location }) { - const { animalsExistOnFarm } = useAnimalInventory(); + const { animalsExistOnFarm } = useAnimalsExist(); const onContinuePath = animalsExistOnFarm ? '/add_task/task_animal_selection' : undefined; const progress = getProgress('CUSTOM_TASK', 'task_crops'); diff --git a/packages/webapp/src/containers/Task/TaskLocations/index.jsx b/packages/webapp/src/containers/Task/TaskLocations/index.jsx index 98504b7a44..1032287bca 100644 --- a/packages/webapp/src/containers/Task/TaskLocations/index.jsx +++ b/packages/webapp/src/containers/Task/TaskLocations/index.jsx @@ -22,8 +22,8 @@ import { useTranslation } from 'react-i18next'; import { useReadOnlyPinCoordinates } from '../useReadOnlyPinCoordinates'; import { useMaxZoom } from '../../Map/useMaxZoom'; import { managementPlanSelector } from '../../managementPlanSlice'; -import useAnimalInventory from '../../Animals/Inventory/useAnimalInventory'; import { getProgress } from '../util'; +import useAnimalsExist from '../../Animals/Inventory/useAnimalsExist'; export default function TaskLocationsSwitch({ history, match, location }) { const isHarvestLocation = useIsTaskType('HARVEST_TASK'); @@ -175,7 +175,7 @@ function TaskCustomLocations({ history, location }) { const activeAndCurrentManagementPlansByLocationIds = useActiveAndCurrentManagementPlanTilesByLocationIds(locations); const wildManagementPlanTiles = useCurrentWildManagementPlanTiles(); - const { animalsExistOnFarm } = useAnimalInventory(); + const { animalsExistOnFarm } = useAnimalsExist(); const onContinue = (formData) => { const hasLocationManagementPlans = formData.locations.some(