Skip to content
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
31 changes: 1 addition & 30 deletions plugin-hrm-form/src/___tests__/states/case/saveCase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { mockLocalFetchDefinitions } from '../../mockFetchDefinitions';
import '../../mockGetConfig';
import { createCaseAsyncAction, saveCaseReducer, updateCaseOverviewAsyncAction } from '../../../states/case/saveCase';
import { HrmState } from '../../../states';
import { reduce } from '../../../states/case/reducer';
import { createCase, getCase, updateCaseOverview, updateCaseStatus } from '../../../services/CaseService';
import { connectToCase } from '../../../services/ContactService';
import { ReferralLookupStatus } from '../../../states/contacts/resourceReferral';
Expand Down Expand Up @@ -182,28 +181,6 @@ const contact = {
referrals: [],
};

const expectObject: RecursivePartial<HrmState> = {
...partialState,
connectedCase: {
cases: {
[mockPayload.id]: {
connectedCase: mockPayload,
caseWorkingCopy: {
sections: {},
caseSummary: {
status: 'test-st',
followUpDate: '',
childIsAtRisk: false,
summary: '',
},
},
availableStatusTransitions: [],
references: new Set(['x']),
},
},
},
};

describe('createCaseAsyncAction', () => {
test('Calls the createCase service, and create a case', () => {
createCaseAsyncAction(contact, workerSid, definitionVersion);
Expand All @@ -230,7 +207,7 @@ describe('createCaseAsyncAction', () => {
id: '234',
info: {},
},
references: new Set(),
references: new Set(['contact-contact-1']),
sections: {},
timelines: {},
outstandingUpdateCount: 0,
Expand All @@ -239,12 +216,6 @@ describe('createCaseAsyncAction', () => {
},
});
});

test('should handle createCaseAsyncAction in the reducer', async () => {
const expected: HrmState = expectObject as HrmState;
const result = reduce(nonInitialState, createCaseAsyncAction(contact, workerSid, definitionVersion));
expect(result).toEqual(expected);
});
});

describe('updateCaseOverviewAsyncAction', () => {
Expand Down
5 changes: 4 additions & 1 deletion plugin-hrm-form/src/states/case/loadCaseIntoState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const loadCaseIntoState = ({
referenceId,
error = null,
loading = false,
preserveWorkingCopy = false,
}: {
state: CaseState;
caseId: Case['id'];
Expand All @@ -38,11 +39,13 @@ export const loadCaseIntoState = ({
referenceId: string;
loading?: boolean;
error?: ParseFetchErrorResult;
preserveWorkingCopy?: boolean;
}): CaseState => {
const existingCase = state.cases[caseId];
const statusUpdates = { loading, error };

const existingReferences = existingCase?.references;
const existingWorkingCopy = existingCase?.caseWorkingCopy;

if (!existingCase || !existingCase.connectedCase) {
return {
Expand All @@ -51,7 +54,7 @@ export const loadCaseIntoState = ({
...state.cases,
[caseId]: {
connectedCase: newCase,
caseWorkingCopy: { sections: {} },
caseWorkingCopy: preserveWorkingCopy && existingWorkingCopy ? existingWorkingCopy : { sections: {} },
availableStatusTransitions: getAvailableCaseStatusTransitions(newCase, definitionVersion),
// eslint-disable-next-line no-nested-ternary
references: existingReferences
Expand Down
2 changes: 2 additions & 0 deletions plugin-hrm-form/src/states/case/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ const loadCaseListIntoState = (
definitionVersion: caseDefinitionVersion,
newCase: caseToAdd,
referenceId,
// Any cases being worked on elsewhere when the list is loaded should have in-progress edits preserved
preserveWorkingCopy: true,
});
}, withoutOldSearchResults);
}
Expand Down
30 changes: 28 additions & 2 deletions plugin-hrm-form/src/states/case/saveCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { getAvailableCaseStatusTransitions } from './caseStatus';
import { connectToCase } from '../../services/ContactService';
import { connectToCaseAsyncAction } from '../contacts/saveContact';
import { markCaseAsUpdating } from './markCaseAsUpdating';
import { referenceCase } from './referenceCase';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't get why do we want to reference the case? If the counselor opens the case it will get referenced, so why keep it loaded?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think there are times when a contact needs to reference it's associated case without necessarily loading it into the UI. We always reference a case via it's contact if we load up a contact already associated with a case, but we didn't when we initially connected the case, so this resolves that inconsistency

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I think you are right, that's why the "connected case banner" is not clickable when the case is created - this should fix the bug.


const UPDATE_CASE_OVERVIEW_ACTION = 'case-action/update-overview';

Expand Down Expand Up @@ -129,13 +130,38 @@ const handleUpdateCaseOverviewFulfilledAction = (
const handleCreateCaseFulfilledAction = (
handleAction: CreateHandlerMap<HrmState>,
asyncAction: typeof createCaseAsyncAction.fulfilled,
) => handleAction(asyncAction, (state, { payload }): HrmState => updateConnectedCase(state, payload.newCase));
) =>
handleAction(
asyncAction,
(state, { payload }): HrmState => {
const { newCase, connectedContact } = payload;
const updatedState = updateConnectedCase(state, newCase);
return {
...updatedState,
connectedCase: referenceCase({
caseId: newCase.id,
referenceId: `contact-${connectedContact.id}`,
state: updatedState.connectedCase,
}),
};
},
);

const handleConnectToCaseFulfilledAction = (
handleAction: CreateHandlerMap<HrmState>,
asyncAction: typeof connectToCaseAsyncAction.fulfilled,
) =>
handleAction(asyncAction, (state, { payload: { contact, contactCase } }) => updateConnectedCase(state, contactCase));
handleAction(asyncAction, (state, { payload: { contact, contactCase } }) => {
const updated = updateConnectedCase(state, contactCase);
return {
...updated,
connectedCase: referenceCase({
caseId: contactCase.id,
referenceId: `contact-${contact.id}`,
state: updated.connectedCase,
}),
};
});

const handleCancelCaseFulfilledAction = (
handleAction: CreateHandlerMap<HrmState>,
Expand Down
Loading