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

Develop #990

Merged
merged 15 commits into from
Oct 29, 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 @@ -32,7 +32,8 @@ const HRMSCard = () => {
},
]
: [];


// only for state admin
const moduleForSomeSTATEUser =
STATE_ADMIN && MDMS_ADMIN
? [
Expand All @@ -41,6 +42,11 @@ const HRMSCard = () => {
link: `${window?.location?.origin}/workbench-ui/employee/workbench/mdms-search-v2?moduleName=tenant&masterName=tenants`,
category: t("HR_EDIT_MASTER"),
},
{
label: t("WORK_BENCH_URL_LOCALISATION"),
link: `${window?.location?.origin}/workbench-ui/employee/workbench/localisation-search`,
category: t("HR_EDIT_MASTER"),
},
]
: [];

Expand Down Expand Up @@ -88,11 +94,11 @@ const HRMSCard = () => {
category: t("SEARCH_USER_HEADER"),
},

{
label: t("HR_STATE_ REPORTS"),
link: `/${window?.contextPath}/employee/hrms/dashboard?moduleName=dashboard&pageName=state`,
category: t("HR_DASHBOARD_HEADER"),
},
{
label: t("HR_STATE_ REPORTS"),
link: `/${window?.contextPath}/employee/hrms/dashboard?moduleName=dashboard&pageName=state`,
category: t("HR_DASHBOARD_HEADER"),
},
{
label: t("HR_RATE_DASHBOARD"),
link: `/${window?.contextPath}/employee/hrms/dashboard?moduleName=dashboard&pageName=rate-master`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const BannerPicker = (props) => {
return (
<Banner
message={GetActionMessage(props.action, props.isSuccess, props.isEmployee, props.t)}
applicationNumber={props.isSuccess?props?.data?.Employees?.[0]?.code:''}
applicationNumber={props.isSuccess ? props?.data?.Employees?.[0]?.code : ""}
info={GetLabel(props.action, props.isSuccess, props.isEmployee, props.t)}
successful={props.isSuccess}
/>
Expand All @@ -40,17 +40,17 @@ const Response = (props) => {
const mutation = state.key === "UPDATE" ? Digit.Hooks.hrms.useHRMSUpdate(tenantId) : Digit.Hooks.hrms.useHRMSCreate(tenantId);

const employeeCreateSession = Digit.Hooks.useSessionStorage("NEW_EMPLOYEE_CREATE", {});
const [sessionFormData,setSessionFormData, clearSessionFormData] = employeeCreateSession;
const [sessionFormData, setSessionFormData, clearSessionFormData] = employeeCreateSession;

// remove session form data if user navigates away from the estimate create screen
useEffect(()=>{
useEffect(() => {
if (!window.location.href.includes("/hrms/create") && sessionFormData && Object.keys(sessionFormData) != 0) {
clearSessionFormData();
clearSessionFormData();
}
},[location]);
}, [location]);
Comment on lines +46 to +50
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix useEffect implementation issues.

The cleanup effect has several issues that should be addressed:

  1. Use strict equality (!==) instead of loose equality (!=)
  2. The location dependency isn't defined (should be from react-router)
  3. Missing cleanup function

Here's the suggested fix:

- useEffect(() => {
-   if (!window.location.href.includes("/hrms/create") && sessionFormData && Object.keys(sessionFormData) != 0) {
-     clearSessionFormData();
-   }
- }, [location]);
+ import { useLocation } from 'react-router-dom';
+ // Add at the component start:
+ const location = useLocation();
+ 
+ useEffect(() => {
+   if (!window.location.href.includes("/hrms/create") && sessionFormData && Object.keys(sessionFormData) !== 0) {
+     clearSessionFormData();
+   }
+   return () => {
+     // Cleanup if needed
+   };
+ }, [location, sessionFormData, clearSessionFormData]);

Committable suggestion was skipped due to low confidence.


const onError = (error, variables) => {
setErrorInfo(error?.response?.data?.Errors[0]?.code || 'ERROR');
setErrorInfo(error?.response?.data?.Errors[0]?.code || "ERROR");
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Standardize error handling approach.

The error message extraction is inconsistent between the onError function and DisplayText function. Consider creating a utility function for consistent error handling.

+ const getErrorMessage = (error) => {
+   return error?.response?.data?.Errors?.[0]?.code || "ERROR";
+ };

  const onError = (error, variables) => {
-   setErrorInfo(error?.response?.data?.Errors[0]?.code || "ERROR");
+   setErrorInfo(getErrorMessage(error));
    setMutationHappened(true);
  };

  const DisplayText = (action, isSuccess, isEmployee, t) => {
    if (!isSuccess) {
-     return mutation?.error?.response?.data?.Errors[0].code || "ERROR";
+     return getErrorMessage(mutation?.error);
    }
    // ...
  };

Also applies to: 86-86

setMutationHappened(true);
};

Expand All @@ -62,7 +62,7 @@ const Response = (props) => {
const onSuccess = () => {
setMutationHappened(true);
};
if (!mutationHappened ) {
if (!mutationHappened) {
if (state.key === "UPDATE") {
mutation.mutate(
{
Expand All @@ -83,20 +83,20 @@ const Response = (props) => {

const DisplayText = (action, isSuccess, isEmployee, t) => {
if (!isSuccess) {
return mutation?.error?.response?.data?.Errors[0].code||errorInfo;
return mutation?.error?.response?.data?.Errors[0].code || "ERROR";
} else {
Digit.SessionStorage.set("isupdate", Math.floor(100000 + Math.random() * 900000));
return state.key === "CREATE"?"HRMS_CREATE_EMPLOYEE_INFO" :"";
return state.key === "CREATE" ? "HRMS_CREATE_EMPLOYEE_INFO" : "";
}
};
if (mutation.isLoading || (mutation.isIdle && !mutationHappened)) {
if (mutation.isLoading || (mutation.isIdle && !mutationHappened)) {
return <Loader />;
}
return (
<Card>
<BannerPicker
t={t}
data={mutation?.data|| successData}
data={mutation?.data || successData}
action={state.action}
isSuccess={!successData ? mutation?.isSuccess : true}
isLoading={(mutation.isIdle && !mutationHappened) || mutation?.isLoading}
Expand All @@ -105,7 +105,7 @@ const Response = (props) => {
<CardText>{t(DisplayText(state.action, mutation.isSuccess || !!successData, props.parentRoute.includes("employee"), t), t)}</CardText>

<ActionBar>
<Link to={`${props.parentRoute.includes("employee") ? `/${window?.contextPath}/employee` : `/${window?.contextPath}/citizen`}`}>
<Link to={`${props.parentRoute.includes("employee") ? `/${window?.contextPath}/employee` : `/${window?.contextPath}/citizen`}`}>
<SubmitBar label={t("CORE_COMMON_GO_TO_HOME")} />
</Link>
</ActionBar>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Link, useHistory } from "react-router-dom";
import _ from "lodash";
import React from "react";
import { useTranslation } from "react-i18next";

function anonymizeHalfString(input) {
// Initialize an empty string to store the anonymized output
Expand All @@ -22,28 +23,27 @@ function anonymizeHalfString(input) {
}

export const UICustomizations = {
OpenPaymentSearch:{
OpenPaymentSearch: {
preProcess: (data, additionalDetails) => {

//we need to get three things -> consumerCode,businessService,tenantId
// businessService and tenantId can be either in queryParams or in form
let {consumerCode,businessService,tenantId} = data?.state?.searchForm || {};
businessService = businessService?.code
tenantId = tenantId?.[0]?.code
if(!businessService){
businessService = additionalDetails?.queryParams?.businessService
let { consumerCode, businessService, tenantId } = data?.state?.searchForm || {};
businessService = businessService?.code;
tenantId = tenantId?.[0]?.code;
Comment on lines +30 to +32
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null checks for nested property destructuring

The current destructuring could throw errors if data.state is undefined.

Consider adding null checks:

- let { consumerCode, businessService, tenantId } = data?.state?.searchForm || {};
- businessService = businessService?.code;
- tenantId = tenantId?.[0]?.code;
+ let { consumerCode, businessService, tenantId } = data?.state?.searchForm ?? {};
+ businessService = businessService?.code ?? undefined;
+ tenantId = tenantId?.[0]?.code ?? undefined;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let { consumerCode, businessService, tenantId } = data?.state?.searchForm || {};
businessService = businessService?.code;
tenantId = tenantId?.[0]?.code;
let { consumerCode, businessService, tenantId } = data?.state?.searchForm ?? {};
businessService = businessService?.code ?? undefined;
tenantId = tenantId?.[0]?.code ?? undefined;

if (!businessService) {
businessService = additionalDetails?.queryParams?.businessService;
}
if(!tenantId){
tenantId = additionalDetails?.queryParams?.tenantId
if (!tenantId) {
tenantId = additionalDetails?.queryParams?.tenantId;
}
const finalParams = {
// consumerCode,
tenantId,
businessService,
connectionNumber:consumerCode,
isOpenPaymentSearch:true
}
data.params = finalParams
connectionNumber: consumerCode,
isOpenPaymentSearch: true,
};
data.params = finalParams;
// data.params.textSearch = finalParams.consumerCode
// const tenantId = Digit.ULBService.getCurrentTenantId();
// data.body = { RequestInfo: data.body.RequestInfo };
Expand All @@ -69,9 +69,9 @@ export const UICustomizations = {
delete data.body.custom;
delete data.body.pagination;
data.options = {
userService:false,
auth:false
}
userService: false,
auth: false,
};
// delete data.body.inbox;
// delete data.params;
return data;
Expand All @@ -85,70 +85,60 @@ export const UICustomizations = {
return link;
},
additionalCustomizations: (row, key, column, value, t, searchResult) => {

switch (key) {
case "OP_CONS_CODE":
return <span className="link">
<Link
to={`/${window.contextPath}/citizen/payment/open-view?tenantId=${row.tenantId}&businessService=WS&consumerCode=${row.connectionNo}`}
>
{String(value ? (column.translate ? t(column.prefix ? `${column.prefix}${value}` : value) : value) : t("ES_COMMON_NA"))}
</Link>
</span>

return (
<span className="link">
<Link
to={`/${window.contextPath}/citizen/payment/open-view?tenantId=${row.tenantId}&businessService=WS&consumerCode=${row.connectionNo}`}
>
{String(value ? (column.translate ? t(column.prefix ? `${column.prefix}${value}` : value) : value) : t("ES_COMMON_NA"))}
</Link>
</span>
);

case "OP_APPLICATION_TYPE":
return <div>
{ value ? t(Digit.Utils.locale.getTransformedLocale(`OP_APPLICATION_TYPE_${value}`)) : t("ES_COMMON_NA")}
</div>

return <div>{value ? t(Digit.Utils.locale.getTransformedLocale(`OP_APPLICATION_TYPE_${value}`)) : t("ES_COMMON_NA")}</div>;

case "OP_APPLICATION_STATUS":
return <div>
{ value ? t(Digit.Utils.locale.getTransformedLocale(`OP_APPLICATION_STATUS_${value}`)) : t("ES_COMMON_NA")}
</div>
return <div>{value ? t(Digit.Utils.locale.getTransformedLocale(`OP_APPLICATION_STATUS_${value}`)) : t("ES_COMMON_NA")}</div>;
case "OP_CONNECTION_TYPE":
return <div>
{ value ? t(Digit.Utils.locale.getTransformedLocale(`OP_CONNECTION_TYPE_${value}`)) : t("ES_COMMON_NA")}
</div>
return <div>{value ? t(Digit.Utils.locale.getTransformedLocale(`OP_CONNECTION_TYPE_${value}`)) : t("ES_COMMON_NA")}</div>;
case "OP_METER_INSTALLATION_DATE":
return <div>
{value ? Digit.DateUtils.ConvertEpochToDate(value) : t("ES_COMMON_NA")}
</div>
return <div>{value ? Digit.DateUtils.ConvertEpochToDate(value) : t("ES_COMMON_NA")}</div>;
case "OP_METER_READING_DATE":
return <div>
{value ? Digit.DateUtils.ConvertEpochToDate(value) : t("ES_COMMON_NA")}
</div>
return <div>{value ? Digit.DateUtils.ConvertEpochToDate(value) : t("ES_COMMON_NA")}</div>;
case "OP_PROPERTY_TYPE":
return <div>
{ value ? t(Digit.Utils.locale.getTransformedLocale(`OP_PROPERTY_TYPE_${value}`)) : t("ES_COMMON_NA")}
</div>
return <div>{value ? t(Digit.Utils.locale.getTransformedLocale(`OP_PROPERTY_TYPE_${value}`)) : t("ES_COMMON_NA")}</div>;
case "OP_PAYER_NAME":
return <div>
{value ? anonymizeHalfString(value) : t("ES_COMMON_NA")}
</div>


return <div>{value ? anonymizeHalfString(value) : t("ES_COMMON_NA")}</div>;

default:
return <span>{t("ES_COMMON_DEFAULT_NA")}</span>
return <span>{t("ES_COMMON_DEFAULT_NA")}</span>;
}
if (key === "OP_BILL_DATE") {
return Digit.DateUtils.ConvertEpochToDate(value);
}

if(key === "OP_BILL_TOTAL_AMT"){
return <span>{`₹ ${value}`}</span>
if (key === "OP_BILL_TOTAL_AMT") {
return <span>{`₹ ${value}`}</span>;
}

if(key === "OP_CONS_CODE") {
return <span className="link">
if (key === "OP_CONS_CODE") {
return (
<span className="link">
<Link
to={`/${window.contextPath}/citizen/payment/open-view?tenantId=${row.tenantId}&businessService=${row.businessService}&consumerCode=${row.consumerCode}`}
>
{String(value ? (column.translate ? t(column.prefix ? `${column.prefix}${value}` : value) : value) : t("ES_COMMON_NA"))}
</Link>
</span>
</span>
);
}
},
Comment on lines +123 to 138
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix unreachable code after switch statement

The code block after the switch statement is unreachable due to the default case that always returns. This means the conditions for 'OP_BILL_DATE', 'OP_BILL_TOTAL_AMT', and 'OP_CONS_CODE' will never be executed.

Move these conditions into the switch statement:

    switch (key) {
        case "OP_CONS_CODE":
          return (
            <span className="link">
              <Link
                to={`/${window.contextPath}/citizen/payment/open-view?tenantId=${row.tenantId}&businessService=WS&consumerCode=${row.connectionNo}`}
              >
                {String(value ? (column.translate ? t(column.prefix ? `${column.prefix}${value}` : value) : value) : t("ES_COMMON_NA"))}
              </Link>
            </span>
          );
+       case "OP_BILL_DATE":
+         return Digit.DateUtils.ConvertEpochToDate(value);
+       case "OP_BILL_TOTAL_AMT":
+         return <span>{`₹ ${value}`}</span>;
        default:
          return <span>{t("ES_COMMON_DEFAULT_NA")}</span>;
    }
-   if (key === "OP_BILL_DATE") {
-     return Digit.DateUtils.ConvertEpochToDate(value);
-   }
-   if (key === "OP_BILL_TOTAL_AMT") {
-     return <span>{`₹ ${value}`}</span>;
-   }
-   if (key === "OP_CONS_CODE") {
-     return (
-       <span className="link">
-         <Link
-           to={`/${window.contextPath}/citizen/payment/open-view?tenantId=${row.tenantId}&businessService=${row.businessService}&consumerCode=${row.consumerCode}`}
-         >
-           {String(value ? (column.translate ? t(column.prefix ? `${column.prefix}${value}` : value) : value) : t("ES_COMMON_NA"))}
-         </Link>
-       </span>
-     );
-   }

Committable suggestion was skipped due to low confidence.

🧰 Tools
🪛 Biome

[error] 119-138: This code is unreachable

... because either this statement, ...

... this statement, ...

... this statement, ...

... this statement, ...

... this statement, ...

... this statement, ...

... this statement, ...

... this statement, ...

... or this statement will return from the function beforehand

(lint/correctness/noUnreachable)

populateReqCriteria: () => {
const { t } = useTranslation();

const tenantId = Digit.ULBService.getCurrentTenantId();
return {
url: "/mdms-v2/v1/_search",
Expand All @@ -171,12 +161,14 @@ export const UICustomizations = {
config: {
enabled: true,
select: (data) => {
const result = data?.MdmsRes?.tenant?.tenants?.filter(row => row?.divisionCode && row?.divisionName)?.map(row => {
return {
...row,
updatedCode:`${row.divisionName} - ${row?.name}`
}
});
const result = data?.MdmsRes?.tenant?.tenants
?.filter((row) => row?.divisionCode && row?.divisionName)
?.map((row) => {
return {
...row,
updatedCode: `${row?.divisionName} - ${t(row?.code)}`,
};
});
Comment on lines +164 to +171
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider memoizing the transformed data

The data transformation and sorting operation could be expensive for large datasets. Consider memoizing the result using useMemo if this component re-renders frequently.

const memoizedResult = useMemo(() => {
  const result = data?.MdmsRes?.tenant?.tenants
    ?.filter((row) => row?.divisionCode && row?.divisionName)
    ?.map((row) => ({
      ...row,
      updatedCode: `${row?.divisionName} - ${t(row?.code)}`,
    }))
    ?.sort((a, b) => {
      const nameA = (a.divisionName || "").toLowerCase().trim();
      const nameB = (b?.divisionName || "").toLowerCase().trim();
      return nameA.localeCompare(nameB);
    });
  return result;
}, [data?.MdmsRes?.tenant?.tenants, t]);

result.sort((a, b) => {
const nameA = (a.divisionName || "").toLowerCase().trim();
const nameB = (b?.divisionName || "").toLowerCase().trim();
Expand All @@ -188,17 +180,16 @@ export const UICustomizations = {
};
},
customValidationCheck: (data) => {

//checking both to and from date are present
const { consumerCode } = data;
if(!consumerCode) return false;
if(consumerCode.length < 10 || consumerCode.length > 25){
if (!consumerCode) return false;
if (consumerCode.length < 10 || consumerCode.length > 25) {
return { warning: true, label: "ES_COMMON_ENTER_VALID_CONSUMER_CODE" };
}
// if ((createdFrom === "" && createdTo !== "") || (createdFrom !== "" && createdTo === ""))
// return { warning: true, label: "ES_COMMON_ENTER_DATE_RANGE" };

return false;
}
}
},
},
};
Loading
Loading