Skip to content

Commit

Permalink
HLM-5630/HL-5635- summary cache data fix (#347)
Browse files Browse the repository at this point in the history
* Error message for mandatory

* HLM-5630/HL-5635- summary cache data fix

---------

Co-authored-by: nabeelmd-eGov <[email protected]>
  • Loading branch information
nabeelmd-eGov and nabeelmd-eGov authored Apr 19, 2024
1 parent 3cbdf66 commit a41e3e9
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 353 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ const CampaignSummary = () => {
},
{
key: "CAMPAIGN_START_DATE",
value: Digit.Utils.date.convertEpochToDate(data?.[0]?.campaignDetails?.startDate) || t("CAMPAIGN_SUMMARY_NA"),
value: Digit.Utils.date.convertEpochToDate(data?.[0]?.startDate) || t("CAMPAIGN_SUMMARY_NA"),
},
{
key: "CAMPAIGN_END_DATE",
value: Digit.Utils.date.convertEpochToDate(data?.[0]?.campaignDetails?.endDate) || t("CAMPAIGN_SUMMARY_NA"),
value: Digit.Utils.date.convertEpochToDate(data?.[0]?.endDate) || t("CAMPAIGN_SUMMARY_NA"),
},
],
},
Expand All @@ -71,26 +71,28 @@ const CampaignSummary = () => {
},
],
},
...data?.[0]?.campaignDetails?.deliveryRules?.map((item, index) => ({
sections: [
{
type: "COMPONENT",
cardHeader: { value: t("DELIVERY_CYCLE_DETAILS"), inlineStyles: { marginTop: 0 } },
cardSecondaryAction: (
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(2)}>
<span>{t(`CAMPAIGN_EDIT`)}</span>
<EditIcon />
</div>
),
component: "CycleDetaisPreview",
props: {
data: data?.[0],
item: item,
index: index,
...data?.[0]?.campaignDetails?.deliveryRules?.map((item, index) => {
return {
sections: [
{
type: "COMPONENT",
cardHeader: { value: t("DELIVERY_CYCLE_DETAILS"), inlineStyles: { marginTop: 0 } },
cardSecondaryAction: (
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(2)}>
<span>{t(`CAMPAIGN_EDIT`)}</span>
<EditIcon />
</div>
),
component: "CycleDetaisPreview",
props: {
data: data?.[0],
items: item,
index: index,
},
},
},
],
})),
],
};
}),
],
};
},
Expand All @@ -104,281 +106,10 @@ const CampaignSummary = () => {
history.push(`/${window?.contextPath}/employee/campaign/setup-campaign?step=${step}`);
};

const DUMMY_DATA = [
{
id: "899e6cdf-93b5-4fac-b8bb-4d6404622227",
tenantId: "mz",
status: "started",
action: "create",
campaignNumber: "CMP-2024-03-21-000070",
campaignName: null,
projectType: null,
hierarchyType: "ADMIN",
boundaryCode: "mz",
projectId: null,
createdBy: "867ba408-1b82-4746-8274-eb916e625fea",
lastModifiedBy: "867ba408-1b82-4746-8274-eb916e625fea",
createdTime: 1711020182790,
lastModifiedTime: 1711020182790,
additionalDetails: {},
campaignDetails: {
endDate: 1665929225005,
startDate: 1665497225000,
deliveryRules: [
{
endDate: 1665497225000,
products: [
{
product: "string",
count: 2,
},
{
product: "skljsdlk",
count: 2,
},
{
product: "d38732897",
count: 3,
},
{
product: "jkhdskdsj",
count: 4,
},
],
startDate: 1665497225000,
conditions: [
{
value: 0,
operator: "string",
attribute: "string",
},
],
cycleNumber: 1,
deliveryNumber: 1,
deliveryRuleNumber: 1,
},
{
endDate: 1665497225000,
products: [
{
product: "string",
count: 2,
},
{
product: "skljsdlk",
count: 2,
},
{
product: "d38732897",
count: 3,
},
{
product: "jkhdskdsj",
count: 4,
},
],
startDate: 1665497225000,
conditions: [
{
value: 0,
operator: "string",
attribute: "string",
},
],
cycleNumber: 1,
deliveryNumber: 2,
deliveryRuleNumber: 1,
},
{
endDate: 1665497225000,
products: [
{
product: "string",
count: 2,
},
{
product: "skljsdlk",
count: 2,
},
{
product: "d38732897",
count: 3,
},
{
product: "jkhdskdsj",
count: 4,
},
],
startDate: 1665497225000,
conditions: [
{
value: 0,
operator: "string",
attribute: "string",
},
],
cycleNumber: 2,
deliveryNumber: 1,
deliveryRuleNumber: 1,
},
{
endDate: 1665497225000,
products: [
{
product: "string",
count: 2,
},
{
product: "skljsdlk",
count: 2,
},
{
product: "d38732897",
count: 3,
},
{
product: "jkhdskdsj",
count: 4,
},
],
startDate: 1665497225000,
conditions: [
{
value: 0,
operator: "dasjhdasjh",
attribute: "ASSS",
},
{
value: 0,
operator: "akaskjasklj",
attribute: "uyeewquy",
},
{
value: 0,
operator: "jasdkjsda",
attribute: "jdkjdask",
},
],
cycleNumber: 2,
deliveryNumber: 2,
deliveryRuleNumber: 1,
},
],
},
},
];

const config = {
cards: [
{
sections: [
{
type: "DATA",
cardHeader: { value: t("CAMPAIGN_DETAILS"), inlineStyles: { marginTop: 0 } },
cardSecondaryAction: (
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(1)}>
<span>{t(`CAMPAIGN_EDIT`)}</span>
<EditIcon />
</div>
),
values: [
{
key: "CAMPAIGN_TYPE",
value: DUMMY_DATA?.[0]?.projectType || t("CAMPAIGN_SUMMARY_NA"),
},
{
key: "CAMPAIGN_NAME",
value: DUMMY_DATA?.[0]?.campaignName || t("CAMPAIGN_SUMMARY_NA"),
},
{
key: "CAMPAIGN_START_DATE",
value: Digit.Utils.date.convertEpochToDate(DUMMY_DATA?.[0]?.campaignDetails?.startDate) || t("CAMPAIGN_SUMMARY_NA"),
},
{
key: "CAMPAIGN_END_DATE",
value: Digit.Utils.date.convertEpochToDate(DUMMY_DATA?.[0]?.campaignDetails?.endDate) || t("CAMPAIGN_SUMMARY_NA"),
},
],
},
],
},
{
sections: [
{
type: "DATA",
cardHeader: { value: t("TARGET_DETAILS"), inlineStyles: { marginTop: 0 } },
cardSecondaryAction: (
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(4)}>
<span>{t(`CAMPAIGN_EDIT`)}</span>
<EditIcon />
</div>
),
values: [
{
key: "CAMPAIGN_TYPE",
value: DUMMY_DATA?.[0]?.hierarchyType || t("CAMPAIGN_SUMMARY_NA"),
},
],
},
],
},
...DUMMY_DATA?.[0]?.campaignDetails?.deliveryRules?.map((item, index) => ({
sections: [
{
type: "COMPONENT",
cardHeader: { value: t("DELIVERY_CYCLE_DETAILS"), inlineStyles: { marginTop: 0 } },
cardSecondaryAction: (
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(2)}>
<span>{t(`CAMPAIGN_EDIT`)}</span>
<EditIcon />
</div>
),
component: "CycleDetaisPreview",
props: {
DUMMY_DATA: DUMMY_DATA?.[0],
item: item,
index: index,
},
// values: [
// {
// key: "CAMPAIGN_TYPE",
// value: t("CAMPAIGN_SUMMARY_NA"),
// },
// {
// key: "CAMPAIGN_NAME",
// value: t("CAMPAIGN_SUMMARY_NA"),
// },
// {
// key: "CAMPAIGN_START_DATE",
// value: t("CAMPAIGN_SUMMARY_NA"),
// },
// {
// key: "CAMPAIGN_END_DATE",
// value: t("CAMPAIGN_SUMMARY_NA"),
// },
// ],
},
],
})),
],
};

if (isLoading) {
return <Loader />;
}

if (!id) {
return (
<React.Fragment>
<div className="cardHeaderWithOptions">
<Header>{t("ES_TQM_SUMMARY_HEADING")}</Header>
</div>

<ViewComposer data={config} />
</React.Fragment>
);
}

return (
<>
<Header>{t("ES_TQM_SUMMARY_HEADING")}</Header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,41 @@ import React, { Fragment } from "react";
import { useTranslation } from "react-i18next";
import DetailsTable from "./DetailsTable";

const CycleDetaisPreview = ({ data, item, index }) => {
function mergeObjects(item) {
const arr = item?.conditions;
const mergedArr = [];
const mergedAttributes = new Set();

arr.forEach((obj) => {
if (!mergedAttributes.has(obj.attribute)) {
const sameAttrObjs = arr.filter((o) => o.attribute === obj.attribute);

if (sameAttrObjs.length > 1) {
const fromValue = Math.min(...sameAttrObjs.map((o) => o.value));
const toValue = Math.max(...sameAttrObjs.map((o) => o.value));

mergedArr.push({
fromValue,
toValue,
value: `${fromValue} to ${toValue}`,
operator: "IN_BETWEEN",
attribute: obj.attribute,
});

mergedAttributes.add(obj.attribute);
} else {
mergedArr.push(obj);
}
}
});

return { ...item, conditions: mergedArr };
}

const CycleDetaisPreview = ({ data, items, index }) => {
const { t } = useTranslation();
// const { cycleNumber, deliveryNumber } = data?.campaignDetails?.deliveryRules.reduce(
// (acc, { cycleNumber, deliveryNumber }) => ({
// cycleNumber: Math.max(acc.cycleNumber, cycleNumber),
// deliveryNumber: Math.max(acc.deliveryNumber, deliveryNumber),
// }),
// { cycleNumber: 0, deliveryNumber: 0 }
// );
const item = mergeObjects(items);

return (
<>
<Row
Expand Down
Loading

0 comments on commit a41e3e9

Please sign in to comment.