Skip to content

Commit

Permalink
Merge pull request #637 from odisha-muktasoft/UCEM-782-2
Browse files Browse the repository at this point in the history
Ucem 782 2
  • Loading branch information
Tulika-eGov authored Aug 28, 2024
2 parents 9cd7c33 + 44b21f4 commit a5d9bea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down Expand Up @@ -177,32 +178,37 @@ 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)
{
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)
{
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;
}

Expand All @@ -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});
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit a5d9bea

Please sign in to comment.