Skip to content

Commit

Permalink
feat: add ask_to_complete behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
r0xsh committed Nov 8, 2024
1 parent a14f4a7 commit 7c449d0
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/navigation/courier/barcode/Barcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import BarcodeCameraView from '../../../components/BarcodeCameraView';

import { CommonActions } from '@react-navigation/native';
import NavigationHolder from '../../../NavigationHolder';
import { assignTask } from '../../../redux/Dispatch/actions';
import { unassignTask } from '../../../redux/Dispatch/actions';
import { phonecall } from 'react-native-communications';
import BottomModal from '../../../components/BottomModal';
import { navigateToCompleteTask } from '../../utils';
import { selectTasks } from '../../../redux/Courier';

async function _fetchBarcode(httpClient, barcode) {
if (barcode) {
Expand Down Expand Up @@ -59,7 +59,13 @@ function TextSection({ title, value, variant = 'data' }) {
);
}

function BarcodePage({ t, httpClient, user, assignTask, unassignTask }) {
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 @@ -131,14 +137,21 @@ function BarcodePage({ t, httpClient, user, assignTask, unassignTask }) {

useEffect(() => {
async function checkClientAction() {
if (!clientAction) return;
if (!clientAction || !entity) return;
switch (clientAction) {
case 'ask_to_unassign':
await askToUnassign();
break;
case 'ask_to_assign':
await askToAssign();
break;
case 'ask_to_complete':
navigateToCompleteTask(
navigation,
route,
taskLists.find(t => t['@id'] === `/api/tasks/${entity.id}`),
);
break;
}
setClientAction(null);
}
Expand Down Expand Up @@ -177,7 +190,7 @@ function BarcodePage({ t, httpClient, user, assignTask, unassignTask }) {
</BottomModal>
<View style={{ flex: 1 }}>
<BarcodeCameraView
disabled={disableScan || showNoteModal}
disabled={disableScan || showNoteModal || clientAction !== null}
onScanned={async code => {
if (clientAction) return;
const { entity, client_action } = await _fetchBarcode(
Expand Down Expand Up @@ -266,6 +279,7 @@ function mapStateToProps(state) {
return {
httpClient: state.app.httpClient,
user: state.app.user,
taskLists: selectTasks(state),
};
}

Expand Down

0 comments on commit 7c449d0

Please sign in to comment.