Skip to content

Commit

Permalink
update the investment on company changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chopkinsmade committed Jan 2, 2024
1 parent 2d8210a commit f715c17
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
68 changes: 43 additions & 25 deletions src/client/modules/Tasks/TaskForm/TaskFormFields.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
FieldCompaniesTypeahead,
FieldTypeahead,
} from '../../../components'

import { ID as TASK_DETAILS_ID } from '../TaskDetails/state'
import { validateDaysRange, validateIfDateInFuture } from './validators'
import { FORM_LAYOUT, OPTIONS_YES_NO } from '../../../../common/constants'
import { OPTIONS } from './constants'
Expand All @@ -23,6 +23,7 @@ import { TASK_SAVE_TASK_DETAILS } from './state'
import Task from '../../../components/Task'
import { TASK_GET_PROJECTS_LIST } from '../../Investments/Projects/state'
import { INVESTMENTS__PROJECTS_LOADED } from '../../../actions'
import Effect from '../../../components/Effect'

const StyledFieldInput = styled(FieldInput)`
text-align: center;
Expand Down Expand Up @@ -66,7 +67,7 @@ const TaskFormFields = ({
submitButtonLabel="Save task"
cancelButtonLabel="Back"
>
{({ values }) => (
{({ values, setFieldValue }) => (
<>
<FieldInput
label="Task title"
Expand Down Expand Up @@ -152,30 +153,47 @@ const TaskFormFields = ({
initialValue={task?.company}
/>
{(task?.company || values.company) && (
<>
{/* todo - this needs to refire the query when the company value changes */}
<Task.Status
name={TASK_GET_PROJECTS_LIST}
startOnRender={{
payload: {
limit: 250,
companyId: task?.company?.value || values.company.value,
},
onSuccessDispatch: INVESTMENTS__PROJECTS_LOADED,
}}
></Task.Status>
<Task>
{(getTask) => {
const getProjectsTask = getTask(
TASK_GET_PROJECTS_LIST,
TASK_DETAILS_ID
)

const companyId = values.company?.value || task?.company?.value

{companyInvestmentProjects && (
<FieldTypeahead
options={companyInvestmentProjects}
name="investmentProject"
label="Investment project (optional)"
hint="This will link the task to the project selected. The task will be added to your task list on the homepage."
initialValue={task?.investmentProject}
placeholder="Type to search for investment projects"
/>
)}
</>
return (
<>
<Effect
dependencyList={[companyId]}
effect={() => {
setFieldValue('investmentProject', {
value: null,
label: null,
})
getProjectsTask.start({
payload: {
limit: 250,
companyId: companyId,
},
onSuccessDispatch: INVESTMENTS__PROJECTS_LOADED,
})
}}
/>
{companyInvestmentProjects && (
<FieldTypeahead
options={companyInvestmentProjects}
name="investmentProject"
label="Investment project (optional)"
hint="This will link the task to the project selected. The task will be added to your task list on the homepage."
initialValue={task?.investmentProject}
placeholder="Type to search for investment projects"
/>
)}
</>
)
}}
</Task>
)}
</>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/client/modules/Tasks/TaskForm/transformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const transformTaskFormValuesForAPI = (
})

const getUniquePKValue = (formValues) => {
if (formValues.investmentProject) {
if (formValues?.investmentProject?.value) {
return {
investment_project: formValues.investmentProject.value,
company: null,
Expand Down

0 comments on commit f715c17

Please sign in to comment.