Skip to content

Commit

Permalink
delivery new changes, toast fix, error fix (#716)
Browse files Browse the repository at this point in the history
* delivery new changes, toast fix, error fix

* new fixes

* fixes

* change text component to field component

* added hierarchy

* fix

* fix

* fix

* fix

* passing hierarchy from props

---------

Co-authored-by: nabeelmd-eGov <[email protected]>
  • Loading branch information
nabeelmd-eGov and nabeelmd-eGov committed May 29, 2024
1 parent 1df27df commit 613906d
Show file tree
Hide file tree
Showing 14 changed files with 415 additions and 184 deletions.
2 changes: 1 addition & 1 deletion micro-ui/web/micro-ui-internals/example/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />

<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].44-campaign/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].45-campaign/dist/index.css" />
<!-- added below css for hcm-workbench module inclusion-->

<!-- <link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" /> -->
Expand Down
2 changes: 1 addition & 1 deletion micro-ui/web/micro-ui-internals/packages/css/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egovernments/digit-ui-css",
"version": "1.0.44-campaign",
"version": "1.0.45-campaign",
"license": "MIT",
"main": "dist/index.css",
"author": "Jagankumar <[email protected]>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,26 @@ input[type="date"]::-webkit-calendar-picker-indicator {
}
}
}

.digit-toast-success {
max-width: 90%;
margin-left: auto;
margin-right: auto;
height: auto;
.toast-label {
line-height: 1.5;
word-break: break-word;
height: auto;
white-space: unset;
}
}

.digit-dropdown-select.error {
border: 1px solid #d4351c;
}
.campaign-type-wrapper {
.digit-error-icon-message-wrap {
margin-top: 4px;
font-size: 14px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,21 @@ import CycleDataPreview from "./components/CycleDataPreview";
import { ErrorBoundary } from "@egovernments/digit-ui-components";
import CampaignResourceDocuments from "./components/CampaignResourceDocuments";

export const BOUNDARY_HIERARCHY_TYPE="ADMIN";
/**
* The CampaignModule function fetches store data based on state code, module code, and language, and
* renders the EmployeeApp component within a TourProvider component if the data is not loading.
* @returns The CampaignModule component returns either a Loader component if data is still loading, or
* a TourProvider component wrapping an EmployeeApp component with specific props passed to it.
*/
const CampaignModule = ({ stateCode, userType, tenants }) => {
const tenantId = Digit.ULBService.getCurrentTenantId();
const { data: BOUNDARY_HIERARCHY_TYPE } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "hierarchyConfig" }], {
select: (data) => {
return data?.["HCM-ADMIN-CONSOLE"]?.hierarchyConfig?.[0]?.hierarchy;
},
});

const moduleCode = ["campaignmanager", "workbench", "mdms", "schema","hcm-admin-schemas",`boundary-${BOUNDARY_HIERARCHY_TYPE}`];
const moduleCode = ["campaignmanager", "workbench", "mdms", "schema", "hcm-admin-schemas", `boundary-${BOUNDARY_HIERARCHY_TYPE}`];
const { path, url } = useRouteMatch();
const language = Digit.StoreData.getCurrentLanguage();
const { isLoading, data: store } = Digit.Services.useStore({
Expand All @@ -50,7 +55,7 @@ const CampaignModule = ({ stateCode, userType, tenants }) => {
return (
<ErrorBoundary moduleName="CAMPAIGN">
<TourProvider>
<EmployeeApp path={path} stateCode={stateCode} url={url} userType={userType} />
<EmployeeApp BOUNDARY_HIERARCHY_TYPE={BOUNDARY_HIERARCHY_TYPE} path={path} stateCode={stateCode} url={url} userType={userType} />
</TourProvider>
</ErrorBoundary>
);
Expand All @@ -76,7 +81,7 @@ const componentsToRegister = {
AddProduct,
AddProductField,
CycleDataPreview,
CampaignResourceDocuments
CampaignResourceDocuments,
};

const overrideHooks = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from "react";
import { DatePicker, LabelFieldPair, Header } from "@egovernments/digit-ui-react-components";
import { useTranslation } from "react-i18next";
import { TextInput } from "@egovernments/digit-ui-components";
import { ErrorMessage, FieldV1, TextInput } from "@egovernments/digit-ui-components";

const CampaignDates = ({ onSelect, formData, ...props }) => {
const { t } = useTranslation();
Expand All @@ -14,6 +14,8 @@ const CampaignDates = ({ onSelect, formData, ...props }) => {
const [startDate, setStartDate] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_DATE?.campaignDates?.startDate); // Set default start date to today
const [endDate, setEndDate] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_DATE?.campaignDates?.endDate); // Default end date
const [executionCount, setExecutionCount] = useState(0);
const [error, setError] = useState(null);
const [startValidation, setStartValidation] = useState(null);

useEffect(() => {
setDates({
Expand All @@ -23,18 +25,39 @@ const CampaignDates = ({ onSelect, formData, ...props }) => {
setStartDate(props?.props?.sessionData?.HCM_CAMPAIGN_DATE?.campaignDates?.startDate);
setEndDate(props?.props?.sessionData?.HCM_CAMPAIGN_DATE?.campaignDates?.endDate);
}, [props?.props?.sessionData?.HCM_CAMPAIGN_DATE?.campaignDates]);


useEffect(() => {
if (props?.props?.isSubmitting && !endDate && !startDate) {
setError({ startDate: "CAMPAIGN_FIELD_MANDATORY", endDate: "CAMPAIGN_FIELD_MANDATORY" });
} else if (props?.props?.isSubmitting && !startDate) {
setError({ startDate: "CAMPAIGN_FIELD_MANDATORY" });
} else if (props?.props?.isSubmitting && !endDate) {
setError({ endDate: "CAMPAIGN_FIELD_MANDATORY" });
} else if (!props?.props?.isSubmitting) {
setError(null);
}
}, [props?.props?.isSubmitting]);
useEffect(() => {
onSelect("campaignDates", { startDate: startDate, endDate: endDate });
if (!startDate && startValidation) {
setError({ startDate: "CAMPAIGN_START_DATE_ERROR" });
} else if (!endDate && startValidation) {
setError({ endDate: "CAMPAIGN_END_DATE_ERROR" });
} else if (new Date(endDate).getTime() < new Date(startDate).getTime() && startValidation) {
setError({ endDate: "CAMPAIGN_END_DATE_BEFORE_ERROR" });
onSelect("campaignDates", { startDate: startDate, endDate: endDate });
} else if (startDate || endDate) {
setError(null);
onSelect("campaignDates", { startDate: startDate, endDate: endDate });
}
}, [startDate, endDate]);

useEffect(() => {
if (executionCount < 5) {
onSelect("campaignDates", { startDate: startDate, endDate: endDate });
setExecutionCount(prevCount => prevCount + 1);
setExecutionCount((prevCount) => prevCount + 1);
}
});

function setStart(value) {
setStartDate(value);
}
Expand All @@ -53,19 +76,39 @@ const CampaignDates = ({ onSelect, formData, ...props }) => {
<span className="mandatory-date">*</span>
</div>
<div className="date-field-container">
<TextInput
<FieldV1
error={error?.startDate ? t(error?.startDate) : ""}
withoutLabel={true}
type="date"
value={startDate}
placeholder={t("HCM_START_DATE")}
populators={{
validation: {
min: Digit.Utils.date.getDate(Date.now() + ONE_DAY_IN_MS),
},
}}
min={Digit.Utils.date.getDate(Date.now() + ONE_DAY_IN_MS)}
onChange={(d) => setStart(d)}
onChange={(d) => {
setStartValidation(true);
setStart(d);
}}
/>
<TextInput
<FieldV1
error={error?.endDate ? t(error?.endDate) : ""}
withoutLabel={true}
type="date"
value={endDate}
placeholder={t("HCM_END_DATE")}
populators={{
validation: {
min: Digit.Utils.date.getDate(Date.now() + 2 * ONE_DAY_IN_MS),
},
}}
min={Digit.Utils.date.getDate(Date.now() + 2 * ONE_DAY_IN_MS)}
onChange={(d) => setEnd(d)}
onChange={(d) => {
setStartValidation(true);
setEnd(d);
}}
/>
</div>
</LabelFieldPair>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import React, { useState, useEffect } from "react";
import { Header, TextInput } from "@egovernments/digit-ui-react-components";
import { Header } from "@egovernments/digit-ui-react-components";
import { useTranslation } from "react-i18next";
import { LabelFieldPair } from "@egovernments/digit-ui-react-components";
import { ErrorMessage, FieldV1 } from "@egovernments/digit-ui-components";

const CampaignName = ({ onSelect, formData, control, ...props }) => {
const CampaignName = ({ onSelect, formData, control, formState, ...props }) => {
const { t } = useTranslation();
const [name, setName] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_NAME?.campaignName || null);
const [name, setName] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_NAME?.campaignName || "");
const [executionCount, setExecutionCount] = useState(0);

const [startValidation, setStartValidation] = useState(null);
const [error, setError] = useState(null);
useEffect(() => {
setName(props?.props?.sessionData?.HCM_CAMPAIGN_NAME?.campaignName);
}, [props?.props?.sessionData?.HCM_CAMPAIGN_NAME]);

useEffect(() => {
onSelect("campaignName", name);
if (props?.props?.isSubmitting && !name) {
setError({ message: "CAMPAIGN_FIELD_ERROR_MANDATORY" });
} else {
setError(null);
}
}, [props?.props?.isSubmitting]);
useEffect(() => {
if (startValidation && !name) {
setError({ message: "CAMPAIGN_NAME_FIELD_ERROR" });
} else if (name) {
setError(null);
onSelect("campaignName", name);
}
}, [name, props?.props?.sessionData?.HCM_CAMPAIGN_NAME?.campaignName]);

useEffect(() => {
Expand All @@ -32,7 +46,17 @@ const CampaignName = ({ onSelect, formData, control, ...props }) => {
<span>{`${t("HCM_CAMPAIGN_NAME")}`}</span>
<span className="mandatory-span">*</span>
</div>
<TextInput style={{ width: "40rem", marginBottom: "0" }} name="campaignName" value={name} onChange={(event) => setName(event.target.value)} />
<FieldV1
type="text"
error={error?.message ? t(error?.message) : ""}
style={{ width: "40rem", marginBottom: "0" }}
populators={{ name: "campaignName" }}
value={name}
onChange={(event) => {
setStartValidation(true);
setName(event.target.value);
}}
/>
</LabelFieldPair>
</React.Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@ import React, { useState, useMemo, useRef, useEffect } from "react";
import { UploadIcon, FileIcon, DeleteIconv2, Toast, Card, Header } from "@egovernments/digit-ui-react-components";
import { useTranslation } from "react-i18next";
import { LabelFieldPair } from "@egovernments/digit-ui-react-components";
import { Dropdown } from "@egovernments/digit-ui-components";
import { Dropdown, ErrorMessage } from "@egovernments/digit-ui-components";

const CampaignSelection = ({ onSelect, formData, ...props }) => {
const CampaignSelection = ({ onSelect, formData, formState, ...props }) => {
const { t } = useTranslation();
const tenantId = Digit.ULBService.getStateId();
const { isLoading, data: projectType } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-PROJECT-TYPES", [{ name: "projectTypes" }]);
const [type, setType] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType || {});
const [beneficiaryType, setBeneficiaryType] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType?.beneficiaryType || "");
const [showBeneficiary, setShowBeneficiaryType] = useState(Boolean(props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType?.beneficiaryType));
const [executionCount, setExecutionCount] = useState(0);
const [error, setError] = useState(null);
const [startValidation, setStartValidation] = useState(null);

useEffect(() => {
if (props?.props?.isSubmitting && !type) {
setError({ message: "CAMPAIGN_FIELD_MANDATORY" });
}
}, [props?.props?.isSubmitting]);
useEffect(() => {
setType(props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType);
setBeneficiaryType(props?.props?.sessionData?.HCM_CAMPAIGN_TYPE?.projectType?.beneficiaryType);
Expand All @@ -26,7 +33,12 @@ const CampaignSelection = ({ onSelect, formData, ...props }) => {
};

useEffect(() => {
onSelect("projectType", type);
if (!type && startValidation) {
setError({ message: "CAMPAIGN_FIELD_MANDATORY" });
} else {
setError(null);
onSelect("projectType", type);
}
}, [type]);

useEffect(() => {
Expand All @@ -44,16 +56,21 @@ const CampaignSelection = ({ onSelect, formData, ...props }) => {
<span>{`${t("HCM_CAMPAIGN_TYPE")}`}</span>
<span className="mandatory-span">*</span>
</div>
<Dropdown
style={{ width: "40rem" , paddingBottom: "1rem" }}
t={t}
option={projectType?.["HCM-PROJECT-TYPES"]?.projectTypes}
optionKey={"code"}
selected={type}
select={(value) => {
handleChange(value);
}}
/>
<div className="campaign-type-wrapper">
<Dropdown
style={{ width: "40rem", paddingBottom: "1rem" }}
variant={error ? "error" : ""}
t={t}
option={projectType?.["HCM-PROJECT-TYPES"]?.projectTypes}
optionKey={"code"}
selected={type}
select={(value) => {
setStartValidation(true);
handleChange(value);
}}
/>
{error?.message && <ErrorMessage wrapperStyles={{ marginTop: "-10px" }} message={t(error?.message)} showIcon={true} />}
</div>
</LabelFieldPair>
{showBeneficiary && (
<LabelFieldPair>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const CampaignConfig = (totalFormData, dataParams) => {
export const CampaignConfig = (totalFormData, dataParams, isSubmitting) => {
return [
{
form: [
Expand All @@ -18,6 +18,7 @@ export const CampaignConfig = (totalFormData, dataParams) => {
customProps: {
module: "HCM",
sessionData: totalFormData,
isSubmitting: isSubmitting
},
populators: {
name: "projectType",
Expand All @@ -41,6 +42,7 @@ export const CampaignConfig = (totalFormData, dataParams) => {
customProps: {
module: "HCM",
sessionData: totalFormData,
isSubmitting: isSubmitting
},
populators: {
name: "campaignName",
Expand All @@ -64,6 +66,7 @@ export const CampaignConfig = (totalFormData, dataParams) => {
customProps: {
module: "HCM",
sessionData: totalFormData,
isSubmitting: isSubmitting
},
populators: {
name: "campaignDates",
Expand Down
Loading

0 comments on commit 613906d

Please sign in to comment.