From ed16dc8de977d3bddfa2952163cf2c1269d5a877 Mon Sep 17 00:00:00 2001 From: suryansh-egov Date: Wed, 16 Oct 2024 12:44:26 +0530 Subject: [PATCH] intial changes new --- .../src/components/CampaignCard.js | 7 + .../src/components/Checkboxes.js | 31 ++- .../src/components/CreateQuestion.js | 28 +- .../src/components/CreateQuestionContext.js | 11 +- .../src/components/Dropdowns.js | 19 +- .../src/components/MultipleChoice.js | 28 +- .../src/configs/checklistCreateConfig.js | 5 +- .../src/pages/employee/ViewChecklist.js | 240 ++++++++++++++++++ .../src/pages/employee/index.js | 3 +- 9 files changed, 326 insertions(+), 46 deletions(-) create mode 100644 health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewChecklist.js diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignCard.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignCard.js index ca8f8c58440..846de98d918 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignCard.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CampaignCard.js @@ -73,6 +73,13 @@ const CampaignCard = () => { link: `/${window?.contextPath}/employee/campaign/boundary-management?defaultHierarchyType=DEFAULTBOUNDARY&hierarchyType=DEMOONCONSOLE`, roles: ROLES.CAMPAIGN_MANAGER, // count: isLoading?"-":data + }, + { + label: t("VIEW_CHECKLIST"), + link: `/${window?.contextPath}/employee/campaign/checklist/view?campaignName=paradigms&role=Distributor&checklistType=Health facility Referral: Drug side effect from previous cycle`, + roles: ROLES.CAMPAIGN_MANAGER, + // count: isLoading?"-":data + } ]; diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/Checkboxes.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/Checkboxes.js index b211bcd94bb..3bf97a1bd0f 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/Checkboxes.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/Checkboxes.js @@ -29,7 +29,9 @@ const Checkboxes = ({ subQinitialQuestionData, addComment, handleOptionComment, + typeOfCall }) => { + let dis = typeOfCall==="view"?true:false; return (
{options.map((item, index) => ( @@ -55,9 +57,11 @@ const Checkboxes = ({ t={t} addComment={addComment} handleOptionComment={handleOptionComment} + typeOfCall={typeOfCall} /> {item.optionComment && ))} -
+ {!dis &&
*/} -
+
}
); }; @@ -129,9 +125,11 @@ const CheckBoxOption = ({ t, optionComment, addComment, - handleOptionComment + handleOptionComment, + typeOfCall }) => { const [isFocused, setIsFocused] = useState(false); + let dis = typeOfCall==="view"?true:false; // useEffect(() => { // updateOption({ value: optionTitle, id: index }); @@ -141,8 +139,9 @@ const CheckBoxOption = ({
- + setIsFocused(false)} onFocus={() => setIsFocused(true)} className={isFocused ? "simple_editable-input" : "simple_readonly-input"} - maxLength={maxLength} + // maxLength={maxLength} title={titleHover} style={{ ...labelstyle }} - disabled={isPartiallyEnabled ? !isPartiallyEnabled : formDisabled} + // disabled={isPartiallyEnabled ? !isPartiallyEnabled : formDisabled} />
- { + {!dis && <> } */} - {!disableDelete && ( + {!dis && !disableDelete && ( //
removeOption(index)}> // // {t(`CAMPAIGN_DELETE_ROW_TEXT`)} diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestion.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestion.js index d58c51750a8..89ffe1e316a 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestion.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestion.js @@ -18,6 +18,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field subQparent, subQparentId, subQinitialQuestionData, + typeOfCall }) => { const [options, setOptions] = useState(() => { @@ -169,6 +170,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field subQparent={subQparent} subQparentId={subQparentId} subQinitialQuestionData={subQinitialQuestionData} + typeOfCall={typeOfCall} /> ); break; @@ -192,6 +194,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field subQparent={subQparent} subQparentId={subQparentId} subQinitialQuestionData={subQinitialQuestionData} + typeOfCall={typeOfCall} /> ); break; @@ -215,6 +218,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field subQparent={subQparent} subQparentId={subQparentId} subQinitialQuestionData={subQinitialQuestionData} + typeOfCall={typeOfCall} /> ); break; @@ -224,7 +228,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field } }; -const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, parent = null, parentId = null, optionId }) => { +const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, parent = null, parentId = null, optionId, typeOfCall=null }) => { const { t } = useTranslation(); const state = Digit.ULBService.getStateId(); const tenantId = Digit.ULBService.getCurrentTenantId(); @@ -326,7 +330,10 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p const example = { maxWidth: "100rem" } - + + let dis = typeOfCall === "view" ? true : false; + console.log("type fof call", typeOfCall); + console.log("dis", dis); return ( {initialQuestionData @@ -340,7 +347,7 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p {/* * */}
- {initialQuestionData?.length > 1 && ( + {!dis && initialQuestionData?.length > 1 && ( <>
*/} handleUpdateField(event.target.value, "title", field.key, field.id)} placeholder={"Type your question here"} /> - + />}
{field?.isRegex && ( )} { (field?.type?.code === "Short Answer") && ( ) - - } - {field.dependency && ( + {!dis && field.dependency && ( ); })} -
+ {!dis &&
+
}
); }; diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestionContext.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestionContext.js index 56adfccaa9a..f298c615ef2 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestionContext.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/CreateQuestionContext.js @@ -171,13 +171,17 @@ const CreateQuestionContext = ({ onSelect, ...props }) => { const savedQuestions = localStorage.getItem("questions"); return savedQuestions ? JSON.parse(savedQuestions) : [{ id: crypto.randomUUID(), parentId: null, level: 1, key: 1, title: null, type: { "code": "SingleValueList" }, value: null, isRequired: false }] }) - + + const [typeOfCall, setTypeOfCall] = useState(null); const [questionData, dispatchQuestionData] = useReducer(questionDataReducer, initialState); useEffect(() => { // Avoid dispatch if props haven't changed + console.log("the preops are", props); if (props?.props?.data !== 0 && props?.props?.data?.[0]?.title !== null) { // Dispatch only if the data is different + console.log("the data is", props?.prop?.data); + setTypeOfCall(props?.props?.typeOfCall); dispatchQuestionData({ type: "UPDATE_QUESTION_DATA", payload: props?.props?.data, @@ -186,6 +190,9 @@ const CreateQuestionContext = ({ onSelect, ...props }) => { } }, [props?.props?.time]); // Ensure that the initialState is included in the dependency array + // useEffect(()=>{ + // console.log("call", typeOfCall); + // },[typeOfCall]); useEffect(() => { onSelect("createQuestion", { @@ -202,7 +209,7 @@ const CreateQuestionContext = ({ onSelect, ...props }) => { return ( - + ); }; diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/Dropdowns.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/Dropdowns.js index d38b5a60e54..a216d049ed0 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/Dropdowns.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/Dropdowns.js @@ -30,7 +30,9 @@ const Dropdowns = ({ subQinitialQuestionData, addComment, handleOptionComment, + typeOfCall }) => { + let dis = typeOfCall==="view"?true:false; return (
{options.map((item, index) => ( @@ -56,9 +58,11 @@ const Dropdowns = ({ addComment={addComment} handleOptionComment={handleOptionComment} t={t} + typeOfCall={typeOfCall} /> {item.optionComment && ))} -
+ {!dis &&
+
}
); }; @@ -123,9 +127,11 @@ const DropdownOption = ({ optionComment, addComment, handleOptionComment, - t + t, + typeOfCall }) => { const [isFocused, setIsFocused] = useState(false); + let dis = typeOfCall==="view"?true:false; return (
@@ -133,6 +139,7 @@ const DropdownOption = ({
- { + {!dis && <> } - { + {!dis && <> } - {!disableDelete && ( + {!dis && !disableDelete && ( //
removeOption(index)}> // // {t(`CAMPAIGN_DELETE_ROW_TEXT`)} diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/MultipleChoice.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/MultipleChoice.js index a49bedbe5c5..c0bc73feb77 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/MultipleChoice.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/MultipleChoice.js @@ -29,7 +29,9 @@ const MultipleChoice = ({ subQinitialQuestionData, addComment, handleOptionComment, + typeOfCall }) => { + let dis = typeOfCall==="view"?true:false; return (
{options.map((item, index) => ( @@ -55,9 +57,11 @@ const MultipleChoice = ({ t={t} addComment={addComment} handleOptionComment={handleOptionComment} + typeOfCall={typeOfCall} > {item.optionComment && )} @@ -89,8 +94,9 @@ const MultipleChoice = ({ } ))} -
+ {!dis &&
+
}
); }; @@ -128,17 +134,20 @@ export const RadioButtonOption = ({ optionComment, t, addComment, - handleOptionComment + handleOptionComment, + typeOfCall }) => { // const [optionTitle, setOptionTitle] = useState(title); const [isFocused, setIsFocused] = useState(false); + let dis = typeOfCall==="view"?true:false; return (
- + setIsFocused(false)} onFocus={() => setIsFocused(true)} className={isFocused ? "simple_editable-input" : "simple_readonly-input"} - maxLength={maxLength} + // maxLength={maxLength} title={titleHover} - disabled={isPartiallyEnabled ? !isPartiallyEnabled : formDisabled} + // disabled={isPartiallyEnabled ? !isPartiallyEnabled : formDisabled} />
- { + {!dis && <> } - { + {!dis && <> } - {!disableDelete && ( + {!dis && !disableDelete && ( //
removeOption(index)}> // // {t(`CAMPAIGN_DELETE_ROW_TEXT`)} diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/checklistCreateConfig.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/checklistCreateConfig.js index 18e4dfd152a..1b37e8498f0 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/checklistCreateConfig.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/checklistCreateConfig.js @@ -1,4 +1,4 @@ -export const checklistCreateConfig = (data, time) => [ +export const checklistCreateConfig = (data, time, typeOfCall) => [ { head: "", body: [ @@ -17,7 +17,8 @@ export const checklistCreateConfig = (data, time) => [ customProps: { module: "Campaign", data: data, - time: time + time: time, + typeOfCall: typeOfCall }, }, ], diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewChecklist.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewChecklist.js new file mode 100644 index 00000000000..429ae2b221c --- /dev/null +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewChecklist.js @@ -0,0 +1,240 @@ +import React, { useEffect, useState, createContext, useContext } from "react"; +import { checklistCreateConfig } from "../../configs/checklistCreateConfig"; +import { useTranslation } from "react-i18next"; +import { ViewCardFieldPair, Toast, Card, TextBlock, Button, PopUp, CardText, TextInput, BreadCrumb, Loader, ActionBar } from "@egovernments/digit-ui-components"; +import { FormComposerV2 } from "@egovernments/digit-ui-react-components"; +import { useHistory, useLocation } from "react-router-dom"; + +const ViewChecklist = () => { + const { t } = useTranslation(); + const tenantId = Digit.ULBService.getCurrentTenantId(); + const searchParams = new URLSearchParams(location.search); + const campaignName = searchParams.get("campaignName"); + const role = searchParams.get("role"); + const checklistType = searchParams.get("checklistType"); + const [config, setConfig] = useState(null); + const [checklistTypeCode, setChecklistTypeCode] = useState(null); + const [roleCode, setRoleCode] = useState(null); + const [serviceCode, setServiceCode] = useState(null); + const [searching, setSearching] = useState(true); + const [viewData, setViewData] = useState( + // [ + // { + // id: crypto.randomUUID(), + // parentId: null, + // level: 1, + // key: 1, + // title: null, + // type: { code: "SingleValueList" }, + // value: null, + // isRequired: false + // } + // ] + null + ); + + + + const reqCriteriaResourceMDMS = { + url: `/mdms-v2/v2/_search`, + // url: `/${urlMd}/v2/_search`, + body: { + MdmsCriteria: { + tenantId: tenantId, + schemaCode: "HCMadminconsole.checklisttemplates" + // schemaCode: "HCM-ADMIN-CONSOLE.ChecklistTemplates" + } + }, + config: { + enabled: true, + select: (data) => { + return data?.mdms?.[0]?.data?.data; + }, + }, + // changeQueryName:"checklsit template " + }; + const { isLoading1, data: mdms, isFetching } = Digit.Hooks.useCustomAPIHook(reqCriteriaResourceMDMS); + + const reqCriteria = { + + url: `/localization/messages/v1/_search`, + body: { + tenantId: tenantId + }, + params: { + locale: "en_MZ", + tenantId: tenantId, + module: "hcm-campaignmanager" + }, + } + const { isLoading2, data: localization, isFetching2 } = Digit.Hooks.useCustomAPIHook(reqCriteria); + + useEffect(() => { + if (localization?.messages?.length > 0) { + let matchedItem = localization.messages.find(item => item.message === checklistType); + console.log("matched item", matchedItem); + // If a match is found, assign the 'code' to 'checklistcode' + if (matchedItem) { + let code = matchedItem.code; + let res = code.replace("HCM_CHECKLIST_TYPE_", ""); + setChecklistTypeCode(res); + setRoleCode(role.toUpperCase().replace(/ /g, "_")); + console.log("type", checklistTypeCode); + console.log("role", roleCode); + } else { + } + } else { + } + + }, [localization]) + + useEffect(() => { + setServiceCode(`${campaignName}.${checklistTypeCode}.${roleCode}`); + }, [checklistTypeCode, roleCode] + ) + + useEffect(() => { + console.log("service code", serviceCode); + + const callSearch = async () => { + const res = await Digit.CustomService.getResponse({ + url: `/service-request/service/definition/v1/_search`, + body: { + ServiceDefinitionCriteria: { + "tenantId": tenantId, + "code": [serviceCode] + }, + }, + }); + return res; + } + const fetchData = async () => { + try { + const res = await callSearch(); + console.log("the res is", res); + + if (res?.ServiceDefinitions?.[0]?.attributes) { + setSearching(false); + let temp_data = res?.ServiceDefinitions?.[0]?.attributes + let formatted_data = temp_data.map((item) => item.additionalDetails); + setViewData(formatted_data); + console.log("formatted data", formatted_data); + + } + } + catch (error) { + } + } + fetchData(); + }, [serviceCode]) + + useEffect(() => { + // setConfig(checklistCreateConfig(data=[{ id: crypto.randomUUID(), parentId: null, level: 1, key: 1, title: null, type: {"code": "SingleValueList"}, value: null, isRequired: false }], typeOfCall="view")); + // const initialData = [ + // { + // id: crypto.randomUUID(), + // parentId: null, + // level: 1, + // key: 1, + // title: null, + // type: { code: "SingleValueList" }, + // value: null, + // isRequired: false + // } + // ]; + console.log("achieved data is", viewData); + const currentTime = new Date(); + if (viewData !== null) { + setConfig(checklistCreateConfig(viewData, currentTime, "view")); + // setConfig(checklistCreateConfig({ + // data: viewData, + // time: currentTime, + // typeOfCall: "view" + // })); + } + + }, [viewData]) + + + + + + const fieldPairs = [ + { label: "ROLE", value: role }, + { label: "TYPE_OF_CHECKLIST", value: checklistType }, + { label: "CAMPAIGN_NAME", value: campaignName }, + { label: "CHECKLIST_NAME", value: `${checklistType} ${role}` } + ]; + return ( +
+

+ {t("VIEW_CHECKLIST")} +

+ + {fieldPairs.map((pair, index) => ( +
+ + {index !== fieldPairs.length - 1 &&
} +
+ ))} +
+ {!searching && } + {searching && } + , +
+ ) + + + +}; + +export default ViewChecklist; \ No newline at end of file diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/index.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/index.js index 7375d961843..5b252805573 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/index.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/index.js @@ -15,6 +15,7 @@ import Boundary from "./Boundary"; import GeoPode from "./GeoPode"; import ViewBoundary from "./ViewBoundary"; import ViewHierarchy from "./ViewHierarchy"; +import ViewChecklist from "./ViewChecklist"; /** * The CampaignBreadCrumb function generates breadcrumb navigation for a campaign setup page in a React * application. @@ -127,7 +128,7 @@ const App = ({ path, BOUNDARY_HIERARCHY_TYPE, hierarchyData }) => { } /> } /> } /> - + } />