Skip to content

Commit

Permalink
FEATURE/HCMPRE-1649 : help text and checklist create call order corre…
Browse files Browse the repository at this point in the history
…cted (#2071)

* help text and checklist create call order corrected

* localisations changed

---------

Co-authored-by: Jagankumar <53823168+jagankumar-egov@users.noreply.github.com>
  • Loading branch information
suryansh-egov and jagankumar-egov authored Jan 29, 2025
1 parent 68e3dbd commit ed448fc
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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 @@ -429,7 +430,8 @@ const CreateChecklist = () => {
value: {
name: checklistName,
type: checklistType,
role: role
role: role,
helpText: helpText
}
}
]
Expand All @@ -448,28 +450,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, "_");
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 Down Expand Up @@ -611,6 +623,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>
</Card>
<div style={{ height: "1rem" }}></div>
<FormComposerV2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 @@ -74,6 +75,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 @@ -376,7 +378,8 @@ const UpdateChecklist = () => {
value: {
name: checklistName,
type: checklistType,
role: role
role: role,
helpText: helpText
}
}
]
Expand All @@ -399,12 +402,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, "_");
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 @@ -455,6 +465,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 @@ -533,6 +544,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>
}
</Card>
<div style={{ height: "1rem" }}></div>
{!isLoading && <FormComposerV2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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 @@ -44,6 +45,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 @@ -254,6 +256,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>
}
</Card>
<div style={{ height: "1rem" }} />

Expand Down

0 comments on commit ed448fc

Please sign in to comment.