-
Notifications
You must be signed in to change notification settings - Fork 20
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
Develop #990
Changes from 16 commits
4c4d55d
5039a28
e2b81e4
3f2cc27
5af662d
a56eb86
1dfea84
709fcc6
f69c34f
9080feb
77b818d
51a8bfb
1c68bd4
244a6e3
80cf95e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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} | ||
/> | ||
|
@@ -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]); | ||
|
||
const onError = (error, variables) => { | ||
setErrorInfo(error?.response?.data?.Errors[0]?.code || 'ERROR'); | ||
setErrorInfo(error?.response?.data?.Errors[0]?.code || "ERROR"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 + 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); | ||
}; | ||
|
||
|
@@ -62,7 +62,7 @@ const Response = (props) => { | |
const onSuccess = () => { | ||
setMutationHappened(true); | ||
}; | ||
if (!mutationHappened ) { | ||
if (!mutationHappened) { | ||
if (state.key === "UPDATE") { | ||
mutation.mutate( | ||
{ | ||
|
@@ -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} | ||
|
@@ -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> | ||
|
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 | ||||||||||||||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
|
||||||||||||||
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 }; | ||||||||||||||
|
@@ -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; | ||||||||||||||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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>
- );
- }
🧰 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", | ||||||||||||||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||||||||||||||
|
@@ -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; | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
}, | ||||||||||||||
}, | ||||||||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix useEffect implementation issues.
The cleanup effect has several issues that should be addressed:
!==
) instead of loose equality (!=
)location
dependency isn't defined (should be from react-router)Here's the suggested fix: