Skip to content

Commit

Permalink
CM-144: fix tasks (#10)
Browse files Browse the repository at this point in the history
* CM-144: add my tasks fe

* CM-144: remove unused variables

* CM-144: fix tasks

* CM-144: fix eslint
  • Loading branch information
jdolkowski authored Jul 25, 2023
1 parent b212763 commit 887a834
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const TASK_FULL_PROJECTION = () => [
'businessStatus',
'dateCreated',
'isDeleted',
'taskGroup{id, code, completionPolicy}',
'taskGroup{id, code, completionPolicy, taskexecutorSet {edges{node{id, user{id}}}}}',
'data',
'currentEntityData',
];
Expand Down
1 change: 1 addition & 0 deletions src/components/TaskApprovementPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function TaskApprovementPanel({
coreConfirm,
clearConfirm,
mutation,
journalize,
confirmed,
}) {
const modulesManager = useModulesManager();
Expand Down
6 changes: 4 additions & 2 deletions src/components/TaskHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { injectIntl } from 'react-intl';
import { withTheme, withStyles } from '@material-ui/core/styles';
import TaskStatusPicker from '../pickers/TaskStatusPicker';
import TaskGroupPicker from '../pickers/TaskGroupPicker';
import { TASK_STATUS, TASK_UPDATE } from '../constants';

const styles = (theme) => ({
tableTitle: theme.table.title,
Expand Down Expand Up @@ -44,7 +45,7 @@ const renderHeadPanelTitle = (classes) => (
class TaskHeadPanel extends FormPanel {
render() {
const {
intl, edited, classes, readOnly,
intl, edited, classes, readOnly, rights,
} = this.props;
const task = { ...edited };
return (
Expand Down Expand Up @@ -84,7 +85,8 @@ class TaskHeadPanel extends FormPanel {
module="tasksManagement"
required
withLabel
readOnly={false}
readOnly={!rights.includes(TASK_UPDATE)
|| [TASK_STATUS.COMPLETED, TASK_STATUS.FAILED].includes(task.status)}
withNull
value={task?.taskGroup}
onChange={(taskGroup) => this.updateAttribute('taskGroup', taskGroup)}
Expand Down
10 changes: 6 additions & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ export const RIGHT_TASKS_MANAGEMENT_SEARCH = 191001;

export const TASKS_MANAGEMENT_ROUTE_GROUPS_GROUP = 'tasksManagement.route.group';

export const TASK_GROUP_SEARCH = 191001;
export const TASK_GROUP_CREATE = 191002;
export const TASK_GROUP_UPDATE = 191003;
export const TASK_GROUP_DELETE = 191004;
export const TASK_GROUP_SEARCH = 190001;
export const TASK_GROUP_CREATE = 190002;
export const TASK_GROUP_UPDATE = 190003;
export const TASK_GROUP_DELETE = 190004;

export const TASK_UPDATE = 191003;

export const RIGHT_TASK_EXECUTIONER_GROUPS = 190001;

Expand Down
19 changes: 18 additions & 1 deletion src/pages/TaskDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
useHistory,
useModulesManager,
useTranslations,
decodeId,
} from '@openimis/fe-core';
import _ from 'lodash';
import TaskHeadPanel from '../components/TaskHeadPanel';
import TaskPreviewPanel from '../components/TaskPreviewPanel';
import TaskApprovementPanel from '../components/TaskApprovementPanel';
import { fetchTask, updateTask } from '../actions';
import { TASK_STATUS as taskStatus } from '../constants';

const useStyles = makeStyles((theme) => ({
page: theme.page,
Expand All @@ -24,6 +26,7 @@ function TaskDetailsPage({
task,
fetchTask,
updateTask,
currentUser,
}) {
const modulesManager = useModulesManager();
const classes = useStyles();
Expand Down Expand Up @@ -62,6 +65,19 @@ function TaskDetailsPage({
}
};

const isCurrentUserInTaskGroup = () => {
const taskExecutors = task?.taskGroup?.taskexecutorSet?.edges.map((edge) => decodeId(edge.node.user.id)) ?? [];
return taskExecutors && taskExecutors.includes(currentUser?.id);
};

const panels = () => {
const panels = [TaskPreviewPanel];
if (task && isCurrentUserInTaskGroup() && task.status === taskStatus.ACCEPTED) {
panels.push(TaskApprovementPanel);
}
return panels;
};

return (
<div className={classes.page}>
<Helmet title={formatMessage('benefitPlanTask.detailsPage.triage.title')} />
Expand All @@ -78,7 +94,7 @@ function TaskDetailsPage({
readOnly
HeadPanel={TaskHeadPanel}
formatMessage={formatMessage}
Panels={[TaskPreviewPanel, TaskApprovementPanel]}
Panels={panels()}
rights={rights}
saveTooltip={formatMessage(
`tasksManagement.saveButton.tooltip.${canSave() ? 'enabled' : 'disabled'}`,
Expand All @@ -95,6 +111,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({

const mapStateToProps = (state, props) => ({
rights: !!state.core && !!state.core.user && !!state.core.user.i_user ? state.core.user.i_user.rights : [],
currentUser: !!state.core && !!state?.core?.user ? state.core.user : null,
taskUuid: props.match.params.task_uuid,
task: state.tasksManagement.task,
});
Expand Down
19 changes: 8 additions & 11 deletions src/pages/TasksManagementPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { PublishedComponent } from '@openimis/fe-core';
import { useSelector } from 'react-redux';
import { injectIntl } from 'react-intl';
import { withTheme, withStyles } from '@material-ui/core/styles';
import { RIGHT_TASKS_MANAGEMENT_SEARCH } from '../constants';

const styles = (theme) => ({
page: theme.page,
Expand All @@ -15,16 +14,14 @@ function TasksManagementPage() {
const rights = useSelector((store) => store.core?.user?.i_user?.rights ?? []);

return (
rights.includes(RIGHT_TASKS_MANAGEMENT_SEARCH) && (
<>
<PublishedComponent
pubRef="socialProtection.BenefitPlanTasksPage"
module="tasks_management"
rights={rights}
/>
{/* REST OF PAGES */}
</>
)
<>
<PublishedComponent
pubRef="socialProtection.BenefitPlanTasksPage"
module="tasks_management"
rights={rights}
/>
{/* REST OF PAGES */}
</>
);
}

Expand Down
7 changes: 6 additions & 1 deletion src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ function reducer(
...task,
id: decodeId(task.id),
currentEntityData: JSON.parse((JSON.parse(task.currentEntityData))),
data: JSON.parse(task.data),
data: JSON.parse(task.data, (key, value) => {
if (['date_valid_to', 'date_valid_from'].includes(key)) {
return `${value} 00:00:00`;
}
return value;
}),
}))?.[0],
errorTask: null,
};
Expand Down
2 changes: 1 addition & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"tasksManagement.benefitPlanTask.source": "Source",
"tasksManagement.benefitPlanTask.type": "Type",
"tasksManagement.benefitPlanTask.entity": "Entity",
"tasksManagement.benefitPlanTask.assignee": "Assignee",
"tasksManagement.benefitPlanTask.assignee": "Task Group",
"tasksManagement.benefitPlanTask.businessStatus": "Business Status",
"tasksManagement.benefitPlanTask.status": "Status",
"tasksManagement.benefitPlanTask.status.RECEIVED": "RECEIVED",
Expand Down

0 comments on commit 887a834

Please sign in to comment.