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

FEATURE/HCMPRE-1624 : added alert, fixed localisation on checklist & added more date info on Hierarchy #2054

Merged
merged 8 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -8,8 +8,9 @@ const FinalPopup = ({ showFinalPopUp, setShowFinalPopup, onConfirmClick})=> {
showFinalPopUp && (
<PopUp
className={"custom-popup"}
type={"default"}
heading={t("CREATE_BOUNDARY_HIERARCHY")}
type={"alert"}
alertMessage={t("YOU_WON'T_BE_ABLE_TO_UNDO_THIS_STEP_OF_CREATING_HIERARCHY")}
alertHeading={t("CREATE_BOUNDARY_HIERARCHY")}
suryansh-egov marked this conversation as resolved.
Show resolved Hide resolved
children={[
]}
onClose={()=>{
Expand Down Expand Up @@ -45,9 +46,6 @@ const FinalPopup = ({ showFinalPopUp, setShowFinalPopup, onConfirmClick})=> {
]}
sortFooterChildren={true}
>
<div>
{<div>{t("YOU_WON'T_BE_ABLE_TO_UNDO_THIS_STEP_OF_CREATING_HIERARCHY")}</div>}
</div>
</PopUp>

)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Card, Loader } from "@egovernments/digit-ui-components";
import { Card, InfoCard, Loader } from "@egovernments/digit-ui-components";
import { Button, Toast } from "@egovernments/digit-ui-components";
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -49,7 +49,7 @@ const BoundaryHome = () => {
const [geoPodeData, setGeoPodeData] = useState(false);
const history = useHistory();

const type=searchParams.get("type")|| config?.type;
const type=searchParams.get("type")|| config?.type;

const {isLoading,data,error}=Digit.Hooks.campaign.useBoundaryHome({ screenType: type,defaultHierarchyType:searchParams?.get("defaultHierarchyType"),hierarchyType:searchParams?.get("hierarchyType"),userName:Digit.UserService.getUser()?.info?.userName,tenantId });
if (isLoading) return <Loader />;
Expand Down Expand Up @@ -79,6 +79,15 @@ const type=searchParams.get("type")|| config?.type;
})}
</div>
</Card>
<InfoCard
label="Info"
variant="default"
style={{maxWidth:"200rem", marginTop:"1rem"}}
additionalElements={[<span style={{ color: "#505A5F", fontWeight:600 }}>{t(`CURRENT_HIERARCHY_TYPE_IS`)} {": "} {t(data?.hierarchyName)}</span>,
<span style={{ color: "#505A5F", fontWeight: 600 }}>{t(`HIERARCHY_CREATED_ON`)} {": "} {new Date(data?.boundaryData?.auditDetails?.createdTime).toLocaleDateString()}</span>,
<span style={{ color: "#505A5F", fontWeight: 600 }}>{t(`HIERARCHY_LAST_MODIFIED_ON`)} {": "} {new Date(data?.boundaryData?.auditDetails?.lastModifiedTime).toLocaleDateString()}</span>,
]}
/>
</React.Fragment>
suryansh-egov marked this conversation as resolved.
Show resolved Hide resolved
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,53 +388,56 @@ const UpdateChecklist = () => {
const onSubmit = async (formData, flag = 0, preview = null) => {
let payload;
if (flag === 1) {
payload = payloadData(preview);
payload = payloadData(preview);
} else {
payload = payloadData(formData?.createQuestion?.questionData);
payload = payloadData(formData?.createQuestion?.questionData);
}
setSubmitting(true);
try {
const data = await mutateAsync(payload); // Use mutateAsync for await support
// Handle successful checklist creation
// Proceed with localization if needed
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: `${t(checklistTypeLocal)} ${t(roleLocal)}`,
module: "hcm-checklist"
// Prepare localization data
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: `${t(checklistTypeLocal)} ${t(roleLocal)}`,
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
history.push(`/${window.contextPath}/employee/campaign/response?isSuccess=${true}`, {
message: "ES_CHECKLIST_UPDATE_SUCCESS_RESPONSE",
preText: "ES_CHECKLIST_UPDATE_SUCCESS_RESPONSE_PRE_TEXT",
actionLabel: "CS_CHECKLIST_NEW_RESPONSE_ACTION",
actionLink: `/${window.contextPath}/employee/campaign/checklist/search?name=${campaignName}&campaignId=${campaignId}&projectType=${projectType}`,
secondaryActionLabel: "MY_CAMPAIGN",
secondaryActionLink: `/${window?.contextPath}/employee/campaign/my-campaign`,
});
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_UPDATE_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_UPDATE_SUCCESS_RESPONSE",
preText: "ES_CHECKLIST_UPDATE_SUCCESS_RESPONSE_PRE_TEXT",
actionLabel: "CS_CHECKLIST_NEW_RESPONSE_ACTION",
actionLink: `/${window.contextPath}/employee/campaign/checklist/search?name=${campaignName}&campaignId=${campaignId}&projectType=${projectType}`,
secondaryActionLabel: "MY_CAMPAIGN",
secondaryActionLink: `/${window?.contextPath}/employee/campaign/my-campaign`,
});
} else {
setShowToast({ label: "CHECKLIST_UPDATE_FAILED", isError: "true" });
}
} catch (error) {
// Handle error scenario
} else {
setShowToast({ label: "CHECKLIST_UPDATE_FAILED", isError: "true" });
// console.error("Error creating checklist:", error);
}
} catch (error) {
// Handle error scenario
setShowToast({ label: "CHECKLIST_UPDATE_FAILED", isError: "true" });
// console.error("Error creating checklist:", error);
} finally {
setSubmitting(false);
setSubmitting(false);
}
};
};
suryansh-egov marked this conversation as resolved.
Show resolved Hide resolved

useEffect(()=>{
if(showToast !== null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, createContext, useContext } from "react";
import React, { useEffect, useState, createContext, useContext, useCallback } from "react";
import { checklistCreateConfig } from "../../configs/checklistCreateConfig";
import { useTranslation } from "react-i18next";
import { ViewCardFieldPair, Toast, Card, TextBlock, Button, PopUp, CardText, TextInput, BreadCrumb, Loader, ActionBar, Tag} from "@egovernments/digit-ui-components";
Expand Down Expand Up @@ -27,6 +27,9 @@ const ViewChecklist = () => {

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

const [serviceDefId, setServiceDefId] = useState(null);
const [updateDisable, setUpdateDisable] = useState(false);

const res = {
url: `/service-request/service/definition/v1/_search`,
body: {
Expand All @@ -39,6 +42,7 @@ const ViewChecklist = () => {
config: {
select: (res) => {
if (res?.ServiceDefinitions?.[0]?.attributes) {
setServiceDefId(res?.ServiceDefinitions?.[0]?.id);
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 All @@ -52,7 +56,6 @@ const ViewChecklist = () => {
const { isLoading, data, isFetching } = Digit.Hooks.useCustomAPIHook(res);

useEffect(() => {

if (data) {
data.forEach((question) => {
if (question.type.code === "String") {
Expand All @@ -66,6 +69,48 @@ const ViewChecklist = () => {

}, [data])

// Second API call - use a separate hook with conditional execution
const [serviceResponseParam, setServiceResponseParam] = useState(null);

useEffect(() => {
// Only set API params when serviceDefId is available
if (serviceDefId) {
setServiceResponseParam({
url: `/service-request/service/v1/_search`,
body: {
ServiceCriteria: {
"tenantId": tenantId,
"serviceDefIds": [serviceDefId]
}
},
config: {
select: (res) => {
if (res?.Services?.[0]?.auditDetails) {
const lastModifiedTime = res?.Services?.[0]?.auditDetails?.lastModifiedTime;
if (lastModifiedTime) {
const modifiedDate = new Date(lastModifiedTime);
const today = new Date();
const isToday =
modifiedDate.getDate() === today.getDate() &&
modifiedDate.getMonth() === today.getMonth() &&
modifiedDate.getFullYear() === today.getFullYear();

if (isToday) {
setUpdateDisable(true);
}
}
}
return res;
}
}
});
}
}, [serviceDefId, tenantId]);

suryansh-egov marked this conversation as resolved.
Show resolved Hide resolved
// Conditionally call the hook only when params are available
const { isLoading: secondLoading, data: secondData } = Digit.Hooks.useCustomAPIHook(
serviceResponseParam || {} // Provide an empty object if params are not set
);
function organizeQuestions(questions) {
// Deep clone the questions to avoid mutating the original tempFormData
const clonedQuestions = JSON.parse(JSON.stringify(questions));
Expand Down Expand Up @@ -220,6 +265,7 @@ const ViewChecklist = () => {
}}
fieldStyle={{ marginRight: 0 }}
noBreakLine={true}
isDisabled={updateDisable}
// cardClassName={"page-padding-fix"}
// onFormValueChange={onFormValueChange}
actionClassName={"checklistCreate"}
Expand Down
Loading