Skip to content

Commit

Permalink
changes for the draft flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavya-egov committed Nov 8, 2024
1 parent 2760c50 commit f07aa9d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const DetailsTable = ({ className = "", columnsData, rowsData, summaryRows, card
else{
return{
...i,
value: typeof i?.value === "string"
? t(i.value)
: i?.value,
operator: t(i?.operator?.code) || t(i?.operator),
attribute: i?.attribute?.code
? t(`CAMPAIGN_ATTRIBUTE_${i.attribute.code.toUpperCase()}`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useReducer, Fragment, useEffect, useState } from "react";
import { CardText, LabelFieldPair, Card, CardLabel, CardSubHeader, Paragraph, Header } from "@egovernments/digit-ui-react-components";
import { CardText, LabelFieldPair, Card, CardLabel, CardSubHeader, Paragraph, Header , Loader } from "@egovernments/digit-ui-react-components";
import { useTranslation } from "react-i18next";
import { TextInput, InfoCard , Stepper , TextBlock } from "@egovernments/digit-ui-components";
import { deliveryConfig } from "../../configs/deliveryConfig";
Expand Down Expand Up @@ -72,6 +72,7 @@ const updateCycleData = (cycleData, index, update) => {

function CycleConfiguration({ onSelect, formData, control, ...props }) {
const tenantId = Digit.ULBService.getCurrentTenantId();
const [isLoading , setIsLoading] = useState(false);
const selectedProjectType = window.Digit.SessionStorage.get("HCM_CAMPAIGN_MANAGER_FORM_DATA")?.HCM_CAMPAIGN_TYPE?.projectType?.code;
const { isLoading: deliveryConfigLoading, data: filteredDeliveryConfig } = Digit.Hooks.useCustomMDMS(
tenantId,
Expand All @@ -80,14 +81,21 @@ function CycleConfiguration({ onSelect, formData, control, ...props }) {
{
staleTime: 0,
cacheTime: 0,
enabled: true,
enabled: selectedProjectType ? true : false,
select: (data) => {
const temp= getDeliveryConfig({data: data?.["HCM-PROJECT-TYPES"], projectType:selectedProjectType});
return temp;
},
},
{ schemaCode: `${"HCM-PROJECT-TYPES"}.projectTypes` }
);

useEffect(()=>{
if(!filteredDeliveryConfig || !filteredDeliveryConfig?.code){
setIsLoading(true);
}
else setIsLoading(false);
},[filteredDeliveryConfig])
const saved = Digit.SessionStorage.get("HCM_CAMPAIGN_MANAGER_FORM_DATA")?.HCM_CAMPAIGN_CYCLE_CONFIGURE?.cycleConfigure;
const refetch = Digit.SessionStorage.get("HCM_CAMPAIGN_MANAGER_FORM_DATA")?.HCM_CAMPAIGN_CYCLE_CONFIGURE?.cycleConfigure?.cycleConfgureDate
?.refetch;
Expand Down Expand Up @@ -177,6 +185,10 @@ function CycleConfiguration({ onSelect, formData, control, ...props }) {
else setKey(8);
};

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

return (
<>
<div className="container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,33 @@ const SetupCampaign = ({ hierarchyType, hierarchyData }) => {
},
},
});

useEffect(() => {
if (isPreview === "true") {
setIsDraftCreated(true);
setCurrentKey(14);
}
else if (isDraft === "true") {
setIsDraftCreated(true);
if (isSkip === "false") {
if (currentKey === 1) setCurrentKey(1);
} else if (isDateRestricted === "true") {
setCurrentKey(3);
} else {
if(draftData?.additionalDetails?.key === 7 || draftData?.additionalDetails?.key === 8){
setCurrentKey(6);
}
else{
setCurrentKey(draftData?.additionalDetails?.key);
}
}
}
}, [isPreview, isDraft, draftData]);


const getCurrentKey = () => {
const key = Number((/key=([^&]+)/.exec(location.search) || [])[1]);
setCurrentKey(key);
setCurrentKey(key);
};

useEffect(() => {
Expand All @@ -122,29 +146,8 @@ const SetupCampaign = ({ hierarchyType, hierarchyData }) => {
}
}, [fetchUpload, fetchBoundary]);

useEffect(() => {
if (isPreview === "true") {
setIsDraftCreated(true);
setCurrentKey(14);
return;
}
if (isDraft === "true") {
setIsDraftCreated(true);
if (isSkip === "false") {
currentKey !== 1 ? null : setCurrentKey(1);
} else {
if (isDateRestricted === "true") {
setCurrentKey(3);
} else if (draftData?.additionalDetails?.key) {
setCurrentKey(draftData?.additionalDetails?.key);
} else {
console.warn("No valid key found in draftData");
setCurrentKey(1); // Fallback to initial key
}
}
return;
}
}, [isPreview, isDraft, draftData]);



useEffect(() => {
setTotalFormData(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const getDeliveryConfig = ({ data, projectType }) => {
const generateMRDNConfig = (data) => {

return data?.deliveries?.map(delivery => {
const conditionConfig = delivery.doseCriteria.map(dose => {
const conditionConfig = delivery.doseCriteria.map((dose, index) => {
const productConfig = dose.ProductVariants.map(variant => ({
key: 1,
name: variant.name,
Expand Down Expand Up @@ -132,7 +132,7 @@ const generateMRDNConfig = (data) => {
deliveryType: delivery.deliveryStrategy,
productConfig,
attributeConfig: attributeConfigs, // Use the array of attributeConfigs
disableDeliveryType: true
disableDeliveryType: index === 0
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* This file contains all the utils or helpers required for create campaign and drafts
*/

// import { cloneDeep } from "lodash";
import cloneDeep from 'lodash/cloneDeep';

export const cycleDataRemap=(data)=> {
if (!data) return null;
const uniqueCycleObjects = Object.values(
Expand Down Expand Up @@ -32,11 +35,7 @@ export const cycleDataRemap=(data)=> {
return operatorMapping[operator] || ""; // Default to empty if not found
}
export const restructureData=(data, cycleData, DeliveryConfig, projectType)=> {
const deliveryConfig = DeliveryConfig?.find((e) => e.code === String(projectType));
if (deliveryConfig) {
delete deliveryConfig.cycles;
delete deliveryConfig.resources;
}
const deliveryConfig = cloneDeep(DeliveryConfig?.find(e => e.code === String(projectType)));

const resourcesMap = new Map();
const ageInfo = { maxAge: -Infinity, minAge: Infinity };
Expand Down Expand Up @@ -125,7 +124,7 @@ export const cycleDataRemap=(data)=> {
return [{
ruleKey: ruleKey + 1,
delivery: {},
deliveryStrategy: deliveryStrategy,
deliveryType: deliveryStrategy || "DIRECT",
products,
attributes,
}];;
Expand All @@ -141,7 +140,7 @@ export const cycleDataRemap=(data)=> {
return deliveries?.map((delivery, deliveryIndex) => ({
active: deliveryIndex === 0,
deliveryIndex: String(deliveryIndex + 1),
deliveryStrategy: delivery.deliveryStrategy || "DIRECT",
deliveryType: delivery.deliveryStrategy || "DIRECT",
deliveryRules: mapDoseCriteriaToDeliveryRules(delivery.doseCriteria , delivery.deliveryStrategy),
}));
};
Expand All @@ -162,7 +161,7 @@ export const cycleDataRemap=(data)=> {

return {
id: parseInt(delivery.deliveryIndex, 10),
deliveryStrategy: delivery.deliveryStrategy || "DIRECT",
deliveryType: delivery.deliveryStrategy || "DIRECT",
mandatoryWaitSinceLastDeliveryInDays: null,
doseCriteria: delivery.deliveryRules.map(rule => {
const doseCriteriaResult = processDoseCriteria(rule, resourcesMap);
Expand Down

0 comments on commit f07aa9d

Please sign in to comment.