step 1 api
This commit is contained in:
1 parent
32b1347223
commit
13b17037c9
20 files changed
+1997
-143
No files matched your search
@@ -0,0 +1,28 @@
|
||||
export const API_ENDPOINTS = {
|
||||
LOGOUT: "logout",
|
||||
TERMS_AND_POLICIES_PRIVACY:"terms-and-policies",
|
||||
// registration api's
|
||||
PERSONAL_DETAILS_MASTER :"personal_details_masters",
|
||||
CASTE_MASTER : "get_caste_masters",
|
||||
SUB_CASTE_MASTER : "get_sub_caste_masters",
|
||||
CITY_MASTER : "get_district_masters",
|
||||
STAR_MASTER : "get_star_masters",
|
||||
MOBILE_SEND_OTP: "send_otp",
|
||||
MOBILE_VERIFY_OTP: "verify_otp",
|
||||
|
||||
EDUCATION_DETAILS_MASTER: "educational_details_masters",
|
||||
EDUCATION_LIST_API:"get_education",
|
||||
|
||||
FAMILY_DETAILS_MASTER: "family_details_masters", // family details master api
|
||||
|
||||
LIFESTYLE_DETAILS_MASTER:"lifetstyle_details_masters",
|
||||
|
||||
PREFERED_PARTNER_DETAILS_MASTER:"prefered_details_masters",
|
||||
|
||||
REGISTER_STEP1: "register", // register api
|
||||
REGISTER_STEP2:"update_educational_details", // educational details updated api
|
||||
REGSITER_STEP3:"update_family_details", // family details updated api
|
||||
REGISTER_STEP4:"update_lifestyle_details", // lifestyle details updated api
|
||||
REGISTER_STEP5:"update_preferred_details", // partner preference details updated api
|
||||
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
import axiosInstance from "./axiosInstance";
|
||||
import { API_ENDPOINTS } from "./apiEndpoints";
|
||||
|
||||
export const sendOtpAPI = async (mobile) => {
|
||||
const res = await axiosInstance.post(API_ENDPOINTS.MOBILE_SEND_OTP, {
|
||||
mobile,
|
||||
});
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const verifyOtpAPI = async ({ mobile, otp }) => {
|
||||
const res = await axiosInstance.post(API_ENDPOINTS.MOBILE_VERIFY_OTP, {
|
||||
mobile,
|
||||
otp,
|
||||
});
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const logoutAPI = async () => {
|
||||
const res = await axiosInstance.post(API_ENDPOINTS.LOGOUT);
|
||||
return res.data;
|
||||
};
|
||||
@@ -0,0 +1,189 @@
|
||||
import axios from "axios";
|
||||
import { API_ENDPOINTS } from "./apiEndpoints";
|
||||
|
||||
|
||||
/**
|
||||
* Create an Axios instance with the base URL from environment variables
|
||||
* and default headers for JSON communication.
|
||||
*/
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: import.meta.env.VITE_THIRUKALYANAM_API_BASE_URL ||
|
||||
"https://www.thirukalyanam.amrithaa.net/backend/api/" ,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Create a separate Axios instance for handling multipart file uploads
|
||||
* while sharing the same base URL and authorization mechanism.
|
||||
*/
|
||||
const apiForFiles = axios.create({
|
||||
baseURL: import.meta.env.VITE_THIRUKALYANAM_API_BASE_URL,
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Set Access Token
|
||||
*/
|
||||
export const setAccessToken = (token) => {
|
||||
if (token) {
|
||||
localStorage.setItem("access_token", token); // Store token in localStorage
|
||||
axiosInstance.defaults.headers["Authorization"] = `Bearer ${token}`;
|
||||
apiForFiles.defaults.headers["Authorization"] = `Bearer ${token}`;
|
||||
} else {
|
||||
localStorage.removeItem("access_token");
|
||||
delete axiosInstance.defaults.headers["Authorization"];
|
||||
delete apiForFiles.defaults.headers["Authorization"];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a request interceptor to include the authorization token
|
||||
* in the request headers if it exists in localStorage.
|
||||
*/
|
||||
const addAuthInterceptor = (instance) => {
|
||||
instance.interceptors.request.use(
|
||||
(config) => {
|
||||
const token = localStorage.getItem("access_token");
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => Promise.reject(error)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a response interceptor to handle global error scenarios,
|
||||
* such as redirecting to the login page on a 401 Unauthorized error.
|
||||
*/
|
||||
const addErrorInterceptor = (instance) => {
|
||||
instance.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response && error.response.status === 401) {
|
||||
console.error("Unauthorized access - logging out...");
|
||||
localStorage.removeItem("access_token");
|
||||
// window.location.href = "/";
|
||||
// SAFE redirect (works outside React)
|
||||
window.location.replace("/");
|
||||
} else if (error.response && error.response.status === 403) {
|
||||
window.location.href = "/";
|
||||
// navigate("/");
|
||||
} else if (error.response && error.response.status === 404) {
|
||||
console.error("404 Error - Endpoint not found:", error.config?.url);
|
||||
// Don't redirect for 404, let component handle it
|
||||
} else if (error.response && error.response.status >= 500) {
|
||||
console.error("Server error:", error.response?.data);
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Apply interceptors to both instances
|
||||
addAuthInterceptor(axiosInstance);
|
||||
addAuthInterceptor(apiForFiles);
|
||||
|
||||
addErrorInterceptor(axiosInstance);
|
||||
addErrorInterceptor(apiForFiles);
|
||||
|
||||
/**
|
||||
* Clear all user data from the browser: localStorage, sessionStorage, and cookies.
|
||||
*/
|
||||
export const clearUserData = () => {
|
||||
try {
|
||||
// Clear localStorage
|
||||
localStorage.clear();
|
||||
|
||||
// Clear sessionStorage
|
||||
sessionStorage.clear();
|
||||
|
||||
// Clear cookies
|
||||
document.cookie.split(";").forEach((cookie) => {
|
||||
const [name] = cookie.split("=");
|
||||
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/`;
|
||||
});
|
||||
|
||||
// Remove authorization headers from Axios instances
|
||||
delete axiosInstance.defaults.headers["Authorization"];
|
||||
delete apiForFiles.defaults.headers["Authorization"];
|
||||
|
||||
console.log("User data cleared from browser.");
|
||||
// Add redirect to ensure all tabs show login page
|
||||
// window.location.href = '/';
|
||||
} catch (error) {
|
||||
console.error("Error clearing user data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
export const urlToFile = async (url, filename = "file") => {
|
||||
try {
|
||||
// Use your axios instance to request the URL as a Blob
|
||||
const response = await apiForFiles.get(url, {
|
||||
responseType: "blob",
|
||||
});
|
||||
|
||||
// Axios header keys are lowercase
|
||||
const contentType =
|
||||
response.headers["content-type"] ||
|
||||
"*"(
|
||||
// Guess MIME type based on filename extension
|
||||
filename.toLowerCase().endsWith(".png")
|
||||
? "image/png"
|
||||
: filename.toLowerCase().endsWith(".webp")
|
||||
? "image/webp"
|
||||
: filename.toLowerCase().endsWith(".jpg") ||
|
||||
filename.toLowerCase().endsWith(".jpeg")
|
||||
? "image/jpeg"
|
||||
: "application/octet-stream"
|
||||
);
|
||||
|
||||
// Create and return a File object from the blob data
|
||||
return new File([response.data], filename, { type: contentType });
|
||||
} catch (error) {
|
||||
console.error("urlToFile axios error:", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get FCM token from localStorage
|
||||
*/
|
||||
const getFcmToken = () => {
|
||||
return localStorage.getItem("fcm_token");
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear FCM token from localStorage
|
||||
*/
|
||||
const clearFcmToken = () => {
|
||||
localStorage.removeItem("fcm_token");
|
||||
};
|
||||
|
||||
export const logoutAPI = async () => {
|
||||
console.log("Calling logout API...");
|
||||
try {
|
||||
const res = await axiosInstance.post(API_ENDPOINTS.LOGOUT);
|
||||
return res.data; // assuming API returns { message: "Logout successful" }
|
||||
} catch (error) {
|
||||
console.error("Logout API failed:", error);
|
||||
// even if API fails, still clear local storage
|
||||
} finally {
|
||||
console.log("Clearing local storage...");
|
||||
// always clear local storage
|
||||
localStorage.removeItem("access_token");
|
||||
clearFcmToken();
|
||||
window.location.replace("/");
|
||||
}
|
||||
};
|
||||
|
||||
// Export both instances
|
||||
export default axiosInstance;
|
||||
export { apiForFiles };
|
||||
@@ -0,0 +1,57 @@
|
||||
import axiosInstance from "./axiosInstance";
|
||||
import { API_ENDPOINTS } from "./apiEndpoints";
|
||||
|
||||
export const getPersonalDetailsMasters = async () => {
|
||||
const res = await axiosInstance.get(API_ENDPOINTS.PERSONAL_DETAILS_MASTER);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getCasteMasters = async (religion_id) => {
|
||||
const res = await axiosInstance.get(API_ENDPOINTS.CASTE_MASTER, {
|
||||
params: { religion_id },
|
||||
});
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getSubCasteMasters = async (caste_id) => {
|
||||
const res = await axiosInstance.get(API_ENDPOINTS.SUB_CASTE_MASTER, {
|
||||
params: { caste_id },
|
||||
});
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getCityMasters = async (state_id) => {
|
||||
const res = await axiosInstance.get(API_ENDPOINTS.CITY_MASTER, {
|
||||
params: { state_id },
|
||||
});
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getStarMasters = async (raasi_id) => {
|
||||
const res = await axiosInstance.get(API_ENDPOINTS.STAR_MASTER, {
|
||||
params: { raasi_id },
|
||||
});
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getEducationMasters = async () => {
|
||||
const res = await axiosInstance.get(API_ENDPOINTS.EDUCATION_DETAILS_MASTER);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getFamilyMasters = async () => {
|
||||
const res = await axiosInstance.get(API_ENDPOINTS.FAMILY_DETAILS_MASTER);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getLifestyleMasters = async () => {
|
||||
const res = await axiosInstance.get(API_ENDPOINTS.LIFESTYLE_DETAILS_MASTER);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const getPartnerPreferenceMasters = async () => {
|
||||
const res = await axiosInstance.get(
|
||||
API_ENDPOINTS.PREFERED_PARTNER_DETAILS_MASTER
|
||||
);
|
||||
return res.data;
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
import axiosInstance from "./axiosInstance";
|
||||
import { API_ENDPOINTS } from "./apiEndpoints";
|
||||
|
||||
/**
|
||||
* STEP 1 – Personal Details
|
||||
*/
|
||||
export const registerStep1API = async (payload) => {
|
||||
const res = await axiosInstance.post(API_ENDPOINTS.REGISTER_STEP1, payload);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* STEP 2 – Education Details
|
||||
*/
|
||||
export const registerStep2API = async (payload) => {
|
||||
const res = await axiosInstance.post(API_ENDPOINTS.REGISTER_STEP2, payload);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* STEP 3 – Family Details
|
||||
*/
|
||||
export const registerStep3API = async (payload) => {
|
||||
const res = await axiosInstance.post(API_ENDPOINTS.REGSITER_STEP3, payload);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
/**
|
||||
* STEP 4 – Lifestyle Details
|
||||
*/
|
||||
export const registerStep4API = async (payload) => {
|
||||
const res = await axiosInstance.post(API_ENDPOINTS.REGISTER_STEP4, payload);
|
||||
return res.data;
|
||||
};
|
||||
Reference in new issue
Block a user