diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/components/SORDetailsTemplate.js b/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/components/SORDetailsTemplate.js index 8a4eaf4bd0..1d566d66ed 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/components/SORDetailsTemplate.js +++ b/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/components/SORDetailsTemplate.js @@ -1,4 +1,4 @@ -import { Card, Header, Button, Loader, TextInput, DeleteIcon } from "@egovernments/digit-ui-react-components"; +import { Card, Header, Button, Loader, TextInput, DeleteIcon, Toast } from "@egovernments/digit-ui-react-components"; import React, { useState, useEffect, useCallback } from "react"; import { useTranslation } from "react-i18next"; import SearchBar from "../../../Estimate/src/pageComponents/SearchBar"; @@ -51,6 +51,18 @@ const SORDetailsTemplate = (props) => { }, [SORDetails]); const buttonClick = async () => { + if(formData?.find((ob) => ob?.sorCode === stateData?.selectedSor?.id)) + { + setShowToast({ show: true, label: "RA_SOR_ALREADY_PRESENT_ERROR", error: true }); + setSelectedSOR(null); + return; + } + if(window.location.href.includes("update") && SORDetails?.find((ob) => ob?.sorCode === stateData?.selectedSor?.id)) + { + setShowToast({ show: true, label: "RA_SOR_ALREADY_PRESENT_ERROR", error: true }); + setSelectedSOR(null); + return; + } if (window.location.href.includes("update")) { const sor = transformSOR(stateData?.selectedSor, isUpdate); sor?.sorId && SORDetails?.push({ ...sor, sorType: props?.config?.sorType }); @@ -241,7 +253,7 @@ const SORDetailsTemplate = (props) => { //value={row?.quantity} onChange={(e) => { const { value } = e.target; - if (value ? has4DecimalPlaces(parseFloat(value)) : true) { + if (value ? has4DecimalPlaces(value) : true) { let detailsPicked = window.location.href.includes("update") ? SORDetails : formData; let newSOR = detailsPicked?.map((obj) => { if (obj?.sorCode === row?.sorCode) { diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/pages/employee/CreateRateAnalysis.js b/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/pages/employee/CreateRateAnalysis.js index 4b1c433d01..ac311753fa 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/pages/employee/CreateRateAnalysis.js +++ b/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/pages/employee/CreateRateAnalysis.js @@ -17,6 +17,7 @@ const CreateRateAnalysis = ({ props }) => { const queryStrings = Digit.Hooks.useQueryParams(); // const [sessionFormData, setSessionFormData, clearSessionFormData] = MeasurementSession; const [createState, setState] = useState({ SORDetails:[], extraCharges:[], accessors: undefined, period: {} }); + const [isButtonDisabled, setIsButtonDisabled] = useState(false) const [defaultState, setDefaultState] = useState({ SORDetails:[], extraCharges:[] }); const [showToast, setShowToast] = useState({display: false, error: false}); const [errorMessage, setErrorMessage] = useState(""); @@ -177,11 +178,13 @@ const { isLoading : isallCompositionLoading, data : allcompositionData} = Digit. // Handle form submission const handleCreateRateAnalysis = async (data, action) => { + setIsButtonDisabled(true); if(createState?.SORType !== "Works") { setErrorMessage(t("RA_ONLY_FOR_WORKS")); setShowToast({display:true, error:true}); setIsPopupOpen(false); + setIsButtonDisabled(false); return; } if(createState?.SORDetails?.length <= 0) @@ -189,6 +192,7 @@ const { isLoading : isallCompositionLoading, data : allcompositionData} = Digit. setErrorMessage(t("RA_SOR_DETAILS_MANDATORY")); setShowToast({display:true, error:true}); setIsPopupOpen(false); + setIsButtonDisabled(false); return; } if(createState?.SORDetails?.filter((ob) => ob?.quantity === null || ob?.quantity === "")?.length > 0) @@ -196,13 +200,15 @@ const { isLoading : isallCompositionLoading, data : allcompositionData} = Digit. setErrorMessage(t("RA_SOR_DETAILS_QUANTITY_MANDATORY")); setShowToast({display:true, error:true}); setIsPopupOpen(false); + setIsButtonDisabled(false); return; } if(!isUpdate && allcompositionData?.mdms?.length > 0 && Digit.Utils.date.convertDateToEpoch(createState?.effective_from_date) <= allcompositionData?.mdms?.sort((a, b) => b.data.effectiveFrom - a.data.effectiveFrom)[0].data.effectiveFrom) { - setErrorMessage("Rate analysis cannot be added as a record with the same effective from date already exists."); + setErrorMessage(t("RA_NOT_ADDED_SAME_RECORD_EXIST")); setShowToast({display:true, error:true}); + setIsButtonDisabled(false); return; } @@ -219,11 +225,12 @@ const { isLoading : isallCompositionLoading, data : allcompositionData} = Digit. //call the createMutation for Rate Analysis and route to view page on onSuccess or show error const onError = (resp) => { + setIsButtonDisabled(false); setErrorMessage(resp?.response?.data?.Errors?.[0]?.message); setShowToast({display:true, error:true}); }; const onSuccess = (resp) => { - + setIsButtonDisabled(false); // if(isUpdate) setErrorMessage(`${t("RA_SUCCESS_UPDATE_MEESAGE_1")} ${resp?.mdms[0]?.data?.sorId} ${t("RA_SUCCESS_UPDATE_MESSAGE_2")} ${resp?.mdms?.[0]?.data?.effectiveFrom}`); // else setErrorMessage(`${t("RA_SUCCESS_MEESAGE_1")} ${resp?.mdms[0]?.data?.sorId} ${t("RA_SUCCESS_MESSAGE_2")} ${resp?.mdms?.[0]?.data?.effectiveFrom}`); // setShowToast({display:true, error:false}); @@ -301,6 +308,7 @@ const { isLoading : isallCompositionLoading, data : allcompositionData} = Digit. getFormAccessors={getFormAccessors} defaultValues={{ ...createState }} onSubmit={(_data) => isUpdate && isUpdate !== undefined? validateRateAnalysis() : handleCreateRateAnalysis({..._data,...createState},"SUBMIT")} + isDisabled={isButtonDisabled} fieldStyle={{ marginRight: 0 }} showMultipleCardsWithoutNavs={true} onFormValueChange={onFormValueChange} diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/utils/transformData.js b/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/utils/transformData.js index 80a6e9f93a..dfb172d2cf 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/utils/transformData.js +++ b/frontend/micro-ui/web/micro-ui-internals/packages/modules/RateAnalysis/src/utils/transformData.js @@ -161,7 +161,7 @@ const generateId = async (tenantId = Digit.ULBService.getCurrentTenantId()) => { }; export const has4DecimalPlaces = (value) => { - const regex = /^\d*\.?\d{0,4}$/; + const regex = /^[0-9]*\.?[0-9]{0,4}$/; return regex.test(value); };