{t(`HCM_CAMPAIGN_DATES`)}
*
@@ -76,7 +83,7 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch }) =>
withoutLabel={true}
type="date"
value={startDate}
- nonEditable={today >= startDate ? true : false}
+ nonEditable={startDate?.length > 0 && today > startDate ? true : false}
placeholder={t("HCM_START_DATE")}
populators={
today >= startDate
@@ -97,19 +104,16 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch }) =>
withoutLabel={true}
type="date"
value={endDate}
- nonEditable={today >= endDate ? true : false}
+ nonEditable={endDate?.length > 0 && today > endDate ? true : false}
placeholder={t("HCM_END_DATE")}
- populators={
- today >= endDate
- ? {}
- : {
- validation: {
- min: startDate
- ? Digit.Utils.date.getDate(new Date(startDate).getTime() + 2 * ONE_DAY_IN_MS)
- : Digit.Utils.date.getDate(Date.now() + 2 * ONE_DAY_IN_MS),
- },
- }
- }
+ populators={{
+ validation: {
+ min:
+ startDate >= today
+ ? Digit.Utils.date.getDate(new Date(startDate).getTime() + 2 * ONE_DAY_IN_MS)
+ : Digit.Utils.date.getDate(Date.now() + 2 * ONE_DAY_IN_MS),
+ },
+ }}
onChange={(d) => {
handleDateChange({
date: d,
@@ -131,7 +135,7 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch }) =>
= item?.startDate ? true : false}
+ nonEditable={item?.startDate?.length > 0 && today > item?.startDate ? true : false}
value={item?.startDate}
placeholder={t("HCM_START_DATE")}
populators={
@@ -141,7 +145,8 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch }) =>
validation: {
min:
index > 0
- ? new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime() + 86400000)
+ ? cycleDates?.find((j) => j.cycleIndex == index)?.endDate &&
+ new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime() + 86400000)
?.toISOString()
?.split("T")?.[0]
: startDate,
@@ -161,22 +166,18 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch }) =>
withoutLabel={true}
type="date"
value={item?.endDate}
- nonEditable={today >= item?.endDate && today >= cycleDates?.[index + 1]?.startDate ? true : false}
+ nonEditable={item?.endDate?.length > 0 && today > item?.endDate && today > cycleDates?.[index + 1]?.startDate ? true : false}
placeholder={t("HCM_END_DATE")}
- populators={
- today >= item?.endDate
- ? {}
- : {
- validation: {
- min: cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate
- ? new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime() + 86400000)
- ?.toISOString()
- ?.split("T")?.[0]
- : null,
- max: endDate,
- },
- }
- }
+ populators={{
+ validation: {
+ min: cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate
+ ? new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime() + 86400000)
+ ?.toISOString()
+ ?.split("T")?.[0]
+ : null,
+ max: endDate,
+ },
+ }}
onChange={(d) => {
handleCycleDateChange({
date: d,
diff --git a/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/DateWithBoundary.js b/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/DateWithBoundary.js
index e2b9498cbcc..5c2ba3d6379 100644
--- a/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/DateWithBoundary.js
+++ b/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/DateWithBoundary.js
@@ -2,7 +2,7 @@ import React, { useState, useEffect, Fragment, useReducer, useMemo } from "react
import { useTranslation } from "react-i18next";
import { useLocation } from "react-router-dom";
import { LabelFieldPair, Header } from "@egovernments/digit-ui-react-components";
-import { Button, Card, Dropdown, MultiSelectDropdown } from "@egovernments/digit-ui-components";
+import { Button, Card, Dropdown, MultiSelectDropdown, Toast } from "@egovernments/digit-ui-components";
import BoundaryWithDate from "./BoundaryWithDate";
const initialState = (projectData) => {
@@ -88,6 +88,9 @@ const reducer = (state, action) => {
return item;
});
break;
+ case "DELETE_BOUNDARY":
+ return state.filter((item) => item?.id !== action?.item?.id);
+ break;
default:
return state;
break;
@@ -116,6 +119,7 @@ const DateWithBoundary = ({ onSelect, formData, ...props }) => {
const [targetBoundary, setTargetBoundary] = useState([]);
const [projectData, setProjectData] = useState(null);
const [dateReducer, dateReducerDispatch] = useReducer(reducer, initialState(projectData));
+ const [showToast, setShowToast] = useState(null);
useEffect(() => {
onSelect("dateWithBoundary", dateReducer);
@@ -149,6 +153,10 @@ const DateWithBoundary = ({ onSelect, formData, ...props }) => {
};
const { data: hierarchyDefinition } = Digit.Hooks.useCustomAPIHook(reqCriteria);
+ useEffect(() => {
+ const timer = showToast && setTimeout(() => setShowToast(null), 5000);
+ return () => clearTimeout(timer);
+ }, [showToast]);
//hierarchy level
useEffect(() => {
if (hierarchyDefinition) {
@@ -214,6 +222,9 @@ const DateWithBoundary = ({ onSelect, formData, ...props }) => {
};
const selectBoundary = async () => {
+ if (!targetBoundary || targetBoundary?.length === 0) {
+ setShowToast({ isError: true, label: "SELECT_HIERARCHY_AND_BOUNDARY_ERROR" });
+ }
const temp = await Digit.Hooks.campaign.useProjectSearchWithBoundary({
name: state?.name ? state.name : historyState?.name,
tenantId: tenantId,
@@ -222,6 +233,12 @@ const DateWithBoundary = ({ onSelect, formData, ...props }) => {
setProjectData(temp);
};
+ const onDeleteBoundary = (item, index) => {
+ dateReducerDispatch({
+ type: "DELETE_BOUNDARY",
+ item: item,
+ });
+ };
return (
<>
@@ -269,7 +286,24 @@ const DateWithBoundary = ({ onSelect, formData, ...props }) => {