Skip to content

Commit 1cb3c1d

Browse files
[#700] Load segment answers for imported data from excel
1 parent 1ac47b4 commit 1cb3c1d

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

frontend/src/pages/cases/components/CaseSettings.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,14 @@ const CaseSettings = ({ open = false, handleCancel = () => {} }) => {
278278

279279
apiCall
280280
.then((res) => {
281+
let data = res?.data || {};
282+
data = {
283+
...data,
284+
segments: data?.segments?.length
285+
? orderBy(data.segments, ["id"])
286+
: [],
287+
};
288+
281289
// NEW 23-06-2026 :: set form segments id fields value after saving the data
282290
const currentSegments = form.getFieldValue("segments") || [];
283291
const segmentsWithID = data?.segments?.length
@@ -369,13 +377,6 @@ const CaseSettings = ({ open = false, handleCancel = () => {} }) => {
369377
// EOL track event
370378

371379
setPrevCaseSettingValue(filteredCurrentValue);
372-
let data = res?.data || {};
373-
data = {
374-
...data,
375-
segments: data?.segments?.length
376-
? orderBy(data.segments, ["id"])
377-
: [],
378-
};
379380

380381
const lowestSegmentId = data?.segments?.[0]?.id;
381382
const newActiveSegmentId = deleteSegment
@@ -525,7 +526,20 @@ const CaseSettings = ({ open = false, handleCancel = () => {} }) => {
525526
};
526527
api
527528
.post("case-import/generate-segment-values", confirmedSegPayload)
528-
.then(() => {
529+
.then((res) => {
530+
const generatedData = res.data;
531+
532+
/// update currentCase global state with generated segments from generatedData
533+
// when successfully generated segment values
534+
if (generatedData?.segments?.length) {
535+
CurrentCaseState.update((s) => ({
536+
...s,
537+
segments: orderBy(generatedData.segments, "id"),
538+
import_id: generatedData?.import_id || null,
539+
}));
540+
}
541+
// EOL
542+
529543
// reset form and close drawer
530544
setTimeout(() => {
531545
form.resetFields();

frontend/src/pages/cases/components/EnterIncomeDataForm.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ const EnterIncomeDataDriver = ({
371371

372372
const parentQuestionField = `${fieldKey}-${question?.parent}`;
373373

374-
// TODO :: remove this code to fix issue total income/section total
374+
// TODO :: remove this code to fix issue total income/section total (DONT REMOVE)
375375
/**
376376
* e.g. primary section total should be 1400
377377
* but if this part of code active the section total become 1600
@@ -380,7 +380,11 @@ const EnterIncomeDataDriver = ({
380380
const parentQuestionValue =
381381
initialDriverValues?.[parentQuestionField] || 0;
382382

383-
if (!parentQuestionValue && currentCase?.import_id) {
383+
if (
384+
parentQuestion?.question_type === "aggregator" &&
385+
!parentQuestionValue &&
386+
currentCase?.import_id
387+
) {
384388
const allChildrensValues = calculateChildrenValues(
385389
question,
386390
fieldKey,
@@ -396,12 +400,17 @@ const EnterIncomeDataDriver = ({
396400
: allChildrensValues.reduce((acc, { value }) => acc + value, 0);
397401
if (parentQuestion) {
398402
// use parent value if they already have value
399-
const formValue =
400-
parentQuestionValue || parentQuestionValue === 0
401-
? roundToDecimal(parentQuestionValue)
402-
: roundToDecimal(sumAllChildrensValues);
403+
const formValue = parentQuestionValue
404+
? roundToDecimal(parentQuestionValue)
405+
: roundToDecimal(sumAllChildrensValues);
403406
// EOL use parent value if they already have value
404407
form.setFieldValue(parentQuestionField, formValue);
408+
// trigger on change
409+
onValuesChange(
410+
{ [parentQuestionField]: formValue },
411+
form.getFieldsValue()
412+
);
413+
// eol trigger on change
405414
updateSectionTotalValues(
406415
commodity.commodity_type,
407416
fieldName,

frontend/src/pages/cases/store/current_case.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const defaultCurrentCaseState = {
6060
updated_by: null,
6161
updated_at: null,
6262
status: null,
63+
import_id: null,
6364
};
6465

6566
const CurrentCaseState = new Store(defaultCurrentCaseState);

0 commit comments

Comments
 (0)