Skip to content

Commit

Permalink
checklist-bugs-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
suryansh-egov committed Oct 14, 2024
1 parent 8e309a6 commit 87bf9ba
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const CreateQuestionContext = ({ onSelect, ...props }) => {
}
};
// const [initialState, setInitialState] = useState([{ id: crypto.randomUUID(), parentId: null, level: 1, key: 1, title: null, type: { "code": "SingleValueList" }, value: null, isRequired: false }])

const [initialState, setInitialState] = useState(()=>{
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 }]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const CreateChecklist = () => {
const checklistType = searchParams.get("checklistType");
const projectName = searchParams.get("campaignName");
const campagnType = searchParams.get("campaignType");
const [checklistTypeCode, setChecklistTypeCode] = useState(null);
const [roleCode, setRoleCode] = useState(null);
const flow = searchParams.get("flow");
const role = searchParams.get("role");
const campaignName = searchParams.get("campaignName");
Expand All @@ -40,27 +42,62 @@ const CreateChecklist = () => {
const history = useHistory();
let data_mdms=[]
let template_data=[]
const reqCriteriaResource = {
url: `/mdms-v2/v2/_search`,
body: {
MdmsCriteria: {
const reqCriteriaResource = {
url: `/mdms-v2/v2/_search`,
body: {
MdmsCriteria: {
tenantId: tenantId,
schemaCode: "HCMadminconsole.checklisttemplates"
}
},
config: {
enabled: true,
select: (data) => {
return data?.mdms?.[0]?.data?.data;
},
},
// changeQueryName:"checklsit template "
};
const { isLoading, data: mdms, isFetching } = Digit.Hooks.useCustomAPIHook(reqCriteriaResource);
const reqCriteria = {

url: `/localization/messages/v1/_search`,
body:{
tenantId: tenantId
},
params: {
locale: "en_MZ",
tenantId: tenantId,
schemaCode: "HCMadminconsole.checklisttemplates"
}
},
config: {
enabled: true,
select: (data) => {
return data?.mdms?.[0]?.data?.data;
module: "hcm-campaignmanager"
},
},
};
const { isLoading, data: mdms, isFetching } = Digit.Hooks.useCustomAPIHook(reqCriteriaResource);
}
const { isLoading1, data: localization, isFetching1 } = Digit.Hooks.useCustomAPIHook(reqCriteria);
useEffect(()=>{
console.log("the achieved localization is", localization);
if (localization?.messages?.length > 0) {
let matchedItem = localization.messages.find(item => item.message === checklistType);
// If a match is found, assign the 'code' to 'checklistcode'
if (matchedItem) {
console.log("matched", matchedItem);
let code = matchedItem.code;
let res = code.replace("HCM_CHECKLIST_TYPE_", "");
console.log("the res", res);
setChecklistTypeCode(res);
} else {
console.log('No matching checklist type found.');
}
} else {
console.log('Localization or messages array is not available.');
}

}, [localization])


useEffect(()=>{
if(data_mdms && data_mdms.length!=0) template_data=data_mdms;
}, [mdms])

module = "HCM";
module = "hcm-checklist";
const { mutateAsync: localisationMutateAsync } = Digit.Hooks.campaign.useUpsertLocalisation(tenantId, module, locale);

let processedData = [];
Expand All @@ -69,10 +106,10 @@ module = "HCM";
},[])


const [checklistName, setChecklistName] = useState("");
const addChecklistName = (data) => {
setChecklistName(data);
}
const [checklistName, setChecklistName] = useState(`${checklistType} ${role}`);
// const addChecklistName = (data) => {
// setChecklistName(data);
// }

const closeToast = () => {
setShowToast(null);
Expand Down Expand Up @@ -159,15 +196,18 @@ module = "HCM";
}
codes[question.id] = code;

let moduleChecklist = "hcm-checklist";

let checklistTypeTemp = checklistType.toUpperCase().replace(/ /g, "_");
let roleTemp = role.toUpperCase().replace(/ /g, "_");
if(checklistTypeCode) checklistTypeTemp=checklistTypeCode;
let formattedString = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${code}`;


const obj = {
"code": formattedString,
"message": String(question.title),
"module": module,
"module": moduleChecklist,
"locale": locale
}
local.push(obj);
Expand All @@ -180,12 +220,13 @@ module = "HCM";
const optionval = option.label;
const upperCaseString = optionval.toUpperCase();
const transformedString = upperCaseString.replace(/ /g, '_');
if(checklistTypeCode) checklistTypeTemp=checklistTypeCode;
option.label = transformedString;
let formattedStringTemp = `${campaignName}.${checklistTypeTemp}.${roleTemp}.${option.label}`;
const obj = {
"code": formattedStringTemp,
"message": String(optionval),
"module": module, // to be dynamic
"module": moduleChecklist, // to be dynamic
"locale": locale //to be dynamic
}
local.push(obj);
Expand Down Expand Up @@ -290,6 +331,7 @@ module = "HCM";
);
let checklistTypeTemp = checklistType.toUpperCase().replace(/ /g, "_");
let roleTemp = role.toUpperCase().replace(/ /g, "_");
if(checklistTypeCode) checklistTypeTemp=checklistTypeCode;
let code_of_checklist = `${campaignName}.${checklistTypeTemp}.${roleTemp}`;
return {
tenantId: tenantId,
Expand Down Expand Up @@ -319,8 +361,18 @@ module = "HCM";
const data = await mutateAsync(payload); // Use mutateAsync for await support
// Handle successful checklist creation
// Proceed with localization if needed
console.log("data success", data);
console.log("ul", uniqueLocal);
let checklistTypeTemp = checklistType.toUpperCase().replace(/ /g, "_");
if(checklistTypeCode) checklistTypeTemp=checklistTypeCode;
let roleTemp = role.toUpperCase().replace(/ /g, "_");
uniqueLocal.push({code: `${campaignName}_${checklistTypeTemp}_${roleTemp}`,
locale: locale,
message: `${checklistType} ${role}`,
module: "hcm-checklist" });
if (data.success) { // Replace with your actual condition
const localisations = uniqueLocal;
console.log("unique local", uniqueLocal);
const localisationResult = await localisationMutateAsync(localisations);
// Check if localization succeeded
if (!localisationResult.success) {
Expand Down Expand Up @@ -452,12 +504,12 @@ module = "HCM";
<div style={{ display: "flex" }}>
<div style={{ width: "26%", fontWeight: "500", marginTop: "0.7rem" }}>{t("NAME_OF_CHECKLIST")}</div>
<TextInput
isRequired={true}
disabled={true}
className="tetxinput-example"
type={"text"}
name={t("NAME_OF_CHECKLIST")}
value={checklistName || ""}
onChange={(event) => addChecklistName(event.target.value)}
value={`${checklistType} ${role}`}
// onChange={(event) => addChecklistName(event.target.value)}
placeholder={"Checklist Name"}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const SearchChecklist = () => {
};

const createNewChecklist = () => {
localStorage.removeItem("questions");
history.push(
`/${window.contextPath}/employee/campaign/checklist/create?checklistType=${list?.list}&campaignName=${stateData?.name}&role=${code?.code}&campaignType=${stateData?.campaignType}`
);
Expand Down

0 comments on commit 87bf9ba

Please sign in to comment.