Skip to content

Commit

Permalink
Merge branch 'integration' into LF-2230/allow-completion-of-tasks-for…
Browse files Browse the repository at this point in the history
…-psuedo-users
  • Loading branch information
Cali0707 authored May 10, 2022
2 parents 3a10bb8 + 941e07a commit d63c5f7
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 36 deletions.
7 changes: 3 additions & 4 deletions packages/api/src/controllers/taskController.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ const taskController = {
return res.status(400).send('Task has already been completed or abandoned');
}

if (!adminRoles.includes(req.role) && checkTaskStatus.assignee_user_id != req.user.user_id) {
return res
.status(400)
.send('Farm workers are not allowed to reassign a task assigned to another worker');

if (!adminRoles.includes(req.role) && checkTaskStatus.assignee_user_id != req.user.user_id && checkTaskStatus.assignee_user_id !== null){
return res.status(403).send('Farm workers are not allowed to reassign a task assigned to another worker');
}

// Avoid 1) making an empty update, and 2) sending a redundant notification.
Expand Down
2 changes: 1 addition & 1 deletion packages/api/tests/task.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ describe('Task tests', () => {
{ assignee_user_id: user_id },
task_id,
async (err, res) => {
expect(res.status).toBe(400);
expect(res.status).toBe(403);
done();
},
);
Expand Down
4 changes: 2 additions & 2 deletions packages/webapp/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@
"DATE": "Date",
"ESTIMATED_REVENUE": {
"ESTIMATED_ANNUAL_REVENUE": "Estimated annual revenue",
"ESTIMATED_ANNUAL_YIELD": "Estimated annual yield",
"ESTIMATED_ANNUAL_YIELD": "Estimated annual harvest",
"ESTIMATED_PRICE_PER_UNIT": "Estimated price per unit",
"TITLE": "Estimated Revenue"
},
Expand Down Expand Up @@ -913,7 +913,7 @@
"DURATION_TOOLTIP": "These are suggested values. Please adjust for your local conditions.",
"EDITING_PLAN_WILL_NOT_MODIFY": "Editing this plan will not modify tasks assigned to it.",
"ESTIMATED_SEED": "Estimated seed required",
"ESTIMATED_YIELD": "Estimated annual yield",
"ESTIMATED_YIELD": "Estimated annual harvest",
"FIRST_MP_SPOTLIGHT": {
"BODY_PART1": "LiteFarm has generated a few tasks based on your plan. You can add more tasks or assign them on this screen.",
"BODY_PART2": "Your plan will become active once you complete a task.",
Expand Down
4 changes: 2 additions & 2 deletions packages/webapp/public/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@
"DATE": "Fecha",
"ESTIMATED_REVENUE": {
"ESTIMATED_ANNUAL_REVENUE": "Ingresos anuales estimados",
"ESTIMATED_ANNUAL_YIELD": "Rendimiento anual estimado",
"ESTIMATED_ANNUAL_YIELD": "MISSING",
"ESTIMATED_PRICE_PER_UNIT": "Precio estimado por unidad",
"TITLE": "Ingresos estimados"
},
Expand Down Expand Up @@ -916,7 +916,7 @@
"DURATION_TOOLTIP": "Estos son valores sugeridos. Ajústelo a las condiciones locales.",
"EDITING_PLAN_WILL_NOT_MODIFY": "La edición de este plan no modificará las tareas asignadas.",
"ESTIMATED_SEED": "Semilla estimada es obligatoria",
"ESTIMATED_YIELD": "Rendimiento estimado",
"ESTIMATED_YIELD": "MISSING",
"FIRST_MP_SPOTLIGHT": {
"BODY_PART1": "LiteFarm ha generado algunas tareas basadas en su plan. Puede agregar más tareas o asignarlas en esta pantalla.",
"BODY_PART2": "Su plan se activará una vez que complete una tarea.",
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@
"DURATION_TOOLTIP": "Ce sont des valeurs suggérées. Veuillez les ajuster en fonction de vos conditions locales.",
"EDITING_PLAN_WILL_NOT_MODIFY": "MISSING",
"ESTIMATED_SEED": "Semence estimée requise",
"ESTIMATED_YIELD": "Rendement estimé",
"ESTIMATED_YIELD": "MISSING",
"FIRST_MP_SPOTLIGHT": {
"BODY_PART1": "MISSING",
"BODY_PART2": "MISSING",
Expand Down
4 changes: 2 additions & 2 deletions packages/webapp/public/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@
"DATE": "Data",
"ESTIMATED_REVENUE": {
"ESTIMATED_ANNUAL_REVENUE": "Receita anual estimada",
"ESTIMATED_ANNUAL_YIELD": "Rendimento anual estimado",
"ESTIMATED_ANNUAL_YIELD": "MISSING",
"ESTIMATED_PRICE_PER_UNIT": "Preço por unidade estimado",
"TITLE": "Receita Estimada"
},
Expand Down Expand Up @@ -916,7 +916,7 @@
"DURATION_TOOLTIP": "Esses são valores sugeridos. Ajuste de acordo com as condições locais.",
"EDITING_PLAN_WILL_NOT_MODIFY": "Editar este plano não irá modificar as tarefas atribuídas a ele.",
"ESTIMATED_SEED": "Semente estimada necessária",
"ESTIMATED_YIELD": "Rendimento estimado",
"ESTIMATED_YIELD": "MISSING",
"FIRST_MP_SPOTLIGHT": {
"BODY_PART1": "LiteFarm gerou algumas tarefas com base em seu plano. Você pode adicionar mais tarefas ou atribuí-las nesta tela.",
"BODY_PART2": "Seu plano será ativado assim que você concluir uma tarefa.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const PureTaskCard = ({
onClickCompleteOrDueDate?.();
};

const iconStyle = {
const iconStyle = {
iconTextContainer: {
display: 'flex',
flexDirection: 'row',
Expand Down
25 changes: 23 additions & 2 deletions packages/webapp/src/components/Modals/QuickAssignModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function TaskQuickAssignModal({
onAssignTask,
users,
user,
taskCardContents,
}) {
const { t } = useTranslation();
const selfOption = { label: `${user.first_name} ${user.last_name}`, value: user.user_id };
Expand All @@ -35,8 +36,24 @@ export default function TaskQuickAssignModal({
const [selectedWorker, setWorker] = useState(isAssigned ? unAssignedOption : selfOption);
const [assignAll, setAssignAll] = useState(false);

const checkUnassignedTaskForSameDate = () => {
const selectedTask = taskCardContents.find((t) => t.task_id == task_id);
let isUnassignedTaskPresent = false;
for (let task of taskCardContents) {
if (
task.completeOrDueDate === selectedTask.completeOrDueDate &&
!task.assignee &&
task.task_id !== task_id
) {
isUnassignedTaskPresent = true;
break;
}
}
return isUnassignedTaskPresent;
};

const onAssign = () => {
assignAll
assignAll && checkUnassignedTaskForSameDate()
? onAssignTasksOnDate({
task_id: task_id,
date: due_date,
Expand All @@ -49,6 +66,10 @@ export default function TaskQuickAssignModal({
dismissModal();
};

const onCheckedAll = () => {
setAssignAll(!assignAll);
};

const disabled = selectedWorker === null;

return (
Expand Down Expand Up @@ -86,7 +107,7 @@ export default function TaskQuickAssignModal({
<Checkbox
style={{ paddingRight: '24px' }}
label={t('ADD_TASK.ASSIGN_ALL_TO_PERSON')}
onChange={() => setAssignAll(!assignAll)}
onChange={onCheckedAll}
/>
</ModalComponent>
);
Expand Down
37 changes: 19 additions & 18 deletions packages/webapp/src/components/Task/TaskReadOnly/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import ReactSelect from '../../Form/ReactSelect';
import { BiPencil } from 'react-icons/bi';
import TaskQuickAssignModal from '../../Modals/QuickAssignModal';
import { getDateInputFormat } from '../../../util/moment';
import UpdateTaskDateModal from '../../Modals/UpdateTaskDateModal';

export default function PureTaskReadOnly({
onGoBack,
Expand All @@ -63,6 +64,7 @@ export default function PureTaskReadOnly({
getMaxZoom,
onAssignTasksOnDate,
onAssignTask,
onChangeTaskDate,
}) {
const { t } = useTranslation();
const taskType = task.taskType;
Expand All @@ -89,7 +91,7 @@ export default function PureTaskReadOnly({
secondDateLabel: null,
};
}
}, []);
}, [task]);
const locationIds = task.locations.map(({ location_id }) => location_id);
const owner_user_id = task.owner_user_id;
const {
Expand Down Expand Up @@ -126,6 +128,7 @@ export default function PureTaskReadOnly({
!isTaskType(taskType, 'PLANT_TASK') && !isTaskType(taskType, 'TRANSPLANT_TASK');

const [showTaskAssignModal, setShowTaskAssignModal] = useState(false);
const [showDueDateModal, setShowDueDateModal] = useState(false);

const canCompleteTask = (user.user_id === task.assignee_user_id) || (assignedToPseudoUser && user.is_admin);

Expand All @@ -152,7 +155,7 @@ export default function PureTaskReadOnly({
/>
}
/>
<div className={styles.assigneeContainer} style={{ marginBottom: '40px' }}>
<div className={styles.editableContainer}>
<Input
label={t('ADD_TASK.ASSIGNEE')}
disabled={true}
Expand All @@ -163,23 +166,14 @@ export default function PureTaskReadOnly({
)}
</div>

<Input
style={{ marginBottom: '40px' }}
type={'date'}
value={date}
label={dateLabel}
disabled
/>
<div className={styles.editableContainer}>
<Input type={'date'} value={date} label={dateLabel} disabled />
{isCurrent && isAdmin && (
<BiPencil className={styles.pencil} onClick={(_) => setShowDueDateModal(true)} />
)}
</div>

{secondDate && (
<Input
style={{ marginBottom: '40px' }}
type={'date'}
value={secondDate}
label={secondDateLabel}
disabled
/>
)}
{secondDate && <Input type={'date'} value={secondDate} label={secondDateLabel} disabled />}

<Semibold style={{ marginBottom: '12px' }}>{t('TASK.LOCATIONS')}</Semibold>
{isTaskType(taskType, 'TRANSPLANT_TASK') && (
Expand Down Expand Up @@ -391,6 +385,13 @@ export default function PureTaskReadOnly({
dismissModal={() => setShowTaskAssignModal(false)}
/>
)}
{showDueDateModal && (
<UpdateTaskDateModal
due_date={date}
onChangeTaskDate={onChangeTaskDate}
dismissModal={() => setShowDueDateModal(false)}
/>
)}
</Layout>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
cursor: pointer;
}

.assigneeContainer {
.editableContainer {
display: flex;
flex-direction: row;
margin-bottom: 40px;
div {
flex-grow: 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default function ManagementTasks({ history, match }) {
key={task.task_id}
onClick={() => history.push(`/tasks/${task.task_id}/read_only`)}
style={{ marginBottom: '14px' }}
taskCardContents={taskCardContents}
{...task}
/>
))}
Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/src/containers/Task/TaskCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const TaskCard = ({
onClick = null,
selected,
happiness,
taskCardContents,
classes = { card: {} },
...props
}) => {
Expand Down Expand Up @@ -81,6 +82,7 @@ const TaskCard = ({
onAssignTask={onAssignTask}
users={users}
user={user}
taskCardContents={taskCardContents}
dismissModal={() => setShowTaskAssignModal(false)}
/>
)}
Expand Down Expand Up @@ -110,6 +112,7 @@ TaskCard.propTypes = {
onClickCompleteOrDueDate: PropTypes.func,
selected: PropTypes.bool,
task_id: PropTypes.number,
taskCardContents: PropTypes.array,
};

export default TaskCard;
4 changes: 3 additions & 1 deletion packages/webapp/src/containers/Task/TaskReadOnly/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { harvestUseTypesSelector } from '../../harvestUseTypeSlice';
import { useReadonlyTask } from './useReadonlyTask';
import { isTaskType } from '../useIsTaskType';
import { useMaxZoom } from '../../Map/useMaxZoom';
import { assignTask, assignTasksOnDate } from '../saga';
import { assignTask, assignTasksOnDate, changeTaskDate } from '../saga';

function TaskReadOnly({ history, match }) {
const task_id = match.params.task_id;
Expand Down Expand Up @@ -80,6 +80,7 @@ function TaskReadOnly({ history, match }) {
};
const { maxZoomRef, getMaxZoom } = useMaxZoom();

const onChangeTaskDate = (date) => dispatch(changeTaskDate({ task_id, due_date: date }));
const onAssignTasksOnDate = (task) => dispatch(assignTasksOnDate(task));
const onAssignTask = (task) => dispatch(assignTask(task));
return (
Expand All @@ -102,6 +103,7 @@ function TaskReadOnly({ history, match }) {
getMaxZoom={getMaxZoom}
onAssignTasksOnDate={onAssignTasksOnDate}
onAssignTask={onAssignTask}
onChangeTaskDate={onChangeTaskDate}
/>
</>
);
Expand Down
1 change: 1 addition & 0 deletions packages/webapp/src/containers/Task/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default function TaskPage({ history }) {
key={task.task_id}
onClick={() => history.push(`/tasks/${task.task_id}/read_only`)}
style={{ marginBottom: '14px' }}
taskCardContents={taskCardContents}
{...task}
/>
))
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/containers/Task/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function* assignTaskOnDateSaga({ payload: { task_id, date, assignee_user_
let modified_tasks = [];
for (let i = 0; i < result.data.length; i++) {
modified_tasks.push({
id: result.data[i],
id: result.data[i].task_id,
changes: { assignee_user_id },
});
}
Expand Down

0 comments on commit d63c5f7

Please sign in to comment.