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

Console settings module updated with proper data #1748

Merged
merged 8 commits into from
Nov 6, 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 @@ -15,7 +15,7 @@
"@egovernments/digit-ui-module-core": "1.8.2-beta.13",
"@egovernments/digit-ui-module-utilities": "1.0.1-beta.30",
"@egovernments/digit-ui-react-components": "1.8.2-beta.17",
"@egovernments/digit-ui-module-hcmworkbench":"0.0.46",
"@egovernments/digit-ui-module-hcmworkbench":"0.0.47",
"@egovernments/digit-ui-module-campaign-manager": "0.2.1",
"@egovernments/digit-ui-module-microplan":"0.0.1",
"http-proxy-middleware": "^1.0.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egovernments/digit-ui-module-hcmworkbench",
"version": "0.0.46",
"version": "0.0.47",
"description": "Workbench-HCM",
"main": "dist/index.js",
"module": "dist/index.modern.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import RowDetails from "./components/RowDetails";
import TargetComponent from "./components/TargetComponent";

const HCMWORKBENCHModule = ({ stateCode, userType, tenants }) => {
const moduleCode = ["workbench-hcm"];
const modulePrefix = "hcm";
const moduleCode = ["campaign-settings"];
const { path, url } = useRouteMatch();
const language = Digit.StoreData.getCurrentLanguage();
const { isLoading, data: store } = Digit.Services.useStore({
stateCode,
moduleCode,
language,
modulePrefix,
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved
});

if (isLoading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const FacilityComponent = (props) => {
},
body: {
Facility: {
"id": [projectFacility?.ProjectFacilities?.[0]?.facilityId]
"id": projectFacility?.ProjectFacilities?.map(mapping=>mapping?.facilityId)
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved
},
},
config:{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const ProjectBeneficiaryComponent = (props) => {
},
},
config:{
enabled: productIds.length>0 ? true: false
enabled: Boolean(productIds?.length)
}
};

Expand Down Expand Up @@ -136,10 +136,7 @@ const ProjectBeneficiaryComponent = (props) => {
{ label: t("PRODUCT_ID"), key: "productVariant.productId" },
{ label: t("SKU"), key: "productVariant.sku" },
{ label: t("PRODUCT_VARIATION"), key: "productVariant.variation" },
{ label: t("START_DATE"), key: "formattedStartDate" },
{ label: t("END_DATE"), key: "formattedEndDate" },
{ label: t("RESOURCE_TYPE"), key: "resource.type" },
// { label: t("IS_BASE_UNIT_VARIANT"), key: "resource.isBaseUnitVariant" },
{ label: t("NAME"), key: "productVariant.product.name" },
{ label: t("MANUFACTURER"), key: "productVariant.product.manufacturer" },
{ label: t("PRODUCT_TYPE"), key: "productVariant.product.type" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ProjectStaffComponent = (props) => {
const [showModal, setShowModal] = useState(false);
const [userName, setUserName] = useState("");
const [showToast, setShowToast] = useState(false);
const [showResult, setShowResult] = useState("");
const [showResult, setShowResult] = useState(null);
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved
const [deletionDetails, setDeletionDetails] = useState({
projectId: null,
userId: null,
Expand All @@ -36,7 +36,7 @@ const ProjectStaffComponent = (props) => {
limit: 10,
},
config: {
enable: data?.horizontalNav?.configNavItems[0].code === "Project Resource" ? true : false,
enable: props.projectId && data?.horizontalNav?.configNavItems[0].code === "HCM_STAFF_MAPPED" ? true : false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify API request configurations and add type checking.

  1. The boolean literals in conditional expressions can be simplified:
- enable: props.projectId && data?.horizontalNav?.configNavItems[0].code === "HCM_STAFF_MAPPED" ? true : false,
+ enable: !!(props.projectId && data?.horizontalNav?.configNavItems[0].code === "HCM_STAFF_MAPPED"),
- enable: userIds?.length>0 ? true : false,
+ enable: !!(userIds?.length > 0),
  1. Consider adding type checking for the arrays before accessing their elements:
enable: Array.isArray(data?.horizontalNav?.configNavItems) && data.horizontalNav.configNavItems[0]?.code === "HCM_STAFF_MAPPED"

Also applies to: 72-75

🧰 Tools
🪛 Biome

[error] 39-39: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

},
body: {
ProjectStaff: {
Expand Down Expand Up @@ -69,7 +69,10 @@ const ProjectStaffComponent = (props) => {
body: {
"tenantId": "mz",
"uuid": userIds
}
},
config: {
enable: userIds?.length>0 ? true : false,
},
};

const { isLoading: isUserSearchLoading, data: userInfo } = Digit.Hooks.useCustomAPIHook(userRequestCriteria);
Expand Down Expand Up @@ -99,6 +102,8 @@ const ProjectStaffComponent = (props) => {
const columns = [
{ label: t("PROJECT_STAFF_ID"), key: "id" },
{ label: t("USERNAME"), key: "userInfo.userName" },
{ label: t("NAME"), key: "userInfo.name" },
{ label: t("MOBILENUMBER"), key: "userInfo.mobileNumber" },
{ label: t("ROLES"), key: "userInfo.roles" },
{ label: t("IS_DELETED"), key: "isDeleted" },
{ label: t("START_DATE"), key: "formattedStartDate" },
Expand Down Expand Up @@ -134,8 +139,9 @@ const ProjectStaffComponent = (props) => {
{
onSuccess: async (data) => {
if (data?.Employees && data?.Employees?.length > 0) {
setShowResult(data?.Employees[0]?.code);
setShowResult(data?.Employees[0]);
} else {
setShowResult(null);
setShowToast({ label: "WBH_USER_NOT_FOUND", isError: true });
setTimeout(() => setShowToast(null), 5000);
Comment on lines +142 to 146
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance error handling and user feedback.

  1. Consider adding a loading state while the search is in progress
  2. Add proper error boundary to handle API failures gracefully
  3. Provide more specific error messages instead of generic "USER_NOT_FOUND"

Example implementation:

 onSuccess: async (data) => {
+    setIsLoading(false);
     if (data?.Employees && data?.Employees?.length > 0) {
         setShowResult(data?.Employees[0]);
     } else {
         setShowResult(null);
-        setShowToast({ label: "WBH_USER_NOT_FOUND", isError: true });
+        setShowToast({ 
+            label: `WBH_USER_NOT_FOUND_WITH_CODE_${userName}`,
+            isError: true 
+        });
         setTimeout(() => setShowToast(null), 5000);
     }
+ },
+ onError: (error) => {
+    setIsLoading(false);
+    setShowToast({ 
+        label: error.message || "WBH_SEARCH_ERROR",
+        isError: true 
+    });
 }

Committable suggestion skipped: line range outside the PR's diff.

}
Expand Down Expand Up @@ -168,7 +174,7 @@ const ProjectStaffComponent = (props) => {
setShowModal(false);
setShowPopup(false);
setUserName("");
setShowResult("");
setShowResult(null);
};

const closeToast = () => {
Expand All @@ -195,7 +201,7 @@ const ProjectStaffComponent = (props) => {
ProjectStaff: {
tenantId,
userId: userId,
projectId: projectId,
projectId: props?.Project[0]?.id || projectId,
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved
startDate: props?.Project[0]?.startDate,
endDate: props?.Project[0]?.endDate,
},
Expand Down Expand Up @@ -270,7 +276,7 @@ const ProjectStaffComponent = (props) => {
onSubmit={handleProjectStaffSubmit}
onClose={closeModal}
heading={"WBH_ASSIGN_PROJECT_STAFF"}
isDisabled={!showResult || showResult.length === 0} // Set isDisabled based on the condition
isDisabled={showResult==null} // Set isDisabled based on the condition
/>
)}
{showPopup && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const projectStaffData = (searchResult) => {
const getRoles = searchResult?.user?.roles ? searchResult.user.roles.map((role) => `WBH_${role.name}`).join(",") : "NA";
const getRoles = searchResult?.user?.roles ? searchResult.user.roles.map((role) => `ACCESSCONTROL_ROLES_ROLES_${role?.code}`).join(",") : "NA";

return {
cards: [
Expand All @@ -9,6 +9,8 @@ export const projectStaffData = (searchResult) => {
type: "DATA",
values: [
{ key: "WBH_USERNAME", value: searchResult?.code || "NA" },
{ key: "WBH_NAME", value: searchResult?.user?.name || "NA" },
{ key: "WBH_MOBILENO", value: searchResult?.user?.mobileNumber || "NA" },
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved
{ key: "WBH_BOUNDARY", value: searchResult?.jurisdictions?.[0]?.boundary || "NA" },
{ key: "WBH_BOUNDARY_TYPE", value: searchResult?.jurisdictions?.[0]?.boundaryType || "NA" },
{ key: "WBH_ROLES", value: getRoles },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export const data = (project) => {
],
},
{
navigationKey: "card5",
navigationKey: "card1",
sections: [
{
navigationKey: "card5",
navigationKey: "card1",
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved

type: "COMPONENT",
component: "TargetComponent",
Expand Down Expand Up @@ -100,10 +100,10 @@ export const data = (project) => {
],
},
{
navigationKey: "card1",
navigationKey: "card5",
sections: [
{
navigationKey: "card1",
navigationKey: "card5",

type: "COMPONENT",
component: "ProjectStaffComponent",
Expand Down Expand Up @@ -132,30 +132,30 @@ export const data = (project) => {
showNav: true,
configNavItems: [
{
name: "card5",
name: "card1",
active: true,
code: "Targets",
code: "HCM_TARGET_MAPPED",
},
{
name: "card3",
active: true,
code: "Children",
code: "HCM_CHILDREN_MAPPED",
},
{
name: "card2",
active: true,
code: "Project Resource",
code: "HCM_RESOURCE_MAPPED",
},
{
name: "card1",
name: "card5",
active: true,
code: "Project Staff",
code: "HCM_STAFF_MAPPED",
},

{
name: "card4",
active: true,
code: "Facility",
code: "HCM_FACILITY_MAPPED",
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved
},

],
Expand Down
2 changes: 1 addition & 1 deletion health/micro-ui/web/workbench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@egovernments/digit-ui-module-core": "1.8.2-beta.25",
"@egovernments/digit-ui-module-utilities": "1.0.1-beta.35",
"@egovernments/digit-ui-react-components": "1.8.2-beta.17",
"@egovernments/digit-ui-module-hcmworkbench":"0.0.46",
"@egovernments/digit-ui-module-hcmworkbench":"0.0.47",
"@egovernments/digit-ui-module-campaign-manager": "0.2.1",
"react": "17.0.2",
"react-dom": "17.0.2",
Expand Down