Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdms integration fixes #456

Merged
merged 2 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ import { AddIcon, Button, Card, CardText, Dropdown, Header, TextInput } from "@e
import { useTranslation } from "react-i18next";
import { LabelFieldPair } from "@egovernments/digit-ui-react-components";
import { DustbinIcon } from "./icons/DustbinIcon";
import { productType } from "../configs/productType";
// import { productType } from "../configs/productType";
import { PRIMARY_COLOR } from "../utils";

const AddProductField = ({ onSelect }) => {
const { t } = useTranslation();
const tenantId = Digit.ULBService.getCurrentTenantId();
const { isLoading: productTypeLoading, data: productType } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "productType" }], {
select: (data) => {
return data?.["HCM-ADMIN-CONSOLE"]?.productType;
},
});
const [productFieldData, setProductFieldData] = useState([{ key: 1, name: null, type: null, variant: null }]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//migrated to mdms
export const attributeConfig = [
{
key: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//migrated to mdms
export const deliveryConfig = [
{
projectType: "LLIN-mz",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//migrated to mdms
export const operatorConfig = [
{
key: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//migrated to mdms
export const productType = [
{
key: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Loader, FormComposerV2, Header, Toast } from "@egovernments/digit-ui-react-components";
import { Loader, FormComposerV2, Header } from "@egovernments/digit-ui-react-components";
import React, { useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { useHistory, useLocation } from "react-router-dom";
import { addProductConfig } from "../../configs/addProductConfig";
import { Toast } from "@egovernments/digit-ui-components";

function AddProduct() {
const { t } = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
import { SVG } from "@egovernments/digit-ui-react-components";
import React, { Fragment, useContext, useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { attributeConfig } from "../../../configs/attributeConfig";
import { operatorConfig } from "../../../configs/operatorConfig";
// import { attributeConfig } from "../../../configs/attributeConfig";
// import { operatorConfig } from "../../../configs/operatorConfig";
import RemoveableTagNew from "../../../components/RemovableTagNew";
import AddProducts from "./AddProductscontext";
import { CycleContext } from ".";
Expand All @@ -37,7 +37,18 @@ const makeSequential = (jsonArray, keyName) => {
}));
};

const AddAttributeField = ({ deliveryRuleIndex, delivery, deliveryRules, setDeliveryRules, attribute, setAttributes, index, onDelete }) => {
const AddAttributeField = ({
deliveryRuleIndex,
delivery,
deliveryRules,
setDeliveryRules,
attribute,
setAttributes,
index,
onDelete,
attributeConfig,
operatorConfig,
}) => {
const [val, setVal] = useState("");
const [showAttribute, setShowAttribute] = useState(null);
const [showOperator, setShowOperator] = useState(null);
Expand Down Expand Up @@ -272,6 +283,7 @@ const AddCustomAttributeField = ({
setAttributes,
index,
onDelete,
operatorConfig,
}) => {
const [val, setVal] = useState("");
const [showAttribute, setShowAttribute] = useState(null);
Expand Down Expand Up @@ -449,7 +461,27 @@ const AddCustomAttributeField = ({
const AddAttributeWrapper = ({ deliveryRuleIndex, delivery, deliveryRules, setDeliveryRules, index, key }) => {
const { campaignData, dispatchCampaignData, filteredDeliveryConfig } = useContext(CycleContext);
const { t } = useTranslation();

const tenantId = Digit.ULBService.getCurrentTenantId();
const { isLoading: attributeConfigLoading, data: attributeConfig } = Digit.Hooks.useCustomMDMS(
tenantId,
"HCM-ADMIN-CONSOLE",
[{ name: "attributeConfig" }],
{
select: (data) => {
return data?.["HCM-ADMIN-CONSOLE"]?.attributeConfig;
},
}
);
const { isLoading: operatorConfigLoading, data: operatorConfig } = Digit.Hooks.useCustomMDMS(
tenantId,
"HCM-ADMIN-CONSOLE",
[{ name: "operatorConfig" }],
{
select: (data) => {
return data?.["HCM-ADMIN-CONSOLE"]?.operatorConfig;
},
}
);
const [attributes, setAttributes] = useState([{ key: 1, deliveryRuleIndex, attribute: "", operator: "", value: "" }]);
const reviseIndexKeys = () => {
setAttributes((prev) => prev.map((unit, index) => ({ ...unit, key: index + 1 })));
Expand Down Expand Up @@ -503,6 +535,7 @@ const AddAttributeWrapper = ({ deliveryRuleIndex, delivery, deliveryRules, setDe
key={index}
index={index}
onDelete={() => deleteAttribute(item, deliveryRuleIndex)}
operatorConfig={operatorConfig}
/>
))
: delivery.attributes.map((item, index) => (
Expand All @@ -516,9 +549,11 @@ const AddAttributeWrapper = ({ deliveryRuleIndex, delivery, deliveryRules, setDe
key={index}
index={index}
onDelete={() => deleteAttribute(item, deliveryRuleIndex)}
attributeConfig={attributeConfig}
operatorConfig={operatorConfig}
/>
))}
{!filteredDeliveryConfig?.attrAddDisable && delivery.attributes.length !== attributeConfig.length && (
{!filteredDeliveryConfig?.attrAddDisable && delivery.attributes.length !== attributeConfig?.length && (
<Button
variation="secondary"
label={t(`CAMPAIGN_ADD_MORE_ATTRIBUTE_TEXT`)}
Expand Down Expand Up @@ -586,7 +621,7 @@ const AddDeliveryRule = ({ targetedData, deliveryRules, setDeliveryRules, index,
{deliveryRules.length !== 1 && (
<div
onClick={() => onDelete()}
style={{ fontWeight: "600", fontSize: "1rem", color:PRIMARY_COLOR, display: "flex", gap: "0.5rem", alignItems: "center" }}
style={{ fontWeight: "600", fontSize: "1rem", color: PRIMARY_COLOR, display: "flex", gap: "0.5rem", alignItems: "center" }}
>
<DustbinIcon /> {t(`CAMPAIGN_DELETE_CONDITION_LABEL`)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { createContext, useContext, useEffect, useReducer, useState } from "react";
import MultiTab from "./MultiTabcontext";
import { deliveryConfig } from "../../../configs/deliveryConfig";
import { Loader } from "@egovernments/digit-ui-react-components";
// import { deliveryConfig } from "../../../configs/deliveryConfig";

const CycleContext = createContext();

Expand All @@ -16,7 +17,27 @@ function DeliverySetup({ onSelect, config, formData, control, tabCount = 2, subT
const [cycleData, setCycleData] = useState(config?.customProps?.sessionData?.["HCM_CAMPAIGN_CYCLE_CONFIGURE"]?.cycleConfigure);
const saved = window.Digit.SessionStorage.get("HCM_CAMPAIGN_MANAGER_FORM_DATA")?.HCM_CAMPAIGN_DELIVERY_DATA?.deliveryRule;
const selectedProjectType = window.Digit.SessionStorage.get("HCM_CAMPAIGN_MANAGER_FORM_DATA")?.HCM_CAMPAIGN_TYPE?.projectType?.code;
const filteredDeliveryConfig = deliveryConfig.find((i) => i.projectType === selectedProjectType);
const tenantId = Digit.ULBService.getCurrentTenantId();
const { isLoading: deliveryConfigLoading, data: filteredDeliveryConfig } = Digit.Hooks.useCustomMDMS(
tenantId,
"HCM-ADMIN-CONSOLE",
[{ name: "deliveryConfig" }],
{
select: (data) => {
// return data?.["HCM-ADMIN-CONSOLE"]?.deliveryConfig;
const temp = data?.["HCM-ADMIN-CONSOLE"]?.deliveryConfig;
return temp?.find((i) => i?.projectType === selectedProjectType);
},
}
);
// const [filteredDeliveryConfig, setFilteredDeliveryConfig] = useState(deliveryConfig?.find((i) => i?.projectType === selectedProjectType));
// useEffect(() => {
// if (!deliveryConfigLoading) {
// const temp = deliveryConfig?.find((i) => i?.projectType === selectedProjectType);
// setFilteredDeliveryConfig(temp);
// }
// }, [deliveryConfigLoading, filteredDeliveryConfig]);
// const filteredDeliveryConfig = deliveryConfig.find((i) => i.projectType === selectedProjectType);
useEffect(() => {
setCycleData(config?.customProps?.sessionData?.["HCM_CAMPAIGN_CYCLE_CONFIGURE"]?.cycleConfigure);
}, [config?.customProps?.sessionData?.["HCM_CAMPAIGN_CYCLE_CONFIGURE"]?.cycleConfigure]);
Expand Down Expand Up @@ -194,7 +215,7 @@ function DeliverySetup({ onSelect, config, formData, control, tabCount = 2, subT
cycle: cycleData?.cycleConfgureDate?.cycle,
deliveries: cycleData?.cycleConfgureDate?.deliveries,
});
}, [cycleData]);
}, [cycleData, filteredDeliveryConfig, deliveryConfigLoading]);

useEffect(() => {
onSelect("deliveryRule", campaignData);
Expand All @@ -206,6 +227,9 @@ function DeliverySetup({ onSelect, config, formData, control, tabCount = 2, subT
}
});

if (deliveryConfigLoading) {
return <Loader />;
}
return (
<CycleContext.Provider
value={{
Expand Down
Loading