Skip to content

Commit

Permalink
fix: fix navigation flow after completing a task via the barcode
Browse files Browse the repository at this point in the history
  • Loading branch information
r0xsh committed Nov 8, 2024
1 parent 7c449d0 commit bf939ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
20 changes: 9 additions & 11 deletions src/navigation/courier/barcode/Barcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -202,7 +196,11 @@ function BarcodePage({
setClientAction(client_action);
}}
/>
<ScrollView style={{ paddingHorizontal: 20, marginVertical: 20 }}>
<ScrollView
style={{ paddingHorizontal: 20, marginVertical: 20 }}
// onTouchStart={() => console.log(">>>>>>>>>> enter")}
// onTouchEnd={() => console.log(">>>>>>>>>> leave")}
>
<TextSection
title={t('ADDRESS')}
value={entity?.address?.streetAddress}
Expand Down
16 changes: 11 additions & 5 deletions src/navigation/task/Complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const FailureReasonPicker = ({ task, httpClient, onValueChange }) => {
const failureReasonObj = _.find(data['hydra:member'], r => r.code === selectedFailureReason)
onValueChange(selectedFailureReason, failureReasonObj);
setFailureReason(selectedFailureReason)
}
}

if (isError) {
return <Text color="red.500">Failure reasons are not available</Text>;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/navigation/utils.js
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down

0 comments on commit bf939ea

Please sign in to comment.