Skip to content

Commit

Permalink
API Error localisation change, Gender localisation in summary (#579)
Browse files Browse the repository at this point in the history
* no of cycle and deivery drafted changes

* fixes

* add localisation code for boundaries

* fixes

* fixes

* Value localise in summary screen, api error change

---------

Co-authored-by: nabeelmd-eGov <[email protected]>
  • Loading branch information
nabeelmd-eGov and nabeelmd-eGov authored May 15, 2024
1 parent a6dc1fc commit b491428
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function mergeObjects(item) {
return mergedArr;
}

function loopAndReturn(dataa) {
function loopAndReturn(dataa, t) {
let newArray = [];
const data = dataa?.map((i) => ({ ...i, operator: i?.operator, attribute: i?.attribute }));

Expand All @@ -54,7 +54,7 @@ function loopAndReturn(dataa) {
} else if (item?.operator === "EQUAL_TO") {
newArray.push({
...item,
value: item?.value ? item?.value : null,
value: item?.value ? t(item?.value) : null,
});
} else {
newArray.push(item);
Expand All @@ -76,7 +76,7 @@ function loopAndReturn(dataa) {
return format;
}

function reverseDeliveryRemap(data) {
function reverseDeliveryRemap(data, t) {
if (!data) return null;
const reversedData = [];
let currentCycleIndex = null;
Expand Down Expand Up @@ -111,7 +111,7 @@ function reverseDeliveryRemap(data) {
delivery.deliveryRules.push({
ruleKey: item.deliveryRuleNumber,
delivery: {},
attributes: loopAndReturn(item.conditions),
attributes: loopAndReturn(item.conditions, t),
products: [...item.products],
});
});
Expand Down Expand Up @@ -142,7 +142,7 @@ const CampaignSummary = () => {
}
});
const target = data?.[0]?.deliveryRules;
const cycleData = reverseDeliveryRemap(target);
const cycleData = reverseDeliveryRemap(target, t);
return {
cards: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ import { mailConfig } from "../configs/mailConfig";
function SelectingBoundaries({ onSelect, formData, ...props }) {
const { t } = useTranslation();
const tenantId = Digit.ULBService.getCurrentTenantId();
const [params,setParams] = useState(props?.props?.dataParams);
const [params, setParams] = useState(props?.props?.dataParams);
const [hierarchy, setHierarchy] = useState(params?.hierarchyType);
// const [hierarchy, setHierarchy] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.hierarchy || {});
// const [showcomponent, setShowComponent] = useState(
// props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.hierarchy || false
// );
// const [boundaryType, setBoundaryType] = useState(null);
const [boundaryType, setBoundaryType] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.boundaryData ? undefined : null);
const [boundaryType, setBoundaryType] = useState(
props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.boundaryData ? undefined : null
);
const [boundaryData, setBoundaryData] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.boundaryData || {});
// const [parentArray, setParentArray] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.selectedData.filter(item => item.includeAllChildren).map(item => item.code) || null);
const [parentArray , setParentArray] = useState(null);
const [parentArray, setParentArray] = useState(null);
const [boundaryTypeDataresult, setBoundaryTypeDataresult] = useState(null);
const [selectedData, setSelectedData] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.selectedData || []);
const [parentBoundaryTypeRoot, setParentBoundaryTypeRoot] = useState(
Expand All @@ -37,31 +39,30 @@ function SelectingBoundaries({ onSelect, formData, ...props }) {
const [hierarchyTypeDataresult, setHierarchyTypeDataresult] = useState(params?.hierarchy);
const [executionCount, setExecutionCount] = useState(0);
// State variable to store the lowest hierarchy level
const [lowestHierarchy , setLowestHierarchy] = useState(null);
const [lowestHierarchy, setLowestHierarchy] = useState(null);

useEffect(() => {
if(props?.props?.dataParams){
setParams(props?.props?.dataParams)
if (props?.props?.dataParams) {
setParams(props?.props?.dataParams);
}
},[props?.props?.dataParams])
}, [props?.props?.dataParams]);

useEffect(() => {
onSelect("boundaryType", { boundaryData: boundaryData, selectedData: selectedData});
}, [boundaryData, selectedData ]);
onSelect("boundaryType", { boundaryData: boundaryData, selectedData: selectedData });
}, [boundaryData, selectedData]);

useEffect(() => {
setHierarchy(params?.hierarchyType);
}, [params?.hierarchyType ]);
}, [params?.hierarchyType]);


useEffect(() => {
setHierarchyTypeDataresult(params?.hierarchy);
}, [params?.hierarchy ]);
}, [params?.hierarchy]);

useEffect(() => {
if (executionCount < 5) {
onSelect("boundaryType", { boundaryData: boundaryData, selectedData: selectedData});
setExecutionCount(prevCount => prevCount + 1);
onSelect("boundaryType", { boundaryData: boundaryData, selectedData: selectedData });
setExecutionCount((prevCount) => prevCount + 1);
}
});

Expand Down Expand Up @@ -96,22 +97,26 @@ function SelectingBoundaries({ onSelect, formData, ...props }) {
if (boundaryWithTypeNullParent) {
if (!props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.boundaryData || Object.keys(boundaryData).length === 0) {
setBoundaryType(boundaryWithTypeNullParent?.boundaryType);
}
setParentBoundaryTypeRoot(boundaryWithTypeNullParent?.boundaryType);
}
setParentBoundaryTypeRoot(boundaryWithTypeNullParent?.boundaryType);
}
createHierarchyStructure(hierarchyTypeDataresult);

setLowestHierarchy(hierarchyTypeDataresult?.boundaryHierarchy?.filter(e=>!hierarchyTypeDataresult?.boundaryHierarchy?.find(e1=>e1?.parentBoundaryType==e?.boundaryType)))
}
}, [hierarchyTypeDataresult]);

setLowestHierarchy(
hierarchyTypeDataresult?.boundaryHierarchy?.filter(
(e) => !hierarchyTypeDataresult?.boundaryHierarchy?.find((e1) => e1?.parentBoundaryType == e?.boundaryType)
)
);
}
}, [hierarchyTypeDataresult]);

function createHierarchyStructure(hierarchyTypeDataresult) {
const hierarchyStructure = {};

// Recursive function to gather all descendants for a given boundary type
function gatherDescendants(boundaryType) {
const descendants = [];hierarchyTypeDataresult
const descendants = [];
hierarchyTypeDataresult;

// Find all children for the current boundary type
const children = hierarchyTypeDataresult?.boundaryHierarchy?.filter((item) => item?.parentBoundaryType === boundaryType);
Expand All @@ -135,7 +140,6 @@ function SelectingBoundaries({ onSelect, formData, ...props }) {
});

setUpdatedHierarchy(hierarchyStructure);

}

const newData = [];
Expand Down Expand Up @@ -239,7 +243,7 @@ function SelectingBoundaries({ onSelect, formData, ...props }) {
// res.forEach((boundary) => {
// const index = transformedRes?.findIndex((item) => item?.code === boundary?.code);
// if (index !== -1) {
// transformedRes[index].includeAllChildren = true;
// transformedRes[index].includeAllChildren = true;
// }
// // Find the parent boundary type using the hierarchy data
// const parentBoundaryType = hierarchyTypeDataresult?.boundaryHierarchy?.find((e) => e?.boundaryType === boundary?.boundaryType)
Expand All @@ -260,7 +264,6 @@ function SelectingBoundaries({ onSelect, formData, ...props }) {
// }
// });


const newBoundaryType = transformedRes?.[0]?.type;
const existingBoundaryType = selectedData?.length > 0 ? selectedData?.[0]?.type : null;
if (existingBoundaryType === newBoundaryType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ const UploadData = ({ formData, onSelect, ...props }) => {
params: {
tenantId: tenantId,
type: type,
hierarchyType: params.hierarchyType,
hierarchyType: params?.hierarchyType,
id: type === "boundary" ? params?.boundaryId : type === "facilityWithBoundary" ? params?.facilityId : params?.userId,
},
};
Expand All @@ -570,7 +570,7 @@ const UploadData = ({ formData, onSelect, ...props }) => {
params: {
tenantId: tenantId,
type: type,
hierarchyType: params.hierarchyType,
hierarchyType: params?.hierarchyType,
id: type === "boundary" ? params?.boundaryId : type === "facilityWithBoundary" ? params?.facilityId : params?.userId,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ const createCampaignService = async (req, tenantId) => {
});
return response;
} catch (error) {
throw new Error(error?.response?.data?.Errors[0].description);
if (!error?.response?.data?.Errors[0].description) {
throw new Error(error?.response?.data?.Errors[0].code);
} else {
throw new Error(error?.response?.data?.Errors[0].description);
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ const updateCampaignService = async (req, tenantId) => {
});
return response;
} catch (error) {
throw new Error(error?.response?.data?.Errors[0].message);
// throw new Error(error?.response?.data?.Errors[0].message);
if (!error?.response?.data?.Errors[0].description) {
throw new Error(error?.response?.data?.Errors[0].code);
} else {
throw new Error(error?.response?.data?.Errors[0].description);
}
}
};

Expand Down

0 comments on commit b491428

Please sign in to comment.