diff --git a/src/Layout/DefaultLayout.jsx b/src/Layout/DefaultLayout.jsx index 23044a7..56976ec 100644 --- a/src/Layout/DefaultLayout.jsx +++ b/src/Layout/DefaultLayout.jsx @@ -167,7 +167,7 @@ const DashboardLayout = ({ isOnline }) => { return ( - Echange rate + Exchange rate ); case path.startsWith("/create-io"): diff --git a/src/Pages/Investor_Management/InvestorDetails/InvestorDetails.jsx b/src/Pages/Investor_Management/InvestorDetails/InvestorDetails.jsx index d0f3683..8459cc3 100644 --- a/src/Pages/Investor_Management/InvestorDetails/InvestorDetails.jsx +++ b/src/Pages/Investor_Management/InvestorDetails/InvestorDetails.jsx @@ -221,7 +221,7 @@ const InvestorDetails = () => { variant={"solid"} > {/* {item.KYCStatus ? "Completed" : "Not complete"} */} - {item?.KYCStatus === true ? "Completed" : "NotCompleted"} + {item?.KYCStatus === true ? "Completed" : "Not Completed"} ), @@ -321,7 +321,7 @@ const InvestorDetails = () => { KYC Status - + @@ -337,7 +337,7 @@ const InvestorDetails = () => { Country - + diff --git a/src/Pages/Master/ExchangeRate/EditExchangeRate.jsx b/src/Pages/Master/ExchangeRate/EditExchangeRate.jsx index 51d9cbd..5ee8d30 100644 --- a/src/Pages/Master/ExchangeRate/EditExchangeRate.jsx +++ b/src/Pages/Master/ExchangeRate/EditExchangeRate.jsx @@ -30,8 +30,37 @@ import { } from "../../../Services/exchange.rate.service"; import ToastBox from "../../../Components/ToastBox"; import { getTomorrowDate } from "../../../Constants/Constants"; +import * as yup from "yup"; import FullscreenLoaders from "../../../Components/Loaders/FullscreenLoaders"; +// const editExchange = yup.object().shape({ +// rate: yup +// .number() +// .required("Rate is required") +// .positive("Rate must be greater than 0") +// .test( +// "is-decimal", +// "Rate must have at most 8 decimal places", +// (value) => +// value !== undefined && value.toString().match(/^\d+(\.\d{1,8})?$/) +// ), +// }); + +const editExchange = yup.object().shape({ + rate: yup + .string() + .required("Rate is required") + .matches( + /^\d+\.\d{8}$/, + "Rate must have exactly 8 decimal places" + ) + .test( + "is-positive", + "Rate must be greater than 0", + (value) => parseFloat(value) > 0 + ), +}); + // Convert date to YYYY-MM-DD format const formatDateValue = (date) => { if (!date) return ""; @@ -57,8 +86,9 @@ const EditExchangeRate = ({ const toast = useToast(); const {} = useDisclosure(); const [isBtnLoading, setIsBtnLoading] = useState(false); + const [rateError, setRateError] = useState(""); - const { data, isLoading, errors } = useGetExchangeRateByIdQuery(id, { + const { data, isLoading, errors,refetch, isFetching } = useGetExchangeRateByIdQuery(id, { skip: !id, }); @@ -67,17 +97,45 @@ const EditExchangeRate = ({ const [rate, setRate] = useState(""); const [alert, setAlert] = useState(false); + console.log(rate); + + useEffect(() => { + if (id) {refetch()} if (foundObject) { - setRate(foundObject.rate); + const numericRate = parseFloat(foundObject.rate) || 0; // Convert to number or default to 0 if invalid + setRate(numericRate.toFixed(8)); // Set rate with exactly 8 decimal places } - }, [foundObject]); + }, [foundObject, isOpen]); + + + // useEffect(()=>{ + // if (id) { + // refetch() + // } + // },[isOpen]) + + const validateRate = async () => { + try { + await editExchange.validate({ rate }); + setRateError(""); // Clear validation error if valid + return true; + } catch (error) { + setRateError(error.message); // Display validation error + return false; + } + }; const handleSave = async () => { + const isValid = await validateRate(); + if (!isValid) { + return; // Prevent submission if validation fails + } + setIsBtnLoading(true); try { const data = { - rate: rate, + rate, }; const res = await updateExchange({ data, id }); if (res?.data?.statusCode === 200) { @@ -88,9 +146,31 @@ const EditExchangeRate = ({ setAlert(false); onClose(); } - } catch (error) {} + } catch (error) { + setIsBtnLoading(false); + // Handle error + } }; + const checkValidate = async (e) => { + e.preventDefault(); + + // Wait for the validation to complete + const isValid = await validateRate(); + + if (!isValid) { + return; // Prevent submission if validation fails + } else { + setAlert(true); // Only trigger modal if validation passes + } + }; + + useEffect(() => { + if (rate) { + validateRate(); + } + }, [rate]); + return ( <> -
{ - e.preventDefault(); - setAlert(true); - }} - > + checkValidate(e)}> Edit rate - {isLoading ? ( + {isFetching ? ( ) : ( <> @@ -153,16 +228,26 @@ const EditExchangeRate = ({ {formatDate(getTomorrowDate())} - + Rate setRate(e.target.value)} + onChange={(e) => { + const value = e.target.value; + // Match numbers with at most 8 decimal places + if (/^\d*\.?\d{0,8}$/.test(value)) { + setRate(value); + } + }} /> + {rateError && ( + + {rateError} + + )} @@ -173,6 +258,15 @@ const EditExchangeRate = ({ size={"sm"} mr={3} onClick={onClose} + // onClick={() => { + // window.location.reload(); + // onClose(); + // }} + // onClick={() => { + // setRate(""); + // setRateError(""); + // onClose(); + // }} > Cancel