Skip to content

Commit

Permalink
project type config simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavya-egov committed Oct 17, 2024
1 parent b350c6d commit 52bd9d6
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 366 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,44 +85,92 @@ function reverseDeliveryRemap(data, t) {
let currentCycleIndex = null;
let currentCycle = null;

// data.forEach((item, index) => {
// if (currentCycleIndex !== item.cycleNumber) {
// currentCycleIndex = item.cycleNumber;
// currentCycle = {
// cycleIndex: currentCycleIndex.toString(),
// startDate: item?.startDate ? Digit.Utils.date.convertEpochToDate(item?.startDate) : null,
// endDate: item?.endDate ? Digit.Utils.date.convertEpochToDate(item?.endDate) : null,
// active: index === 0, // Initialize active to false
// deliveries: [],
// };
// reversedData.push(currentCycle);
// }
const operatorMapping = {
"<=": "LESS_THAN_EQUAL_TO",
">=": "GREATER_THAN_EQUAL_TO",
"<": "LESS_THAN",
">": "GREATER_THAN",
"==": "EQUAL_TO",
"!=": "NOT_EQUAL_TO",
"IN_BETWEEN": "IN_BETWEEN"
};

const cycles = data?.[0]?.cycles || [];
const transformedCycles = cycles.map((cycle) => {
const deliveries = cycle.deliveries?.map((delivery, deliveryIndex) => {
const doseCriteria = delivery.doseCriteria?.flatMap((criteria, ruleKey) => {
const products = criteria.ProductVariants.map((variant, key) => ({
key: key + 1,
count: 1,
value: variant.productVariantId,
name: variant.name
}));

const condition = criteria.condition;
let conditionParts = condition.split("and").map(part => part.trim());
let rules = [];
conditionParts.forEach((part) => {
const parts = part.split(' ').filter(Boolean);

let attributes = [];
if (parts.length === 5 && (parts[1] === "<=" || parts[1] === "<") && (parts[3] === "<" || parts[3] === "<=")) {
const toValue = parts[0];
const fromValue = parts[4];
attributes.push({
key: 1, // Incrementing key for each attribute
operator: { code: operatorMapping["IN_BETWEEN"] },
attribute: { code: parts[2] },
fromValue,
toValue
});
} else {
// Parse single conditions using regex
const match = part.match(/(.*?)\s*(<=|>=|<|>|==|!=)\s*(.*)/);
if (match) {
const attributeCode = match[1].trim();
const operatorSymbol = match[2].trim();
const value = match[3].trim();
attributes.push({
key: attributes.length + 1, // Incrementing key for each attribute
value,
operator: { code: operatorMapping[operatorSymbol] },
attribute: { code: attributeCode }
});
}
}

// const deliveryIndex = item.deliveryNumber.toString();
// Add each part as a new delivery rule
rules.push({
ruleKey: ruleKey + 1,
delivery: {},
products,
attributes
});
});

// let delivery = currentCycle.deliveries.find((delivery) => delivery.deliveryIndex === deliveryIndex);
return rules;
});

// if (!delivery) {
// delivery = {
// deliveryIndex: deliveryIndex,
// active: item.deliveryNumber === 1, // Set active to true only for the first delivery
// deliveryRules: [],
// };
// currentCycle.deliveries.push(delivery);
// }
return {
active: true,
deliveryIndex: String(deliveryIndex + 1),
deliveryRules: doseCriteria
};
});

return {
active: true,
cycleIndex: String(cycle.id),
deliveries: deliveries
};
});

return transformedCycles;

// delivery.deliveryRules.push({
// ruleKey: item.deliveryRuleNumber,
// delivery: {},
// attributes: loopAndReturn(item.conditions, t),
// products: [...item.products],
// });
// });
return data;

return reversedData;
}


function boundaryDataGrp(boundaryData) {
// Create an empty object to hold grouped data by type
const groupedData = {};
Expand Down Expand Up @@ -406,16 +454,16 @@ const CampaignSummary = (props) => {
{
key: "CAMPAIGN_NO_OF_CYCLES",
value:
data?.[0]?.deliveryRules && data?.[0]?.deliveryRules.map((item) => item.cycleIndex)?.length > 0
? Math.max(...data?.[0]?.deliveryRules.map((item) => item.cycleIndex))
data?.[0]?.additionalDetails?.cycleData?.cycleConfgureDate?.cycle ?
data?.[0]?.additionalDetails?.cycleData?.cycleConfgureDate?.cycle
: t("CAMPAIGN_SUMMARY_NA"),
},
{
key: "CAMPAIGN_NO_OF_DELIVERIES",
value:
data?.[0]?.deliveryRules && data?.[0]?.deliveryRules?.flatMap((rule) => rule?.deliveries?.map((delivery) => delivery?.deliveryIndex))?.length > 0
? Math.max(...data?.[0]?.deliveryRules?.flatMap((rule) => rule?.deliveries?.map((delivery) => delivery?.deliveryIndex)))
: t("CAMPAIGN_SUMMARY_NA"),
data?.[0]?.additionalDetails?.cycleData?.cycleConfgureDate?.deliveries ?
data?.[0]?.additionalDetails?.cycleData?.cycleConfgureDate?.deliveries
: t("CAMPAIGN_SUMMARY_NA"),
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const CampaignUpdateSummary = (props) => {
},
cardHeader: { value: t("TARGET_DETAILS"), inlineStyles: { marginTop: 0, fontSize: "1.5rem" } },
cardSecondaryAction: noAction !== "false" && (
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(2)}>
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(4)}>
<span>{t(`CAMPAIGN_EDIT`)}</span>
<EditIcon />
</div>
Expand All @@ -234,7 +234,7 @@ const CampaignUpdateSummary = (props) => {
},
cardHeader: { value: t("FACILITY_DETAILS"), inlineStyles: { marginTop: 0, fontSize: "1.5rem" } },
cardSecondaryAction: noAction !== "false" && (
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(3)}>
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(2)}>
<span>{t(`CAMPAIGN_EDIT`)}</span>
<EditIcon />
</div>
Expand All @@ -254,7 +254,7 @@ const CampaignUpdateSummary = (props) => {
},
cardHeader: { value: t("USER_DETAILS"), inlineStyles: { marginTop: 0, fontSize: "1.5rem" } },
cardSecondaryAction: noAction !== "false" && (
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(4)}>
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(3)}>
<span>{t(`CAMPAIGN_EDIT`)}</span>
<EditIcon />
</div>
Expand Down
Loading

0 comments on commit 52bd9d6

Please sign in to comment.