first commit

This commit is contained in:
rohit-kumar-fullstack
2026-01-02 17:56:16 +05:30
parent b94f98a764
commit 59fb7e0df4
149 changed files with 9362 additions and 12549 deletions
+48
View File
@@ -0,0 +1,48 @@
import axios from 'axios';
import { NavigationString, showErrorAlert, Variable } from '../Constant/AllImports';
import { setToken } from '../Redux/Slices/Token';
import { store } from '../Redux/Store';
export const apiCall = async <R, D = {}>(
method: 'get' | 'post' | 'patch' | 'delete' | 'put',
url: string,
data?: D,
params?: any,
contentType?: string
): Promise<R> => {
try {
const token: any = store.getState().token.token;
const response = await axios({
method,
url,
data,
params,
// withCredentials: true,
baseURL: Variable.Main_Base,
headers: {
Authentication: `Bearer ${token?.token}`,
'Content-Type': contentType || 'application/json',
},
});
return response.data;
} catch (error: any) {
const errorMessage = error?.response?.data?.error;
{ error?.response?.data?.error && showErrorAlert(error?.response?.data?.error || '') }
console.log(errorMessage, '---------------url error');
if (error?.response?.status === 401) {
store.dispatch(setToken({}));
return {
success: false,
message: 'JWT Error - Token expired or malformed',
} as R;
}
return {
success: false,
message: error?.response?.data?.message || 'No Response From Server',
} as R;
}
};