Skip to content

Commit

Permalink
checklist bugs (#1512)
Browse files Browse the repository at this point in the history
Co-authored-by: suryansh-egov <suryansh.singh.egovernments.org>
  • Loading branch information
suryansh-egov authored Oct 14, 2024
1 parent 533ee3d commit 8e309a6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
className={"example"}
/> */}
<TextInput
isRequired={true}
className="tetxinput-example"
type={"text"}
// props={{ fieldStyle: example }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const CreateQuestionContext = ({ onSelect, ...props }) => {
});
break;
case "UPDATE_QUESTION_DATA":
return [...action.payload];
if(action?.payload && action?.payload.length>0) return [...action.payload];
else return state;
case "ADD_QUESTION":
return [
...state,
Expand Down Expand Up @@ -164,13 +165,18 @@ const CreateQuestionContext = ({ onSelect, ...props }) => {
return state;
}
};
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([{ 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 }]
})

const [questionData, dispatchQuestionData] = useReducer(questionDataReducer, initialState);

useEffect(() => {
// Avoid dispatch if props haven't changed
if (props?.props?.data !== 0) {
if (props?.props?.data !== 0 && props?.props?.data?.[0]?.title !== null) {
// Dispatch only if the data is different
dispatchQuestionData({
type: "UPDATE_QUESTION_DATA",
Expand All @@ -185,6 +191,12 @@ const CreateQuestionContext = ({ onSelect, ...props }) => {
onSelect("createQuestion", {
questionData,
});
if(!(questionData.length === 1 && questionData?.[0].title===null))
{
localStorage.setItem("questions", JSON.stringify(questionData));

}
// setInitialState(localStorage.getItem("questions"))
}, [questionData]);


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState, createContext, useContext } from "react";
import { ViewCardFieldPair, Toast, Card, TextBlock, Button, PopUp, CardText, FieldV1 } from "@egovernments/digit-ui-components";
import { FormComposerV2, LabelFieldPair, TextInput, Loader } from "@egovernments/digit-ui-react-components";
import { ViewCardFieldPair, Toast, Card, TextBlock, Button, PopUp, CardText, TextInput, BreadCrumb, Loader } from "@egovernments/digit-ui-components";
import { FormComposerV2 } from "@egovernments/digit-ui-react-components";
import { useHistory, useLocation } from "react-router-dom";
import { checklistCreateConfig } from "../../configs/checklistCreateConfig";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -451,15 +451,14 @@ module = "HCM";
</div>
<div style={{ display: "flex" }}>
<div style={{ width: "26%", fontWeight: "500", marginTop: "0.7rem" }}>{t("NAME_OF_CHECKLIST")}</div>
<FieldV1
<TextInput
isRequired={true}
className="tetxinput-example"
type={"text"}
populators={{
resizeSmart: false
}}
name={t("NAME_OF_CHECKLIST")}
value={checklistName || ""}
onChange={(event) => addChecklistName(event.target.value)}
placeholder={""}
placeholder={"Checklist Name"}
/>
</div>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const CampaignBreadCrumb = ({ location, defaultPath }) => {
const { t } = useTranslation();
const search = useLocation().search;
const pathVar = location.pathname.replace(defaultPath + "/", "").split("?")?.[0];

const crumbs = [
{
path: `/${window?.contextPath}/employee`,
Expand All @@ -32,7 +31,7 @@ const CampaignBreadCrumb = ({ location, defaultPath }) => {
{
path: pathVar === "my-campaign" ? "" : `/${window?.contextPath}/employee/campaign/my-campaign`,
content: t("MY_CAMPAIGN"),
show: pathVar === "my-campaign" || pathVar === "checklist/search" ? true : false,
show: pathVar === "my-campaign" || pathVar === "checklist/search" || pathVar === "checklist/create" ? true : false,
},
{
path: pathVar === "setup-campaign" ? "" : `/${window?.contextPath}/employee/campaign/setup-campaign`,
Expand All @@ -48,6 +47,11 @@ const CampaignBreadCrumb = ({ location, defaultPath }) => {
path: "",
content: t("ACTION_LABEL_CONFIGURE_APP"),
show:pathVar === "checklist/search" ? true : false,
},
{
path: "",
content: t("ACTION_CREATE_CHECKLIST"),
show: pathVar === "checklist/create" ? true : false,
}
];

Expand Down

0 comments on commit 8e309a6

Please sign in to comment.