first commit
This commit is contained in:
63
src/APIServices/DynamicFormAPI.js
Normal file
63
src/APIServices/DynamicFormAPI.js
Normal file
@@ -0,0 +1,63 @@
|
||||
// src/api/dynamicFormApi.js
|
||||
import apiService from '../APIRequestService/APIService'; // Adjust the path as needed
|
||||
|
||||
// Function to fetch forms
|
||||
// export const fetchForms = async () => {
|
||||
// try {
|
||||
// const response = await apiService.get('/api/form_setup');
|
||||
// console.log(response.data);
|
||||
// return response;
|
||||
// } catch (error) {
|
||||
// throw error; // Rethrow for component handling
|
||||
// }
|
||||
// };
|
||||
|
||||
export const fetchForms = async () => {
|
||||
try {
|
||||
console.log("Fetching forms..."); // Debugging log
|
||||
const response = await apiService.get('/api/form_setup');
|
||||
console.log("API Response:", response.data); // Verify response
|
||||
return response.data; // Ensure you're returning data
|
||||
} catch (error) {
|
||||
console.error("Error in fetchForms:", error); // Log errors
|
||||
throw error; // Rethrow for handling
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Function to build a form
|
||||
export const buildForm = async () => {
|
||||
try {
|
||||
const response = await apiService.post(`/api/form_setup`);
|
||||
console.log(response.data);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error building form:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to delete a form
|
||||
export const deleteForm = async (id) => {
|
||||
try {
|
||||
const response = await apiService.delete(`/api/form_setup/${id}`);
|
||||
console.log(response.data);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error deleting form:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
//Function to update a form
|
||||
export const updateForm = async (id, formData) => {
|
||||
try {
|
||||
const response = await apiService.put(`/api/form_setup/${id}`, formData);
|
||||
console.log(response.data);
|
||||
return response;
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error updating form:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user