From bf939eab8163f4087665d37c1a2352d680551e15 Mon Sep 17 00:00:00 2001 From: Antoine Bagnaud Date: Fri, 8 Nov 2024 14:47:20 +0100 Subject: [PATCH] fix: fix navigation flow after completing a task via the barcode --- src/navigation/courier/barcode/Barcode.js | 20 +++++++++----------- src/navigation/task/Complete.js | 16 +++++++++++----- src/navigation/utils.js | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/navigation/courier/barcode/Barcode.js b/src/navigation/courier/barcode/Barcode.js index 5d0afe9a3..eea334892 100644 --- a/src/navigation/courier/barcode/Barcode.js +++ b/src/navigation/courier/barcode/Barcode.js @@ -17,7 +17,7 @@ import { CommonActions } from '@react-navigation/native'; import NavigationHolder from '../../../NavigationHolder'; import { phonecall } from 'react-native-communications'; import BottomModal from '../../../components/BottomModal'; -import { navigateToCompleteTask } from '../../utils'; +import { navigateToTask } from '../../utils'; import { selectTasks } from '../../../redux/Courier'; async function _fetchBarcode(httpClient, barcode) { @@ -59,13 +59,7 @@ function TextSection({ title, value, variant = 'data' }) { ); } -function BarcodePage({ - t, - httpClient, - navigation, - route, - taskLists, -}) { +function BarcodePage({ t, httpClient, navigation, route, taskLists }) { const [barcode, setBarcode] = useState(null); const [entity, setEntity] = useState(null); const [clientAction, setClientAction] = useState(null); @@ -146,9 +140,9 @@ function BarcodePage({ await askToAssign(); break; case 'ask_to_complete': - navigateToCompleteTask( + navigateToTask( navigation, - route, + null, taskLists.find(t => t['@id'] === `/api/tasks/${entity.id}`), ); break; @@ -202,7 +196,11 @@ function BarcodePage({ setClientAction(client_action); }} /> - + console.log(">>>>>>>>>> enter")} + // onTouchEnd={() => console.log(">>>>>>>>>> leave")} + > { const failureReasonObj = _.find(data['hydra:member'], r => r.code === selectedFailureReason) onValueChange(selectedFailureReason, failureReasonObj); setFailureReason(selectedFailureReason) - } + } if (isError) { return Failure reasons are not available; @@ -256,10 +256,16 @@ const SubmitButton = ({ task, tasks, notes, contactName, failureReason, validate const navigateOnSuccess = () => { // Make sure to use merge = true, so that it doesn't break // when navigating to DispatchTaskList - navigation.navigate({ - name: route.params?.navigateAfter, - merge: true, - }); + + if (route.params?.navigateAfter !== null) { + navigation.navigate({ + name: route.params?.navigateAfter, + merge: true, + }); + } else { + navigation.goBack(); + } + } if (success) { diff --git a/src/navigation/utils.js b/src/navigation/utils.js index 6587db0b5..75b795493 100644 --- a/src/navigation/utils.js +++ b/src/navigation/utils.js @@ -1,7 +1,7 @@ let navigateAfter = null; export const navigateToTask = (navigation, route, task, tasks = []) => { - if (route.name !== 'TaskHome') { + if (route !== null && route.name !== 'TaskHome') { navigateAfter = route.name; }