update
This commit is contained in:
@@ -21,8 +21,17 @@ import { useNavigate } from "react-router-dom";
|
||||
const validationSchema = Yup.object().shape({
|
||||
investorName: Yup.string().required("Investor name is required"),
|
||||
clientId: Yup.string().required("Client ID is required"),
|
||||
transaction_date: Yup.date().required("Date is required").max(new Date(), "Date cannot be in the future"),
|
||||
transaction_amount: Yup.number().required("Amount is required").positive("Amount must be positive"),
|
||||
transaction_date: Yup.date()
|
||||
.required('Date is required')
|
||||
.transform((value, originalValue) => {
|
||||
return originalValue === "" ? null : value; // Convert empty strings to null
|
||||
})
|
||||
.typeError('Please enter a valid date').max(new Date(), "Date cannot be in the future"),
|
||||
transaction_amount: Yup.number()
|
||||
.required("Transaction amount is required")
|
||||
.transform((value, originalValue) => originalValue === "" ? null : value) // Convert empty strings to null
|
||||
.typeError('Transaction amount must be a number') // Custom error message if it's not a number
|
||||
.positive('Transaction amount must be greater than zero'),
|
||||
spportFile_path: Yup.mixed().required("Support file is required"),
|
||||
makerComment: Yup.string().required("Description is required"),
|
||||
});
|
||||
@@ -52,10 +61,15 @@ const CreateRequest = () => {
|
||||
// Convert data to FormData
|
||||
const formData = new FormData();
|
||||
|
||||
// Append each field from the data object to the FormData
|
||||
Object.keys(data).forEach((key) => {
|
||||
formData.append(key, data[key]); // Append other fields
|
||||
});
|
||||
// Append each field from the data object to the FormData
|
||||
Object.keys(data).forEach((key) => {
|
||||
if (key === "spportFile_path" && data[key] instanceof FileList) {
|
||||
// Append the first file from FileList (assuming single file input)
|
||||
formData.append(key, fileType); // This extracts the first file
|
||||
} else {
|
||||
formData.append(key, data[key]); // Append other fields
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
// Make the API call with formData
|
||||
@@ -137,7 +151,7 @@ const CreateRequest = () => {
|
||||
onSubmit={handleSubmit(onSubmit)}
|
||||
>
|
||||
{/* Investor Name Field */}
|
||||
<FormControl w={"49%"} mb={2} isInvalid={errors.investorName}>
|
||||
<FormControl isRequired w={"49%"} mb={2} isInvalid={errors.investorName}>
|
||||
<FormLabel textAlign={"left"} fontSize={"xs"} color={"gray.600"}>
|
||||
Investor name
|
||||
</FormLabel>
|
||||
@@ -162,7 +176,7 @@ const CreateRequest = () => {
|
||||
</FormControl>
|
||||
|
||||
{/* Client ID Field */}
|
||||
<FormControl w={"49%"} mb={2} isInvalid={errors.clientId}>
|
||||
<FormControl isRequired w={"49%"} mb={2} isInvalid={errors.clientId}>
|
||||
<FormLabel textAlign={"left"} fontSize={"xs"} color={"gray.600"}>
|
||||
Client Id
|
||||
</FormLabel>
|
||||
@@ -181,7 +195,7 @@ const CreateRequest = () => {
|
||||
</FormControl>
|
||||
|
||||
{/* Date Field */}
|
||||
<FormControl w={"49%"} mb={2} isInvalid={errors.date}>
|
||||
<FormControl isRequired w={"49%"} mb={2} isInvalid={errors.date}>
|
||||
<FormLabel textAlign={"left"} fontSize={"xs"} color={"gray.600"}>
|
||||
Date
|
||||
</FormLabel>
|
||||
@@ -199,7 +213,7 @@ const CreateRequest = () => {
|
||||
</FormControl>
|
||||
|
||||
{/* Amount Field */}
|
||||
<FormControl w={"49%"} mb={2} isInvalid={errors.amount}>
|
||||
<FormControl isRequired w={"49%"} mb={2} isInvalid={errors.amount}>
|
||||
<FormLabel textAlign={"left"} fontSize={"xs"} color={"gray.600"}>
|
||||
Amount
|
||||
</FormLabel>
|
||||
@@ -217,7 +231,7 @@ const CreateRequest = () => {
|
||||
</FormControl>
|
||||
|
||||
{/* Support File Field with Preview */}
|
||||
<FormControl w={"49%"} mb={2} isInvalid={errors.spportFile_path}>
|
||||
<FormControl w={"49%"} mb={2} isInvalid={errors.spportFile_path}>
|
||||
<FormLabel textAlign={"left"} fontSize={"xs"} color={"gray.600"}>
|
||||
Support file
|
||||
</FormLabel>
|
||||
@@ -258,7 +272,7 @@ const CreateRequest = () => {
|
||||
</FormControl>
|
||||
|
||||
{/* Description Field */}
|
||||
<FormControl w={"100%"} mb={2} isInvalid={errors.makerComment}>
|
||||
<FormControl isRequired w={"100%"} mb={2} isInvalid={errors.makerComment}>
|
||||
<FormLabel textAlign={"left"} fontSize={"xs"} color={"gray.600"}>
|
||||
Description
|
||||
</FormLabel>
|
||||
|
||||
@@ -215,7 +215,7 @@ console.log(investor);
|
||||
</HStack>
|
||||
|
||||
|
||||
<NormalTable
|
||||
{investorDetailsLoading?"Loaading":<NormalTable
|
||||
// centered={true}
|
||||
emptyMessage={`We don't have any Sponers `}
|
||||
tableHeadRow={tableHeadRow}
|
||||
@@ -229,7 +229,7 @@ console.log(investor);
|
||||
selectedRadio={selectedRadio}
|
||||
showRadioButton={true}
|
||||
radio={true}
|
||||
/>
|
||||
/>}
|
||||
|
||||
</ModalBody>
|
||||
</ModalContent>
|
||||
|
||||
Reference in New Issue
Block a user