Skip to content

Commit

Permalink
intial changes new
Browse files Browse the repository at this point in the history
  • Loading branch information
suryansh-egov committed Oct 16, 2024
1 parent b350c6d commit ed16dc8
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const Checkboxes = ({
subQinitialQuestionData,
addComment,
handleOptionComment,
typeOfCall
}) => {
let dis = typeOfCall==="view"?true:false;
return (
<div >
{options.map((item, index) => (
Expand All @@ -55,9 +57,11 @@ const Checkboxes = ({
t={t}
addComment={addComment}
handleOptionComment={handleOptionComment}
typeOfCall={typeOfCall}
/>
{item.optionComment && <FieldV1
// className="example"
disabled={dis}
type={"textarea"}
populators={{
resizeSmart:true
Expand All @@ -82,7 +86,7 @@ const Checkboxes = ({
}
</>
))}
<div>
{!dis && <div>
<Button
// className="custom-class"
icon="AddIcon"
Expand All @@ -94,15 +98,7 @@ const Checkboxes = ({
variation="teritiary"
textStyles={{width:'unset'}}
/>
{/* <button
className="unstyled-button link"
type="button"
disabled={(!createNewSurvey && formDisabled) || (isPartiallyEnabled ? !isPartiallyEnabled : formDisabled)}
onClick={() => addOption()}
>
{t("CS_COMMON_ADD_OPTION")}
</button> */}
</div>
</div>}
</div>
);
};
Expand All @@ -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 });
Expand All @@ -141,23 +139,24 @@ const CheckBoxOption = ({
<div>
<div className="optioncheckboxwrapper" style={{justifyContent:"space-between", height:"3rem"}}>
<div style={{display:"flex"}}>
<CheckBox mainClassName="checkboxOptionVariant" label="" disable={isInputDisabled} />
<CheckBox mainClassName="checkboxOptionVariant" label="" disable={dis} />
<input
disabled={dis}
ref={inputRef}
type="text"
value={title}
onChange={(ev) => updateOption({ value: ev.target.value, id: index })}
onBlur={() => 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}
/>
</div>
<div style={{display:"flex", gap:"1rem", alignItems:"center"}}>
{
{!dis &&
<>
<CheckBox
key={field.key}
Expand All @@ -181,7 +180,7 @@ const CheckBoxOption = ({
// isLabelFirst={true}
index={field.key}
/>} */}
{!disableDelete && (
{!dis && !disableDelete && (
// <div className="pointer" onClick={() => removeOption(index)}>
// <DustbinIcon />
// {t(`CAMPAIGN_DELETE_ROW_TEXT`)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field
subQparent,
subQparentId,
subQinitialQuestionData,
typeOfCall
}) => {

const [options, setOptions] = useState(() => {
Expand Down Expand Up @@ -169,6 +170,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field
subQparent={subQparent}
subQparentId={subQparentId}
subQinitialQuestionData={subQinitialQuestionData}
typeOfCall={typeOfCall}
/>
);
break;
Expand All @@ -192,6 +194,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field
subQparent={subQparent}
subQparentId={subQparentId}
subQinitialQuestionData={subQinitialQuestionData}
typeOfCall={typeOfCall}
/>
);
break;
Expand All @@ -215,6 +218,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field
subQparent={subQparent}
subQparentId={subQparentId}
subQinitialQuestionData={subQinitialQuestionData}
typeOfCall={typeOfCall}
/>
);
break;
Expand All @@ -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();
Expand Down Expand Up @@ -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 (
<React.Fragment>
{initialQuestionData
Expand All @@ -340,7 +347,7 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
{/* <span className="mandatory-span">*</span> */}
<div style={{ height: "1rem" }}>
</div>
{initialQuestionData?.length > 1 && (
{!dis && initialQuestionData?.length > 1 && (
<>
<div className="separator"></div>
<div
Expand Down Expand Up @@ -376,6 +383,7 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
className={"example"}
/> */}
<TextInput
disabled={dis}
isRequired={true}
className="tetxinput-example"
type={"text"}
Expand All @@ -385,7 +393,7 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
onChange={(event) => handleUpdateField(event.target.value, "title", field.key, field.id)}
placeholder={"Type your question here"}
/>
<Dropdown
{!dis && <Dropdown
style={{ width: "20%" }}
t={t}
option={dataType}
Expand All @@ -395,7 +403,7 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
handleUpdateField(value, "type", field.key, field.id);
}}
placeholder="Type"
/>
/>}
</div>
{field?.isRegex && (
<Dropdown
Expand Down Expand Up @@ -425,11 +433,13 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
subQparent={field}
subQparentId={field.id}
subQinitialQuestionData={initialQuestionData}
typeOfCall={typeOfCall}
/>
)}
{
(field?.type?.code === "Short Answer") && (
<FieldV1
disabled="true"
className="example"
type={"textarea"}
populators={{
Expand All @@ -442,10 +452,8 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
placeholder={""}
/>
)


}
{field.dependency && (
{!dis && field.dependency && (
<CreateQuestion
onSelect={onSelect}
className="subSection"
Expand All @@ -464,7 +472,7 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
</Card>
);
})}
<div style={{ display: "flex", justifyContent: "center" }}>
{!dis && <div style={{ display: "flex", justifyContent: "center" }}>
<Button
variation="secondary"
label={t("ADD_QUESTION")}
Expand All @@ -476,7 +484,7 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
onClick={()=>addMoreField()}
textStyles={{width:'unset'}}
/>
</div>
</div>}
</React.Fragment>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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", {
Expand All @@ -202,7 +209,7 @@ const CreateQuestionContext = ({ onSelect, ...props }) => {

return (
<QuestionContext.Provider value={{ questionData, dispatchQuestionData }}>
<CreateQuestion initialQuestionData={questionData} level={1} onSelect={onSelect} />
<CreateQuestion initialQuestionData={questionData} level={1} onSelect={onSelect} typeOfCall={typeOfCall} />
</QuestionContext.Provider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const Dropdowns = ({
subQinitialQuestionData,
addComment,
handleOptionComment,
typeOfCall
}) => {
let dis = typeOfCall==="view"?true:false;
return (
<div className="options_checkboxes">
{options.map((item, index) => (
Expand All @@ -56,9 +58,11 @@ const Dropdowns = ({
addComment={addComment}
handleOptionComment={handleOptionComment}
t={t}
typeOfCall={typeOfCall}
/>
{item.optionComment && <FieldV1
// className="example"
disabled={dis}
type={"textarea"}
populators={{
resizeSmart:true
Expand All @@ -83,7 +87,7 @@ const Dropdowns = ({
}
</>
))}
<div>
{!dis && <div>
<Button
className="custom-class"
icon="AddIcon"
Expand All @@ -96,7 +100,7 @@ const Dropdowns = ({
textStyles={{width:'unset'}}

/>
</div>
</div>}
</div>
);
};
Expand All @@ -123,16 +127,19 @@ const DropdownOption = ({
optionComment,
addComment,
handleOptionComment,
t
t,
typeOfCall
}) => {
const [isFocused, setIsFocused] = useState(false);
let dis = typeOfCall==="view"?true:false;

return (
<div>
<div key={index} className="optioncheckboxwrapper" style={{justifyContent:"space-between", height:"2rem"}}>
<div style={{display:"flex"}}>
<TextInput
// style={{ maxWidth: "40rem" }}
disabled={dis}
name="title"
// value={field?.title || ""}
value={title}
Expand All @@ -141,7 +148,7 @@ const DropdownOption = ({
/>
</div>
<div style={{display:"flex", gap:"1rem", alignItems:"center"}}>
{
{!dis &&
<>
<CheckBox
key={field.key}
Expand All @@ -157,7 +164,7 @@ const DropdownOption = ({
/>
</>
}
{
{!dis &&
<>
<CheckBox
key={field.key}
Expand All @@ -173,7 +180,7 @@ const DropdownOption = ({
/>
</>
}
{!disableDelete && (
{!dis && !disableDelete && (
// <div className="pointer" onClick={() => removeOption(index)}>
// <DustbinIcon />
// {t(`CAMPAIGN_DELETE_ROW_TEXT`)}
Expand Down
Loading

0 comments on commit ed16dc8

Please sign in to comment.