Skip to content

Commit

Permalink
Merge pull request #2294 from techmatters/SJH-fix_case_print_update
Browse files Browse the repository at this point in the history
Ensure case print updates after case sections are added
  • Loading branch information
stephenhand authored May 10, 2024
2 parents 4d26116 + 9d3b39d commit 1bbc712
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions plugin-hrm-form/src/components/case/casePrint/CasePrintView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ const MAX_PRINTOUT_CONTACTS = 100;
const SECTION_NAMES = ['perpetrator', 'incident', 'referral', 'household', 'note'] as const;

const mapStateToProps = (state: RootState, { task }: OwnProps) => {
const { connectedCase } = selectCurrentRouteCaseState(state, task.taskSid);
const { connectedCase, sections } = selectCurrentRouteCaseState(state, task.taskSid);
const sectionIdCsvsEntries = SECTION_NAMES.map(
sectionName => [sectionName, Object.keys(sections?.[sectionName] ?? {}).join(',')], // Used to trigger re-fetch of sections
);
const sectionEntries = SECTION_NAMES.map(
sectionName =>
[
Expand All @@ -73,6 +76,7 @@ const mapStateToProps = (state: RootState, { task }: OwnProps) => {
counselorsHash: selectCounselorsHash(state),
connectedCase,
sectionTimelines: Object.fromEntries(sectionEntries),
sectionIdCsvs: Object.fromEntries(sectionIdCsvsEntries),
contactTimeline: selectTimeline(state, connectedCase?.id, 'print-contacts', {
offset: 0,
limit: MAX_PRINTOUT_CONTACTS,
Expand Down Expand Up @@ -107,6 +111,7 @@ const CasePrintView: React.FC<Props> = ({
office,
contactTimeline,
sectionTimelines,
sectionIdCsvs,
loadSectionTimeline,
loadContactTimeline,
}) => {
Expand All @@ -131,17 +136,9 @@ const CasePrintView: React.FC<Props> = ({
for (const sectionName of SECTION_NAMES) {
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(
() => {
if (!sectionTimelines[sectionName]) {
loadSectionTimeline(connectedCase.id, sectionName);
}
},
() => loadSectionTimeline(connectedCase.id, sectionName),
// eslint-disable-next-line react-hooks/exhaustive-deps
[
connectedCase.id,
// eslint-disable-next-line react-hooks/exhaustive-deps
Boolean(sectionTimelines[sectionName]),
],
[connectedCase.id, sectionIdCsvs[sectionName]],
);
}
/*
Expand Down

0 comments on commit 1bbc712

Please sign in to comment.