Files
tanami-admin-panel/src/Pages/IO_Management/CreateIO/IODetails.jsx

675 lines
18 KiB
React
Raw Normal View History

2024-07-09 14:49:05 +05:30
import React, { useContext, useEffect, useState } from "react";
2024-07-05 15:28:02 +05:30
import FormInputMain from "../../../Components/FormInputMain";
2024-07-09 14:49:05 +05:30
import { useNavigate, useParams } from "react-router-dom";
2024-07-08 20:42:55 +05:30
import { yupResolver } from "@hookform/resolvers/yup";
import { useForm } from "react-hook-form";
import * as yup from "yup";
import GlobalStateContext from "../../../Contexts/GlobalStateContext";
2024-07-09 14:49:05 +05:30
import FullscreenLoaders from "../../../Components/Loaders/FullscreenLoaders";
2024-07-10 12:02:35 +05:30
import { generateUniqueId } from "../../../Contexts/GlobalStateProvider";
2024-07-22 14:50:31 +05:30
import { useGetInvestmentTypesQuery } from "../../../Services/investment.type.service";
import { useGetActiveSponserMasterQuery } from "../../../Services/sponser.service";
import {
useCreateIOMutation,
useGetIOByIdQuery,
useUpdateIOMutation,
} from "../../../Services/io.service";
import ToastBox from "../../../Components/ToastBox";
2024-07-25 12:26:18 +05:30
import {
Input,
Table,
Tbody,
Td,
Th,
Thead,
Tr,
useToast,
} from "@chakra-ui/react";
2024-07-24 19:58:15 +05:30
import { formatDate } from "../../Master/Sponser/Sponsers";
2024-07-25 12:26:18 +05:30
import behrain from "../../../assets/bahrain_flag.png";
import kuwait from "../../../assets/kuwait_flag.png";
import oman from "../../../assets/oman_flag.png";
import qatar from "../../../assets/qatar_flag.png";
import uae from "../../../assets/uae_flag.png";
import saudi from "../../../assets/saudi_arabia_flag.png";
2024-08-05 17:56:07 +05:30
import { formatDatee } from "../../../Components/FormField";
2024-08-16 15:02:02 +05:30
import { removeTrailingZeros } from "../../../Constants/Constants";
2024-07-08 20:42:55 +05:30
const schema = yup.object().shape({
2024-07-22 14:50:31 +05:30
investmentNameEnglish: yup
2024-07-08 20:42:55 +05:30
.string()
.required("IO name in English is required")
.min(3, "IO name in English must be at least 3 characters long")
2024-08-13 13:46:41 +05:30
.max(150, "IO name in English must be at most 150 characters long"),
2024-07-08 20:42:55 +05:30
2024-07-22 14:50:31 +05:30
investmentNameArabic: yup
2024-07-08 20:42:55 +05:30
.string()
.required("IO name in Arabic is required")
.min(3, "IO name in Arabic must be at least 3 characters long")
.max(50, "IO name in Arabic must be at most 50 characters long"),
2024-07-22 14:50:31 +05:30
descriptionEnglish: yup
2024-07-08 20:42:55 +05:30
.string()
.required("Description in English is required")
.min(10, "Description in English must be at least 10 characters long")
.max(1000, "Description in English must be at most 1000 characters long"),
2024-07-08 20:42:55 +05:30
2024-07-22 14:50:31 +05:30
descriptionArabic: yup
2024-07-08 20:42:55 +05:30
.string()
.required("Description in Arabic is required")
.min(10, "Description in Arabic must be at least 10 characters long")
.max(2000, "Description in Arabic must be at most 500 characters long"),
2024-08-12 12:22:01 +05:30
expectedReturnArabic: yup
.string()
2024-08-13 13:46:41 +05:30
.required("Expected return in Arabic is required"),
2024-07-08 20:42:55 +05:30
2024-08-13 13:46:41 +05:30
goalAmount: yup
.number()
.typeError("Goal Amount is must be number")
.required('Goal amount is required')
.positive('Goal amount must be a positive number'),
2024-07-08 20:42:55 +05:30
2024-07-22 14:50:31 +05:30
closingDate: yup
.date()
2024-07-26 17:36:12 +05:30
.notRequired("Closing date is required")
2024-07-22 14:50:31 +05:30
.min(new Date(), "Closing date cannot be in the past"),
2024-07-08 20:42:55 +05:30
2024-07-25 12:26:18 +05:30
holdingPeriod: yup.string().required("Holding period is required"),
2024-08-12 12:22:01 +05:30
holdingPeriodArabic: yup.string().required("Holding period is required"),
2024-07-08 20:42:55 +05:30
2024-07-22 14:50:31 +05:30
// minInvestmentAmount: yup
// .number()
// .required("Minimum investment is required")
// .positive("Minimum investment must be a positive number")
// .min(1, "Minimum investment must be at least 1"),
2024-07-26 17:36:12 +05:30
ISIN: yup.string().notRequired(),
2024-07-22 14:50:31 +05:30
2024-07-26 17:36:12 +05:30
InvestmentDetails: yup.string().notRequired(),
2024-07-22 14:50:31 +05:30
2024-07-26 18:37:07 +05:30
comment: yup.string().notRequired()
.min(10, "Comment must be at least 10 characters long")
2024-07-26 15:03:15 +05:30
.max(100, "Comment must be at most 100 characters long"),
2024-07-22 14:50:31 +05:30
2024-07-08 20:42:55 +05:30
expectedReturn: yup
2024-07-26 18:37:07 +05:30
.string()
.required("Expected return is required"),
2024-07-08 20:42:55 +05:30
});
2024-07-24 19:58:15 +05:30
2024-07-25 12:26:18 +05:30
const IODetails = ({ enableNextTab, index, data }) => {
2024-08-08 19:38:17 +05:30
2024-07-25 12:26:18 +05:30
2024-07-09 14:49:05 +05:30
const params = useParams();
2024-07-08 20:42:55 +05:30
const navigate = useNavigate();
2024-07-22 14:50:31 +05:30
const toast = useToast();
2024-07-08 20:42:55 +05:30
2024-07-24 19:58:15 +05:30
const handleInputChange = (index, newValue) => {
const updatedValues = [...values];
updatedValues[index].value = newValue;
setValues(updatedValues);
};
2024-07-22 14:50:31 +05:30
// ======================[ States ]
const [isLoading, setIsLoading] = useState();
2024-07-09 14:49:05 +05:30
2024-07-22 14:50:31 +05:30
// ======================[ Variables Api ]
const id = params?.id;
2024-07-08 20:42:55 +05:30
2024-07-22 14:50:31 +05:30
// ======================[ Cotext Api ]
2024-08-12 17:22:04 +05:30
const { investmentType, sponser, setIOStatus, setIODetails, setIOloading } =
2024-07-22 14:50:31 +05:30
useContext(GlobalStateContext);
// ======================[ RTK Querry Api ]
2024-07-22 16:52:19 +05:30
2024-07-22 14:50:31 +05:30
const {
data: IObyID,
isLoading: IObyIDisLoading,
error: IObyIDerror,
} = useGetIOByIdQuery(id, { skip: !id });
2024-07-22 14:50:31 +05:30
const [creatIO] = useCreateIOMutation();
const [updateIO] = useUpdateIOMutation();
// ======================[ Selector filter ]
2024-07-25 12:26:18 +05:30
const investmentTypeOptions = data?.investmentType.map(
2024-07-22 14:50:31 +05:30
({ investmentTypeName, id }) => {
2024-07-08 20:42:55 +05:30
return {
2024-07-22 14:50:31 +05:30
label: investmentTypeName,
2024-07-23 16:31:21 +05:30
value: Number(id),
2024-07-08 20:42:55 +05:30
};
}
);
2024-07-24 19:58:15 +05:30
2024-07-25 12:26:18 +05:30
const sponserNameOption = data?.sponsor?.map(({ sponsorName, id }) => {
2024-07-08 20:42:55 +05:30
return {
2024-07-22 14:50:31 +05:30
label: sponsorName,
2024-07-23 16:31:21 +05:30
value: Number(id),
2024-07-08 20:42:55 +05:30
};
});
2024-07-25 12:26:18 +05:30
const miniValue = data?.country?.map(
2024-08-16 15:02:02 +05:30
({ countryName, flagIcon, minInvestmentAmt, countryCode, id, currency }, index) => {
2024-07-25 12:26:18 +05:30
return {
id:id,
country: countryName,
value: minInvestmentAmt,
logo: flagIcon,
2024-08-16 15:02:02 +05:30
curr: currency?.currencyCode,
2024-07-25 12:26:18 +05:30
};
}
);
2024-08-16 15:02:02 +05:30
const minInvestmentById = IObyID?.data?.minInvestmentAmt?.map(({minInvestmentAmt, country, country_xid, })=>{
2024-07-25 12:26:18 +05:30
return{
id:country_xid,
country: country?.countryName,
2024-08-16 15:02:02 +05:30
value: removeTrailingZeros(minInvestmentAmt),
2024-07-25 12:26:18 +05:30
logo: country?.flagIcon,
curr: country?.countryCode,
}
})
const [values, setValues] = useState(id?minInvestmentById:miniValue);
2024-08-08 19:38:17 +05:30
const formatNumber = (num) => {
// Remove non-numeric characters and format with commas
return num.replace(/\D/g, '')
.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
};
2024-07-25 12:26:18 +05:30
// console.log(values);
2024-07-22 14:50:31 +05:30
// ======================[ Validator filter ]
2024-07-08 20:42:55 +05:30
const {
control,
2024-07-09 14:49:05 +05:30
reset,
2024-08-13 13:46:41 +05:30
watch,
2024-07-10 12:02:35 +05:30
setValue,
2024-07-08 20:42:55 +05:30
handleSubmit,
formState: { errors },
} = useForm({
resolver: yupResolver(schema),
});
2024-07-24 19:58:15 +05:30
2024-07-09 14:49:05 +05:30
useEffect(() => {
2024-08-12 17:22:04 +05:30
setIOloading(IObyIDisLoading)
2024-07-24 19:58:15 +05:30
setIODetails({
...IObyID?.data,
});
2024-07-22 14:50:31 +05:30
if (IObyID?.data) {
2024-07-09 14:49:05 +05:30
reset({
2024-07-22 14:50:31 +05:30
investmentNameEnglish: IObyID?.data?.investmentNameEnglish,
investmentNameArabic: IObyID?.data?.investmentNameArabic,
descriptionEnglish: IObyID?.data?.descriptionEnglish,
descriptionArabic: IObyID?.data?.descriptionArabic,
2024-08-16 18:23:55 +05:30
goalAmount: IObyID?.data?.goalAmount,
2024-08-06 13:10:24 +05:30
closingDate: formatDatee(IObyID?.data?.closingDate),
2024-07-22 14:50:31 +05:30
holdingPeriod: IObyID?.data?.holdingPeriod,
ISIN: IObyID?.data?.ISIN,
comment: IObyID?.data?.comment,
expectedReturn: IObyID?.data?.expectedReturn,
investmentType_xid: IObyID?.data?.investmentType_xid,
InvestmentDetails: IObyID?.data?.InvestmentDetails,
minInvestmentAmount: IObyID?.data?.minInvestmentAmount,
2024-08-12 12:22:01 +05:30
holdingPeriodArabic: IObyID?.data?.minInvestmentAmount,
expectedReturnArabic: IObyID?.data?.minInvestmentAmount,
2024-07-09 14:49:05 +05:30
});
}
2024-08-12 17:22:04 +05:30
2024-07-22 14:50:31 +05:30
}, [id, IObyID]);
2024-07-05 15:28:02 +05:30
2024-08-16 15:02:02 +05:30
2024-07-25 12:26:18 +05:30
// const minInvestmentById =
2024-07-22 14:50:31 +05:30
//=======================[ Creator ]
2024-07-05 15:28:02 +05:30
const formFields = [
{
2024-07-08 20:42:55 +05:30
label: "IO Name",
2024-07-22 14:50:31 +05:30
name: "investmentNameEnglish",
2024-07-24 19:58:15 +05:30
value: IObyID?.data?.investmentNameEnglish,
2024-07-05 15:28:02 +05:30
type: "text",
2024-07-22 14:50:31 +05:30
isRequired: true,
2024-07-05 15:28:02 +05:30
section: " ",
width: "49%",
2024-08-13 13:46:41 +05:30
maxLength:150,
helperText:`Maximum length should be 150 characters. You have entered ${watch()?.investmentNameEnglish?.length || 0} characters.`
2024-07-05 15:28:02 +05:30
},
{
label: "IO Name (Arabic)",
2024-07-22 14:50:31 +05:30
name: "investmentNameArabic",
2024-07-24 19:58:15 +05:30
value: IObyID?.data?.investmentNameArabic,
2024-07-05 15:28:02 +05:30
type: "text",
2024-07-22 14:50:31 +05:30
isRequired: true,
2024-07-08 20:42:55 +05:30
arabic: true,
2024-07-05 15:28:02 +05:30
section: " ",
width: "49%",
2024-08-13 13:46:41 +05:30
maxLength:150,
helperText:`Maximum length should be 150 characters. You have entered ${watch()?.investmentNameArabic?.length || 0} characters.`
2024-07-05 15:28:02 +05:30
},
{
2024-07-08 20:42:55 +05:30
label: "Description",
2024-07-22 14:50:31 +05:30
name: "descriptionEnglish",
2024-07-24 19:58:15 +05:30
value: IObyID?.data?.descriptionEnglish,
2024-07-05 15:28:02 +05:30
type: "textarea",
2024-07-22 14:50:31 +05:30
isRequired: true,
2024-07-05 15:28:02 +05:30
section: " ",
width: "49%",
2024-08-13 13:46:41 +05:30
maxLength:1000,
helperText:`Maximum length should be 1000 characters. You have entered ${watch()?.descriptionEnglish?.length || 0} characters.`
2024-07-05 15:28:02 +05:30
},
{
label: "Description (Arabic)",
2024-07-22 14:50:31 +05:30
name: "descriptionArabic",
2024-07-24 19:58:15 +05:30
value: IObyID?.data?.descriptionArabic,
2024-07-05 15:28:02 +05:30
type: "textarea",
2024-07-22 14:50:31 +05:30
isRequired: true,
2024-07-08 20:42:55 +05:30
arabic: true,
2024-07-05 15:28:02 +05:30
section: " ",
width: "49%",
2024-08-13 13:46:41 +05:30
maxLength:1000,
helperText:`Maximum length should be 1000 characters. You have entered ${watch()?.descriptionArabic?.length || 0} characters.`
2024-07-05 15:28:02 +05:30
},
2024-08-12 12:22:01 +05:30
{
label: "Holding Period",
name: "holdingPeriod",
type: "text",
placeHolder: "1Y",
isRequired: true,
section: " ",
width: "49%",
value: IObyID?.data?.holdingPeriod,
2024-08-14 18:48:25 +05:30
maxLength:20,
helperText:`Maximum length should be 20 characters. You have entered ${watch()?.holdingPeriod?.length || 0} characters.`
2024-08-12 12:22:01 +05:30
},
{
label: "Holding Period (Arabic)",
name: "holdingPeriodArabic",
type: "text",
placeHolder: "1Y",
isRequired: true,
arabic: true,
section: " ",
width: "49%",
value: IObyID?.data?.holdingPeriodArabic,
2024-08-14 18:48:25 +05:30
maxLength:20,
helperText:`Maximum length should be 20 characters. You have entered ${watch()?.holdingPeriodArabic?.length || 0} characters.`
2024-08-12 12:22:01 +05:30
},
{
label: "Expected Return",
name: "expectedReturn",
type: "text",
isRequired: true,
section: " ",
width: "49%",
value: IObyID?.data?.expectedReturn,
},
{
label: "Expected Return (Arabic)",
name: "expectedReturnArabic",
type: "text",
isRequired: true,
arabic: true,
section: " ",
width: "49%",
value: IObyID?.data?.expectedReturnArabic,
},
2024-07-23 16:31:21 +05:30
{
label: "Investment Type",
placeHolder: "Select option",
name: "investmentType",
type: "select",
isRequired: true,
section: " ",
width: "32.3%",
options: investmentTypeOptions,
2024-07-24 19:58:15 +05:30
value: IObyID?.data?.investmentType_xid,
2024-07-23 16:31:21 +05:30
},
{
2024-08-16 18:23:55 +05:30
label: "Sponsor Name",
2024-07-23 16:31:21 +05:30
placeHolder: "Select option",
name: "sponserName",
type: "select",
isRequired: true,
options: sponserNameOption,
section: " ",
width: "32.3%",
2024-07-24 19:58:15 +05:30
value: IObyID?.data?.sponsor_xid,
2024-07-23 16:31:21 +05:30
},
2024-07-05 15:28:02 +05:30
{
2024-07-22 14:50:31 +05:30
label: "Goal Amount",
placeHolder: "$00.00",
2024-08-16 18:23:55 +05:30
value: IObyID?.data?.goalAmount,
2024-07-22 14:50:31 +05:30
name: "goalAmount",
type: "number",
isRequired: true,
2024-07-05 15:28:02 +05:30
section: " ",
2024-07-08 20:42:55 +05:30
width: "32.3%",
2024-07-05 15:28:02 +05:30
},
{
2024-07-22 14:50:31 +05:30
label: "Closing Date",
name: "closingDate",
2024-08-05 17:56:07 +05:30
// value: "IObyID?.data?.closingDate",
2024-07-22 14:50:31 +05:30
type: "date",
isRequired: true,
2024-07-05 15:28:02 +05:30
section: " ",
2024-07-08 20:42:55 +05:30
width: "32.3%",
2024-08-06 13:10:24 +05:30
dateValue:formatDatee(IObyID?.data?.closingDate),
// helperText: IObyID && `Current closing date is : ${formatDate(IObyID?.data?.closingDate)}`
2024-07-05 15:28:02 +05:30
},
{
2024-07-22 14:50:31 +05:30
label: "ISIN",
placeHolder: "",
name: "ISIN",
type: "text",
align:"right",
2024-07-05 15:28:02 +05:30
section: " ",
width: "32.3%",
},
{
2024-07-22 14:50:31 +05:30
label: "Investment Details",
placeHolder: "",
name: "InvestmentDetails",
type: "text",
2024-07-05 15:28:02 +05:30
section: " ",
width: "32.3%",
2024-07-24 19:58:15 +05:30
value: IObyID?.data?.InvestmentDetails,
2024-07-05 15:28:02 +05:30
},
2024-07-22 14:50:31 +05:30
{
2024-07-24 19:58:15 +05:30
label: "Minimum Investment",
2024-07-22 14:50:31 +05:30
placeHolder: "Enter comment here",
2024-07-24 19:58:15 +05:30
name: "table",
type: "table",
2024-07-22 14:50:31 +05:30
section: " ",
width: "100%",
2024-07-25 12:26:18 +05:30
isRequired: true,
2024-07-22 14:50:31 +05:30
options: investmentTypeOptions,
2024-07-25 12:26:18 +05:30
handleInputChange: handleInputChange,
2024-07-24 19:58:15 +05:30
value: values,
2024-07-09 14:49:05 +05:30
},
2024-07-22 14:50:31 +05:30
{
label: "Comment",
placeHolder: "Enter comment here",
name: "comment",
type: "textarea",
section: " ",
width: "100%",
options: investmentTypeOptions,
2024-07-24 19:58:15 +05:30
value: IObyID?.data?.comment,
2024-08-13 13:46:41 +05:30
maxLength:100,
helperText:`Maximum length should be 100 characters. You have entered ${watch()?.comment?.length || 0} characters.`
2024-07-09 14:49:05 +05:30
},
];
2024-07-24 19:58:15 +05:30
//=======================[ Editor ]
// const formEditFields = [
// {
// label: "IO Name",
// value: IObyID?.data?.investmentNameEnglish,
// name: "investmentNameEnglish",
// type: "text",
// section: " ",
// width: "49%",
// isRequired: true,
// },
// {
// label: "IO Name (Arabic)",
// name: "investmentNameArabic",
// type: "text",
// value: IObyID?.data?.investmentNameArabic,
// isRequired: true,
// arabic: true,
// section: " ",
// width: "49%",
// },
// {
// label: "Description",
// name: "descriptionEnglish",
// value: IObyID?.data?.descriptionEnglish,
// type: "textarea",
// isRequired: true,
// section: " ",
// width: "49%",
// },
// {
// label: "Description (Arabic)",
// name: "descriptionArabic",
// value: IObyID?.data?.descriptionArabic,
// type: "textarea",
// isRequired: true,
// arabic: true,
// section: " ",
// width: "49%",
// },
// {
// label: "Goal Amount",
// placeHolder: "$00.00",
// value: IObyID?.data?.goalAmount,
// name: "goalAmount",
// type: "number",
// isRequired: true,
// section: " ",
// width: "32.3%",
// },
// {
// label: "Closing Date",
// name: "closingDate",
// type: "date",
// isRequired: true,
// value: IObyID?.data?.closingDate,
// section: " ",
// width: "32.3%",
// },
// {
// label: "Holding Period",
// name: "holdingPeriod",
// value: IObyID?.data?.holdingPeriod,
// type: "number",
// isRequired: true,
// placeHolder: "1Y",
// section: " ",
// width: "32.3%",
// },
// {
// label: "Minimum Investment Amount",
// placeHolder: "$00.00",
// name: "minInvestmentAmount",
// value: IObyID?.data?.minInvestmentAmount,
// type: "number",
// isRequired: true,
// section: " ",
// width: "32.3%",
// },
// {
// label: "ISIN",
// placeHolder: "$00.00",
// name: "ISIN",
// value: IObyID?.data?.ISIN,
// type: "number",
// section: " ",
// width: "32.3%",
// },
// {
// label: "Investment Details",
// placeHolder: "",
// name: "InvestmentDetails",
// value: IObyID?.data?.InvestmentDetails,
// type: "text",
// section: " ",
// width: "32.3%",
// },
// {
// label: "Expected Return Estimated",
// placeHolder: "$00.00",
// name: "expectedReturn",
// type: "number",
// isRequired: true,
// value: IObyID?.data?.expectedReturn,
// section: " ",
// width: "32.3%",
// },
// {
// label: "Investment Type",
// placeHolder: "Select option",
// value: IObyID?.data?.investmentType_xid,
// name: "investmentType_xid",
// type: "select",
// isRequired: true,
// section: " ",
// width: "32.3%",
// options: investmentTypeOptions,
// },
// {
// label: "Sponsorer Name",
// placeHolder: "Select option",
// name: "sponsor_xid",
// type: "select",
// options: sponserNameOption,
// value: IObyID?.data?.sponsor_xid,
// section: " ",
// isRequired: true,
// width: "32.3%",
// },
// {
// label: "Comment",
// placeHolder: "Enter comment here",
// name: "comment",
// type: "textarea",
// value: IObyID?.data?.comment,
// section: " ",
// width: "100%",
// // options: investmentTypeOptions,
// },
// ];
2024-07-09 14:49:05 +05:30
2024-07-22 14:50:31 +05:30
// ======================[ Form Contructor Filter ]
2024-07-05 15:28:02 +05:30
const groupedFields = formFields.reduce((groups, field) => {
const { section } = field;
if (!groups[section]) {
groups[section] = [];
}
groups[section].push(field);
return groups;
}, {});
2024-07-22 14:50:31 +05:30
const onSubmit = async (data) => {
2024-07-25 12:26:18 +05:30
delete data.table;
setIsLoading(true);
// console.log(data);
2024-07-23 16:31:21 +05:30
2024-07-25 12:26:18 +05:30
const updatedMinAmount = values?.map(({id, value})=>{
return {
country_xid:id,
minInvestmentAmt: Number(value)
}
})
2024-07-23 16:31:21 +05:30
const formData = {
...data,
investmentType_xid: Number(data.investmentType),
sponsor_xid: Number(data.sponserName),
2024-07-25 12:26:18 +05:30
minInvestmentAmt:updatedMinAmount
2024-07-23 16:31:21 +05:30
};
2024-07-25 12:26:18 +05:30
// console.log(formData);
// console.log(formData);
2024-07-22 14:50:31 +05:30
if (id) {
2024-07-25 12:26:18 +05:30
const res = await updateIO({ data: formData, id });
2024-07-24 19:58:15 +05:30
console.log(res);
if (res?.data?.statusCode === 200) {
2024-07-25 12:26:18 +05:30
setIsLoading(false);
2024-07-22 14:50:31 +05:30
toast({
render: () => <ToastBox message={res?.data?.message} />,
2024-07-22 14:50:31 +05:30
});
2024-07-24 19:58:15 +05:30
navigate(`/view-io/${id}`);
enableNextTab(index);
} else if(res?.error?.status === 400){
2024-07-25 12:26:18 +05:30
setIsLoading(false);
toast({
render: () => <ToastBox message={res?.error?.data?.message } status={"error"} />,
});
2024-07-22 14:50:31 +05:30
}
} else {
try {
2024-07-23 16:31:21 +05:30
const res = await creatIO(formData);
console.log(res?.error?.status);
2024-07-22 14:50:31 +05:30
if (res?.data?.statusCode === 200) {
2024-07-25 12:26:18 +05:30
setIsLoading(false);
2024-07-22 14:50:31 +05:30
toast({
render: () => <ToastBox message={res?.data?.message} />,
});
2024-07-23 16:31:21 +05:30
navigate(`/view-io/${res?.data?.data}`);
2024-07-22 14:50:31 +05:30
enableNextTab(index);
} else if(res?.error?.status === 400){
setIsLoading(false);
toast({
render: () => <ToastBox message={res?.error?.data?.message } status={"error"} />,
2024-08-16 16:33:20 +05:30
});
}else if(res?.error?.status === 500){
setIsLoading(false);
toast({
render: () => <ToastBox message={res?.error?.data?.message } status={"error"} />,
});
2024-07-22 14:50:31 +05:30
}
} catch (error) {
2024-07-25 12:26:18 +05:30
setIsLoading(false);
2024-07-22 14:50:31 +05:30
console.log(error);
}
}
2024-07-10 12:02:35 +05:30
2024-07-25 12:26:18 +05:30
// ==========================
2024-07-22 14:50:31 +05:30
// if (params?.id) {
// return enableNextTab(index);
// }
// const id = generateUniqueId();
// const status = "Draft";
// // setValue("id", id)
// const updatedData = { ...data, id, ioStatus: status };
2024-07-08 12:22:27 +05:30
2024-07-22 14:50:31 +05:30
// // Add the updated data to the IODetails array
// setIODetails([...IODetails, updatedData]);
// // Navigate to the new route
// navigate(`/create-io/${updatedData?.id}`);
};
2024-07-09 14:49:05 +05:30
2024-07-22 14:50:31 +05:30
return IObyIDisLoading ? (
2024-08-08 19:38:17 +05:30
<FullscreenLoaders height={'70vh'} />
2024-07-22 14:50:31 +05:30
) : (
2024-08-08 19:38:17 +05:30
2024-07-05 15:28:02 +05:30
<FormInputMain
p={0.1}
2024-07-08 20:42:55 +05:30
w={250}
2024-07-05 15:28:02 +05:30
width={"23.8%"}
2024-07-24 19:58:15 +05:30
groupedFields={groupedFields}
2024-07-05 15:28:02 +05:30
control={control}
errors={errors}
2024-07-08 20:42:55 +05:30
onSubmit={handleSubmit(onSubmit)}
2024-07-22 14:50:31 +05:30
btnLoading={isLoading}
submitTitle={id ? "Update" : "Submit"}
2024-07-25 12:26:18 +05:30
></FormInputMain>
2024-07-05 15:28:02 +05:30
);
};
export default IODetails;