Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For riders and dispatchers, show <order number>-<delivery_position> instead of <task.id> #1854

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/components/TaskTitle.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { DatadogLogger } from '../Datadog';

const TaskTitle = ({ task }) => {
const { t } = useTranslation();

// fallback when task is not defined, not sure if it can happen
if (!task) {
Atala marked this conversation as resolved.
Show resolved Hide resolved
DatadogLogger.warning('Task props in TaskTitle is not defined')
return <>{t('TASK')}</>
}

return (
<React.Fragment>
{t('TASK_WITH_ID', { id: task.id })}
{task.metadata &&
task.metadata.order_number &&
' | ' + t('ORDER_NUMBER', { number: task.metadata.order_number })}
{ task.metadata?.order_number ?
<>
{
task.metadata?.delivery_position ?
<>{t('ORDER_NUMBER', { number: task.metadata.order_number })}-{task.metadata.delivery_position}</>
: <>{t('ORDER_NUMBER', { number: task.metadata.order_number })}</>
}
</>
: <>{t('TASK_WITH_ID', { id: task.id })}</>
}
</React.Fragment>
);
};
Expand Down
5 changes: 3 additions & 2 deletions src/navigation/navigators/TaskNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import i18n from '../../i18n';
import { stackNavigatorScreenOptions } from '../styles';

import ProofOfDeliveryTabs from './TaskAttachmentsNavigator';
import TaskTitle from '../../components/TaskTitle';

const CompleteStack = createStackNavigator();

const completeTitle = routeParams => {
if (routeParams) {
if (routeParams.task) {
return `${i18n.t('TASK')} #${routeParams.task.id}`;
return <TaskTitle task={routeParams.task} />
}
if (routeParams.tasks) {
return i18n.t('COMPLETE_TASKS');
Expand Down Expand Up @@ -52,7 +53,7 @@ export default () => (
name="TaskHome"
component={screens.TaskHome}
options={({ route }) => ({
title: `${i18n.t('TASK')} #${route.params?.task.id}`,
title: <TaskTitle task={route.params?.task} />
})}
/>
<RootStack.Screen
Expand Down
4 changes: 3 additions & 1 deletion src/navigation/task/Complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,11 @@ class CompleteTask extends Component {
}

multipleTasksLabel(tasks) {

return tasks.reduce(
(label, task, idx) => {
return `${label}${idx !== 0 ? ',' : ''} #${task.id}`;
const taskIdentifier = task?.metadata?.order_number ? `${task.metadata.order_number}-${task?.metadata?.delivery_position}` : task.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it a second time, maybe use a util function?

Copy link
Member Author

@Atala Atala Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where ? in TaskTitle component ?

return `${label}${idx !== 0 ? ',' : ''} #${taskIdentifier}`;
},
`${this.props.t('COMPLETE_TASKS')}: `,
);
Expand Down
5 changes: 3 additions & 2 deletions src/navigation/task/components/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { StyleSheet, TouchableOpacity, View } from 'react-native';
import FontAwesome from 'react-native-vector-icons/FontAwesome';

import { navigateToTask } from '../../../navigation/utils';
import TaskTitle from '../../../components/TaskTitle';

const NavButton = ({ disabled, left, right, onPress, t, task }) => {
const buttonStyle = [styles.button];
Expand All @@ -31,7 +32,7 @@ const NavButton = ({ disabled, left, right, onPress, t, task }) => {
<TouchableOpacity style={buttonStyle} {...buttonProps}>
{!disabled && task && right && (
<Text style={{ marginRight: 10, fontSize: 14 }}>
{t('TASK_WITH_ID', { id: task.id })}
<TaskTitle task={task} />
</Text>
)}
<Icon
Expand All @@ -41,7 +42,7 @@ const NavButton = ({ disabled, left, right, onPress, t, task }) => {
/>
{!disabled && task && left && (
<Text style={{ marginLeft: 10, fontSize: 14 }}>
{t('TASK_WITH_ID', { id: task.id })}
<TaskTitle task={task} />
</Text>
)}
</TouchableOpacity>
Expand Down
2 changes: 2 additions & 0 deletions src/redux/Courier/taskEntityReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ASSIGN_TASK_SUCCESS,
BULK_ASSIGNMENT_TASKS_SUCCESS,
UNASSIGN_TASK_SUCCESS,
UPDATE_TASK_SUCCESS,
} from '../Dispatch/actions';
import { CENTRIFUGO_MESSAGE } from '../middlewares/CentrifugoMiddleware';
import {
Expand Down Expand Up @@ -150,6 +151,7 @@ export const tasksEntityReducer = (
case START_TASK_SUCCESS:
case MARK_TASK_DONE_SUCCESS:
case MARK_TASK_FAILED_SUCCESS:
case UPDATE_TASK_SUCCESS:
return {
...state,
isFetching: false,
Expand Down
10 changes: 8 additions & 2 deletions src/redux/Dispatch/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export const ASSIGN_TASK_REQUEST = 'ASSIGN_TASK_REQUEST';
export const ASSIGN_TASK_SUCCESS = 'ASSIGN_TASK_SUCCESS';
export const ASSIGN_TASK_FAILURE = 'ASSIGN_TASK_FAILURE';

export const UPDATE_TASK_SUCCESS = 'UPDATE_TASK_SUCCESS';

export const BULK_ASSIGNMENT_TASKS_REQUEST = 'BULK_ASSIGNMENT_TASKS_REQUEST';
export const BULK_ASSIGNMENT_TASKS_SUCCESS = 'BULK_ASSIGNMENT_TASKS_SUCCESS';
export const BULK_ASSIGNMENT_TASKS_FAILURE = 'BULK_ASSIGNMENT_TASKS_FAILURE';
Expand Down Expand Up @@ -98,6 +100,8 @@ export const assignTaskRequest = createAction(ASSIGN_TASK_REQUEST);
export const assignTaskSuccess = createAction(ASSIGN_TASK_SUCCESS);
export const assignTaskFailure = createAction(ASSIGN_TASK_FAILURE);

export const updateTaskSuccess = createAction(UPDATE_TASK_SUCCESS);

export const bulkAssignmentTasksRequest = createAction(
BULK_ASSIGNMENT_TASKS_REQUEST,
);
Expand Down Expand Up @@ -376,8 +380,7 @@ export function unassignTask(task, username) {
export function updateTask(action, task) {
return function (dispatch, getState) {
let date = selectSelectedDate(getState());
console.log(action)
console.log(task)

if (isSameDate(task, date)) {
switch (action) {
case 'task:created':
Expand All @@ -398,6 +401,9 @@ export function updateTask(action, task) {
case 'task:done':
dispatch(markTaskDoneSuccess(task));
break;
case 'task:updated':
dispatch(updateTaskSuccess(task));
break;
case 'task:failed':
dispatch(markTaskFailedSuccess(task));
break;
Expand Down
2 changes: 2 additions & 0 deletions src/redux/logistics/taskEntityReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
LOAD_TASK_LISTS_SUCCESS,
LOAD_UNASSIGNED_TASKS_SUCCESS,
UNASSIGN_TASK_SUCCESS,
UPDATE_TASK_SUCCESS,
} from '../Dispatch/actions';

import {
Expand All @@ -31,6 +32,7 @@ export default (state = initialState, action) => {
let assignedTasks = taskListUtils.assignedTasks(action.payload);
return taskAdapter.upsertMany(state, assignedTasks);
}
case UPDATE_TASK_SUCCESS:
case CREATE_TASK_SUCCESS:
case CANCEL_TASK_SUCCESS:
case ASSIGN_TASK_SUCCESS:
Expand Down
1 change: 1 addition & 0 deletions src/redux/middlewares/CentrifugoMiddleware/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function message(payload) {
case 'task:started':
case 'task:done':
case 'task:failed':
case 'task:updated':
dispatch(updateTask(name, data.task));
break;
default:
Expand Down
Loading