Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help text and checklist create call order corrected #2071

Open
wants to merge 2 commits into
base: console
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const CreateChecklist = () => {
const history = useHistory();
const [serviceCode, setServiceCode] = useState(null);
const [def_data, setDef_Data] = useState(null);
const [helpText, setHelpText] = useState("");


module = "hcm-checklist";
Expand Down Expand Up @@ -428,7 +429,8 @@ const CreateChecklist = () => {
value: {
name: checklistName,
type: checklistType,
role: role
role: role,
helpText: helpText
}
}
]
Expand All @@ -447,28 +449,38 @@ const CreateChecklist = () => {
}
setSubmitting(true);
try {
const data = await mutateAsync(payload); // Use mutateAsync for await support
// Handle successful checklist creation
// Proceed with localization if needed
// Prepare localization data
let checklistTypeTemp = checklistType.toUpperCase().replace(/ /g, "_");
if (checklistTypeCode) checklistTypeTemp = checklistTypeCode;
let roleTemp = role.toUpperCase().replace(/ /g, "_");
let helpTextCode = helpText.toUpperCase().replace(/ /g, "_");
suryansh-egov marked this conversation as resolved.
Show resolved Hide resolved
uniqueLocal.push({
code: `${campaignName}.${checklistTypeTemp}.${roleTemp}`,
locale: locale,
message: `${t(checklistTypeLocal)} ${t(roleLocal)}`,
module: "hcm-checklist"
});
uniqueLocal.push({
code: `${campaignName}.${checklistTypeTemp}.${roleTemp}.${helpTextCode}`,
locale: locale,
message: helpText,
module: "hcm-checklist"
});

// Call upsert first
const localisations = uniqueLocal;
const localisationResult = await localisationMutateAsync(localisations);

if (!localisationResult.success) {
// Exit if upsert (localisation) fails
setShowToast({ label: "LOCALIZATION_FAILED_PLEASE_TRY_AGAIN", isError: "true" });
return;
}

// Proceed to create checklist
const data = await mutateAsync(payload);

if (data.success) { // Replace with your actual condition
const localisations = uniqueLocal;
const localisationResult = await localisationMutateAsync(localisations);
// Check if localization succeeded
if (!localisationResult.success) {
setShowToast({ label: "CHECKLIST_CREATED_LOCALISATION_ERROR", isError: "true" });
return; // Exit if localization fails
}

// setShowToast({ label: "CHECKLIST_AND_LOCALISATION_CREATED_SUCCESSFULLY"});
history.push(`/${window.contextPath}/employee/campaign/response?isSuccess=${true}`, {
message: "ES_CHECKLIST_CREATE_SUCCESS_RESPONSE",
preText: "ES_CHECKLIST_CREATE_SUCCESS_RESPONSE_PRE_TEXT",
Expand All @@ -478,11 +490,11 @@ const CreateChecklist = () => {
secondaryActionLink: `/${window?.contextPath}/employee/campaign/my-campaign`,
});
} else {
setShowToast({ label: "CHECKLIST_CREATED_FAILED", isError: "true" });
setShowToast({ label: "CHECKLIST_UPDATE_FAILED", isError: "true" });
}
} catch (error) {
// Handle error scenario
setShowToast({ label: "CHECKLIST_CREATED_FAILED", isError: "true" });
setShowToast({ label: "CHECKLIST_UPDATE_FAILED", isError: "true" });
// console.error("Error creating checklist:", error);
} finally {
setSubmitting(false);
Expand Down Expand Up @@ -610,6 +622,19 @@ const CreateChecklist = () => {
placeholder={"Checklist Name"}
/>
</div>
<div style={{ display: "flex" }}>
<div style={{ width: "26%", fontWeight: "500", marginTop: "0.7rem" }}>{t("CHECKLIST_HELP_TEXT")}</div>
<TextInput
disabled={false}
className="tetxinput-example"
type={"text"}
name={t("CHECKLIST_HELP_TEXT")}
value={helpText}
// value={`${clTranslated} ${rlTranslated}`}
onChange={(event) => setHelpText(event.target.value)}
placeholder={t("CHECKLIST_HELP_TEXT_PALCEHOLDER")}
/>
</div>
suryansh-egov marked this conversation as resolved.
Show resolved Hide resolved
</Card>
<div style={{ height: "1rem" }}></div>
<FormComposerV2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const UpdateChecklist = () => {
const [previewData, setPreviewData] = useState([]);
const [showPopUp, setShowPopUp] = useState(false);
const [curActive, setCurActive] = useState(false);
const [helpText, setHelpText] = useState("");


const popShow = () => {
Expand Down Expand Up @@ -73,6 +74,7 @@ const UpdateChecklist = () => {
select: (res) => {
if (res?.ServiceDefinitions?.[0]?.attributes) {
setCurActive(res?.ServiceDefinitions?.[0].isActive);
setHelpText(res?.ServiceDefinitions?.[0]?.additionalFields?.fields?.[0]?.value?.helpText);
let temp_data = res?.ServiceDefinitions?.[0]?.attributes
let formatted_data = temp_data.map((item) => item.additionalFields?.fields?.[0]?.value);
let nvd = formatted_data.filter((value, index, self) =>
Expand Down Expand Up @@ -375,7 +377,8 @@ const UpdateChecklist = () => {
value: {
name: checklistName,
type: checklistType,
role: role
role: role,
helpText: helpText
}
}
]
Expand All @@ -398,12 +401,19 @@ const UpdateChecklist = () => {
let checklistTypeTemp = checklistType.toUpperCase().replace(/ /g, "_");
if (checklistTypeCode) checklistTypeTemp = checklistTypeCode;
let roleTemp = role.toUpperCase().replace(/ /g, "_");
let helpTextCode = helpText.toUpperCase().replace(/ /g, "_");
suryansh-egov marked this conversation as resolved.
Show resolved Hide resolved
uniqueLocal.push({
code: `${campaignName}.${checklistTypeTemp}.${roleTemp}`,
locale: locale,
message: `${t(checklistTypeLocal)} ${t(roleLocal)}`,
module: "hcm-checklist"
});
uniqueLocal.push({
code: `${campaignName}.${checklistTypeTemp}.${roleTemp}.${helpTextCode}`,
locale: locale,
message: helpText,
module: "hcm-checklist"
});

// Call upsert first
const localisations = uniqueLocal;
Expand Down Expand Up @@ -454,6 +464,7 @@ const UpdateChecklist = () => {
{ label: "CHECKLIST_ROLE", value: roleLocal },
{ label: "TYPE_OF_CHECKLIST", value: checklistTypeLocal },
{ label: "CAMPAIGN_NAME", value: campaignName },
// { label: "CHECKLIST_HELP_TEXT", value: helpText }
// { label: "CHECKLIST_NAME", value: name}
];

Expand Down Expand Up @@ -532,6 +543,21 @@ const UpdateChecklist = () => {
{index !== fieldPairs.length - 1 && <div style={{ height: "1rem" }}></div>}
</div>
))}
{
<div style={{ display: "flex" }}>
<div style={{ width: "26%", fontWeight: "500", marginTop: "0.7rem" }}>{t("CHECKLIST_HELP_TEXT")}</div>
<TextInput
disabled={false}
className="tetxinput-example"
type={"text"}
name={t("CHECKLIST_HELP_TEXT")}
value={helpText}
// value={`${clTranslated} ${rlTranslated}`}
onChange={(event) => setHelpText(event.target.value)}
placeholder={t("CHECKLIST_HELP_TEXT_PALCEHOLDER")}
/>
</div>
}
suryansh-egov marked this conversation as resolved.
Show resolved Hide resolved
</Card>
<div style={{ height: "1rem" }}></div>
{!isLoading && <FormComposerV2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const ViewChecklist = () => {
const [config, setConfig] = useState(null);
const [showPopUp, setShowPopUp] = useState(false);
const [previewData, setPreviewData] = useState([]);
const [helpText, setHelpText] = useState("");

const [viewData, setViewData] = useState(null);

Expand All @@ -43,6 +44,7 @@ const ViewChecklist = () => {
select: (res) => {
if (res?.ServiceDefinitions?.[0]?.attributes) {
setServiceDefId(res?.ServiceDefinitions?.[0]?.id);
setHelpText(res?.ServiceDefinitions?.[0]?.additionalFields?.fields?.[0]?.value?.helpText);
const temp_data = res?.ServiceDefinitions?.[0]?.attributes
const formatted_data = temp_data.map((item) => item.additionalFields?.fields?.[0]?.value);
const nvd = formatted_data.filter((value, index, self) =>
Expand Down Expand Up @@ -253,6 +255,21 @@ const ViewChecklist = () => {
{index !== fieldPairs.length - 1 && <div style={{ height: "1rem" }}></div>}
</div>
))}
{
<div style={{ display: "flex" }}>
<div style={{ width: "26%", fontWeight: "500", marginTop: "0.7rem" }}>{t("CHECKLIST_HELP_TEXT")}</div>
<TextInput
disabled={true}
className="tetxinput-example"
type={"text"}
name={t("CHECKLIST_HELP_TEXT")}
value={helpText}
// value={`${clTranslated} ${rlTranslated}`}
// onChange={(event) => setHelpText(event.target.value)}
placeholder={t("CHECKLIST_HELP_TEXT_PALCEHOLDER")}
/>
</div>
}
suryansh-egov marked this conversation as resolved.
Show resolved Hide resolved
</Card>
<div style={{ height: "1rem" }} />

Expand Down
Loading