Merge branch 'Sprint-10' into dev

This commit is contained in:
Swapnil Bendal
2025-01-08 15:43:22 +05:30
3 changed files with 113 additions and 19 deletions

View File

@@ -167,7 +167,7 @@ const DashboardLayout = ({ isOnline }) => {
return (
<span className="d-flex align-items-end gap-2">
<RiExchangeBoxLine className="h4 m-0 fw-normal" />
Echange rate
Exchange rate
</span>
);
case path.startsWith("/create-io"):

View File

@@ -221,7 +221,7 @@ const InvestorDetails = () => {
variant={"solid"}
>
{/* {item.KYCStatus ? "Completed" : "Not complete"} */}
{item?.KYCStatus === true ? "Completed" : "NotCompleted"}
{item?.KYCStatus === true ? "Completed" : "Not Completed"}
</Text>
</Box>
),
@@ -321,7 +321,7 @@ const InvestorDetails = () => {
KYC Status
</option>
<option value="">KYC Status</option>
<option value="0">Incompleted</option>
<option value="0">Not Completed</option>
<option value="1">Completed</option>
</Select>
@@ -337,7 +337,7 @@ const InvestorDetails = () => {
Country
</option>
<option value="">All</option>
<option value="1">Behrain</option>
<option value="1">Bahrain</option>
<option value="2">Kuwait</option>
<option value="3">Oman</option>
<option value="4">Qatar</option>

View File

@@ -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 (
<>
<Drawer
@@ -100,18 +180,13 @@ const EditExchangeRate = ({
onClose={onClose}
finalFocusRef={btnRef}
>
<form
onSubmit={(e) => {
e.preventDefault();
setAlert(true);
}}
>
<form onSubmit={(e) => checkValidate(e)}>
<DrawerOverlay />
<DrawerContent>
<DrawerCloseButton />
<DrawerHeader fontSize={"md"}>Edit rate</DrawerHeader>
{isLoading ? (
{isFetching ? (
<FullscreenLoaders />
) : (
<>
@@ -153,16 +228,26 @@ const EditExchangeRate = ({
<Text fontSize={"sm"}>{formatDate(getTomorrowDate())}</Text>
</FormControl>
<FormControl mb={4} isRequired>
<FormControl mb={4} isRequired isInvalid={!!rateError}>
<FormLabel fontSize={"sm"}>Rate</FormLabel>
<Input
required
type="number"
placeholder="Type rate here..."
size={"sm"}
value={rate}
onChange={(e) => 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 && (
<Text color="red.500" fontSize="sm" mt={1}>
{rateError}
</Text>
)}
</FormControl>
</DrawerBody>
<DrawerFooter>
@@ -173,6 +258,15 @@ const EditExchangeRate = ({
size={"sm"}
mr={3}
onClick={onClose}
// onClick={() => {
// window.location.reload();
// onClose();
// }}
// onClick={() => {
// setRate("");
// setRateError("");
// onClose();
// }}
>
Cancel
</Button>