Skip to content

Commit

Permalink
HLM 6210: Toast, error focus fix and project type reset delivery data…
Browse files Browse the repository at this point in the history
… fix (#854)

* HLM-6210: campaign type change reset delivery data fix, summary error focus fix

* summary error focus fix

---------

Co-authored-by: nabeelmd-eGov <[email protected]>
  • Loading branch information
nabeelmd-eGov and nabeelmd-eGov authored Jun 12, 2024
1 parent 6002800 commit c442ba4
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion micro-ui/web/micro-ui-internals/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@egovernments/digit-ui-components": "0.0.2-beta.1",
"@egovernments/digit-ui-module-core": "1.8.2-beta.2",
"@egovernments/digit-ui-module-utilities": "1.0.1-beta.30",
"@egovernments/digit-ui-react-components": "1.8.2-beta.3",
"@egovernments/digit-ui-react-components": "1.8.2-beta.6",
"@egovernments/digit-ui-module-hcmworkbench":"0.0.38",
"@egovernments/digit-ui-module-campaign-manager": "0.0.1",
"http-proxy-middleware": "^1.0.5",
Expand Down
2 changes: 1 addition & 1 deletion micro-ui/web/micro-ui-internals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"ajv": "8.12.0",
"lodash": "4.17.21",
"microbundle-crl": "0.13.11",
"@egovernments/digit-ui-react-components": "1.8.2-beta.3",
"@egovernments/digit-ui-react-components": "1.8.2-beta.6",
"@egovernments/digit-ui-components": "0.0.2-beta.1",
"react": "17.0.2",
"react-dom": "17.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react-router-dom": "5.3.0"
},
"dependencies": {
"@egovernments/digit-ui-react-components": "1.8.2-beta.3",
"@egovernments/digit-ui-react-components": "1.8.2-beta.6",
"@egovernments/digit-ui-components": "0.0.2-beta.1",
"@rjsf/core": "5.10.0",
"@rjsf/utils": "5.10.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ const CampaignSummary = (props) => {
// data?.[0]?.resources?.find((i) => i?.type === "boundaryWithTarget") ?
{
name: "target",
errorName: "target",
sections: [
{
name: "target",
Expand All @@ -277,6 +278,7 @@ const CampaignSummary = (props) => {
// data?.[0]?.resources?.find((i) => i?.type === "facility") ?
{
name: "facility",
errorName: "facility",
sections: [
{
name: "facility",
Expand All @@ -299,6 +301,7 @@ const CampaignSummary = (props) => {
// data?.[0]?.resources?.find((i) => i?.type === "user") ?
{
name: "user",
errorName: "user",
sections: [
{
name: "user",
Expand Down Expand Up @@ -348,13 +351,15 @@ const CampaignSummary = (props) => {
values: [
{
key: "CAMPAIGN_NO_OF_CYCLES",
value: data?.[0]?.deliveryRules
value:
data?.[0]?.deliveryRules && data?.[0]?.deliveryRules.map((item) => item.cycleNumber)?.length > 0
? Math.max(...data?.[0]?.deliveryRules.map((item) => item.cycleNumber))
: t("CAMPAIGN_SUMMARY_NA"),
},
{
key: "CAMPAIGN_NO_OF_DELIVERIES",
value: data?.[0]?.deliveryRules
value:
data?.[0]?.deliveryRules && data?.[0]?.deliveryRules.map((item) => item.deliveryNumber)?.length > 0
? Math.max(...data?.[0]?.deliveryRules.map((item) => item.deliveryNumber))
: t("CAMPAIGN_SUMMARY_NA"),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,6 @@ const SetupCampaign = ({ hierarchyType }) => {
};
if (totalFormData?.HCM_CAMPAIGN_DELIVERY_DATA?.deliveryRule) {
const temp = restructureData(totalFormData?.HCM_CAMPAIGN_DELIVERY_DATA?.deliveryRule);

payloadData.deliveryRules = temp;
}

Expand Down Expand Up @@ -709,10 +708,14 @@ const SetupCampaign = ({ hierarchyType }) => {
};
if (totalFormData?.HCM_CAMPAIGN_CYCLE_CONFIGURE?.cycleConfigure) {
payloadData.additionalDetails.cycleData = totalFormData?.HCM_CAMPAIGN_CYCLE_CONFIGURE?.cycleConfigure;
} else {
payloadData.additionalDetails.cycleData = {};
}
if (totalFormData?.HCM_CAMPAIGN_DELIVERY_DATA?.deliveryRule) {
const temp = restructureData(totalFormData?.HCM_CAMPAIGN_DELIVERY_DATA?.deliveryRule);
payloadData.deliveryRules = temp;
} else {
payloadData.deliveryRules = [];
}
if (!payloadData?.startDate && !payloadData?.endDate) {
delete payloadData?.startDate;
Expand Down Expand Up @@ -750,9 +753,9 @@ const SetupCampaign = ({ hierarchyType }) => {
const cycleData = data.cycleConfigure.cycleData;
let dateError = [];
// Validate cycle and deliveries
if (cycle <= 0 || deliveries <= 0) {
return { error: true, message: "DELIVERY_CYCLE_EMPTY_ERROR" };
}
// if (cycle <= 0 || deliveries <= 0) {
// return { error: true, message: "DELIVERY_CYCLE_EMPTY_ERROR" };
// }

[...Array(cycle)].forEach((item, index) => {
const check = cycleData?.find((i) => i?.key === index + 1);
Expand All @@ -767,30 +770,31 @@ const SetupCampaign = ({ hierarchyType }) => {
});
}
});
setSummaryErrors((prev) => {
return {
...prev,
deliveryErrors: prev?.deliveryErrors ? [...prev.deliveryErrors, ...dateError] : [...dateError],
};
});
// setSummaryErrors((prev) => {
// return {
// ...prev,
// deliveryErrors: prev?.deliveryErrors ? [...prev.deliveryErrors, ...dateError] : [...dateError],
// };
// });
// Validate cycleData length
if (cycleData.length !== cycle) {
return { error: true, message: "DELIVERY_CYCLE_MISMATCH_LENGTH_ERROR" };
}
// if (cycleData.length !== cycle) {
// return { error: true, message: "DELIVERY_CYCLE_MISMATCH_LENGTH_ERROR" };
// }

// Validate fromDate and startDate in cycleData
for (const item of cycleData) {
if (!item.fromDate || !item.toDate) {
return { error: true, message: "DELIVERY_CYCLE_DATE_ERROR" };
}
}
// for (const item of cycleData) {
// if (!item.fromDate || !item.toDate) {
// return { error: true, message: "DELIVERY_CYCLE_DATE_ERROR" };
// }
// }

return false;
return dateError;
}

function validateDeliveryRules(data, projectType) {
function validateDeliveryRules(data, projectType, cycleConfigureData) {
let isValid = true;
let deliveryRulesError = [];
let dateError = validateCycleData(cycleConfigureData);

// Iterate over deliveryRule array
data.deliveryRule.forEach((cycle) => {
Expand Down Expand Up @@ -878,7 +882,7 @@ const SetupCampaign = ({ hierarchyType }) => {
setSummaryErrors((prev) => {
return {
...prev,
deliveryErrors: prev?.deliveryErrors ? [...prev.deliveryErrors, ...deliveryRulesError] : deliveryRulesError,
deliveryErrors: [...deliveryRulesError, ...dateError],
};
});
return isValid;
Expand Down Expand Up @@ -1112,7 +1116,11 @@ const SetupCampaign = ({ hierarchyType }) => {
const cycleConfigureData = totalFormData?.HCM_CAMPAIGN_CYCLE_CONFIGURE;
const isCycleError = validateCycleData(cycleConfigureData);
const deliveryCycleData = totalFormData?.HCM_CAMPAIGN_DELIVERY_DATA;
const isDeliveryError = validateDeliveryRules(deliveryCycleData, totalFormData?.["HCM_CAMPAIGN_TYPE"]?.projectType?.code?.toUpperCase());
const isDeliveryError = validateDeliveryRules(
deliveryCycleData,
totalFormData?.["HCM_CAMPAIGN_TYPE"]?.projectType?.code?.toUpperCase(),
cycleConfigureData
);
const isTargetError = totalFormData?.HCM_CAMPAIGN_UPLOAD_BOUNDARY_DATA?.uploadBoundary?.uploadedFile?.[0]?.filestoreId
? false
: (setSummaryErrors((prev) => {
Expand Down
2 changes: 1 addition & 1 deletion micro-ui/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@egovernments/digit-ui-module-workbench": "1.0.1-beta.16",
"@egovernments/digit-ui-module-core": "1.8.2-beta.2",
"@egovernments/digit-ui-module-hrms": "1.8.0-beta.2",
"@egovernments/digit-ui-react-components": "1.8.2-beta.3",
"@egovernments/digit-ui-react-components": "1.8.2-beta.6",
"@egovernments/digit-ui-components": "0.0.2-beta.1",
"@egovernments/digit-ui-module-dss": "1.8.0-beta",
"@egovernments/digit-ui-module-common": "1.8.0-beta",
Expand Down
2 changes: 1 addition & 1 deletion micro-ui/web/workbench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@egovernments/digit-ui-components": "0.0.2-beta.1",
"@egovernments/digit-ui-module-core": "1.8.2-beta.2",
"@egovernments/digit-ui-module-utilities": "1.0.1-beta.30",
"@egovernments/digit-ui-react-components": "1.8.2-beta.3",
"@egovernments/digit-ui-react-components": "1.8.2-beta.6",
"@egovernments/digit-ui-module-hcmworkbench":"0.0.38",
"@egovernments/digit-ui-module-campaign-manager": "0.0.1",
"babel-loader": "8.1.0",
Expand Down

0 comments on commit c442ba4

Please sign in to comment.