Skip to content

Commit aaaa534

Browse files
committed
Added date field and sort subform for child functioning
1 parent d238967 commit aaaa534

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

app/javascript/components/pages/admin/child-functioning/SubformSummary.jsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { toServerDateFormat } from "../../../../libs";
34
import childFunctioningSummaryData from './childFunctioningSummaryData';
45

56
const formatKey = (key) =>
@@ -13,7 +14,10 @@ const formatValue = (key, value) => {
1314
return `${value.replace("_", " to ")} years`;
1415
if (value.includes("_"))
1516
return value.replace(/_/g, " ").replace(/\b\w/g, (char) => char.toUpperCase());
16-
if (!Number.isNaN(Date.parse(value))) return new Date(value).toLocaleDateString(); // Fixed here
17+
const parsedDate = new Date(value);
18+
if (!Number.isNaN(parsedDate.getTime())) {
19+
return toServerDateFormat(parsedDate, { includeTime: false });
20+
}
1721
return value;
1822
}
1923
return value; // Handle non-string values

app/javascript/components/pages/admin/child-functioning/childFunctioningSummaryData.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const childFunctioningSummaryData = [
2+
{ label: "Date", key: "date_fa81c1a"},
23
{ label: "Are you ready to start the Child Functioning Module", key: "cfm_start" },
34
{ label: "Age", key: "cfm_age" },
45
{ label: "Vision wear glass", key: (latestValue) => `cfm_${latestValue?.cfm_age}_vision_wears_glasses` },

app/javascript/components/record-form/form/subforms/subform-field-array/component.jsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { VIOLATIONS_ASSOCIATIONS_FORM } from "../../../../../config";
1414
import css from "../styles.css";
1515
import { isFamilyDetailSubform, isFamilyMemberSubform, isViolationSubform } from "../../utils";
1616
import { GuidingQuestions } from "../../components";
17-
17+
import orderBy from "lodash/orderBy";
1818
import { isEmptyOrAllDestroyed, isTracesSubform } from "./utils";
1919
import SubformSummary from "../../../../pages/admin/child-functioning/SubformSummary"
2020
function Component({
@@ -76,14 +76,16 @@ function Component({
7676
}
7777
}, [index]);
7878

79+
const sortedRecordsByDateDesc = orderBy(orderedValues, [(v) => new Date(v["date_fa81c1a"])], ["desc"]);
80+
7981
const renderEmptyData = isEmptyOrAllDestroyed(orderedValues) ? (
8082
<SubformEmptyData subformName={title} />
8183
) : (
8284
<List dense={renderAsAccordion} classes={{ root: css.list }} disablePadding>
8385
<SubformFields
8486
arrayHelpers={arrayHelpers}
8587
field={field}
86-
values={orderedValues}
88+
values={title === 'Child Functioning Subform' ? sortedRecordsByDateDesc : orderedValues}
8789
locale={i18n.locale}
8890
mode={mode}
8991
setOpen={setOpenDialog}
@@ -109,15 +111,16 @@ function Component({
109111
<GuidingQuestions label={i18n.t("buttons.guidance")} text={guidingQuestions[i18n.locale]} />
110112
</div>
111113
);
112-
const latestValue = orderedValues === undefined ? null : orderedValues[orderedValues.length - 1]
114+
115+
const getlatestValue = (arr) => arr?.[0] ?? null;
116+
const latestValue = getlatestValue(sortedRecordsByDateDesc);
113117
return (
114118
<div className={css.fieldArray} data-testid="subform-field-array">
115119

116120
{/* Conditionally Render Child Functioning Subform Summary */}
117121
{title === 'Child Functioning Subform' && (
118122
<SubformSummary latestValue={latestValue} />
119123
)}
120-
121124
<div className={cssContainer}>
122125
{!renderAsAccordion && (
123126
<div data-testid="subForm-header">
@@ -162,7 +165,7 @@ function Component({
162165
mode={mode}
163166
selectedValue={selectedValue}
164167
open={open}
165-
orderedValues={orderedValues}
168+
orderedValues={title === 'Child Functioning Subform' ? sortedRecordsByDateDesc : orderedValues}
166169
recordModuleID={recordModuleID}
167170
recordType={recordType}
168171
setOpen={setOpenDialog}

0 commit comments

Comments
 (0)