Skip to content

Commit

Permalink
121706
Browse files Browse the repository at this point in the history
  • Loading branch information
remyvdwereld committed Jul 22, 2024
1 parent cfc52fb commit 054de73
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
14 changes: 13 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@
<base href="/">
<title>%REACT_APP_PAGE_TITLE%</title>
<script type="module" src="src/index"></script>
<script src='/config/env.js'></script>
<script>
// Check if the hostname contains "localhost" or is an IP address commonly used for localhost

if (window.location.host === 'localhost:2999') {
// Do not load the script
console.log('Skipping env.js on localhost.');
} else {
// Load the script
var script = document.createElement('script');
script.src = '/config/env.js';
document.head.appendChild(script);
}
</script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/case/Workflow/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TaskButton from "app/components/case/tasks/TaskButton/TaskButton"
import taskActionMap from "./utils/taskActionMap"
import LockIcon from "./components/LockIcon"
import TableAction from "app/components/shared/TableAction/TableAction"
import SelectTask from "./components/SelectTask"
import SelectTaskWorkflow from "./components/SelectTaskWorkflow"

// This width value (113px) is the width of a date + edit icon including the spacing between them
const Span = styled.span`
Expand All @@ -31,7 +31,7 @@ export default (execPost: (payload?: any) => Promise<unknown>) => (
}, {
header: "Opgepakt door",
dataIndex: "owner",
render: (owner: any, task: any) => <SelectTask task={task} />
render: (owner: any, task: any) => <SelectTaskWorkflow task={task} />
}, {
header: "Slotdatum",
dataIndex: "due_date",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ const StyledCheckbox = styled(Checkbox)`
margin-left: -8px;
`

const SelectTask: React.FC<Props> = ({ task }) => {
const SelectTaskWorkflow: React.FC<Props> = ({ task }) => {
const { case_user_task_id: taskId, owner: taskOwner, case: caseId } = task
const [isChecked, setIsChecked] = useState(false)
const [loading, setLoading] = useState(false)
const [me, { isBusy }] = useUsersMe()
const [, { execPatch }] = useTask(taskId)
const apiUrl = makeApiUrl("cases", caseId)
const apiUrl = makeApiUrl("cases", caseId, "workflows")

const { getContextItem, updateContextItem } = useContextCache("cases", apiUrl)

useEffect(() => {
Expand All @@ -49,25 +50,26 @@ const SelectTask: React.FC<Props> = ({ task }) => {
.then((resp: any) => {
if (resp.status === 200) {
// Owner is siuccesfully changed so update context tp prevent a hard page reload for just a checkbox.
const caseItem = getContextItem()
const response = getContextItem()
const workflows = response?.results
// Find the index of the workflow containing the task to be updated
const workflowIndex = caseItem.workflows.findIndex((workflow: any) =>
const workflowIndex = workflows.findIndex((workflow: any) =>
workflow.tasks.some((task: any) => task.case_user_task_id === taskId)
)
// If the workflow containing the task is found
if (workflowIndex !== -1) {
// Find the index of the task within the workflow
const taskIndex = caseItem.workflows[workflowIndex].tasks.findIndex((task: any) =>
const taskIndex = workflows[workflowIndex].tasks.findIndex((task: any) =>
task.case_user_task_id === taskId
)
// If the task is found within the workflow
if (taskIndex !== -1) {
// Make a deep copy of the original case object (Optional: to maintain immutability)
const updatedCase = structuredClone(caseItem)
const updatedResponse = structuredClone(response)
// Update the task as needed
updatedCase.workflows[workflowIndex].tasks[taskIndex].owner = resp.data.owner
updatedResponse.results[workflowIndex].tasks[taskIndex].owner = resp.data.owner
// Update context of the case
updateContextItem(updatedCase)
updateContextItem(updatedResponse)
} else {
console.error("Task not found within the workflow.")
}
Expand Down Expand Up @@ -95,4 +97,4 @@ const SelectTask: React.FC<Props> = ({ task }) => {
)
}

export default SelectTask
export default SelectTaskWorkflow

0 comments on commit 054de73

Please sign in to comment.