botton navi...
This commit is contained in:
+39
-15
@@ -1,4 +1,4 @@
|
||||
import axios, { AxiosRequestConfig } from "axios";
|
||||
import axios, { AxiosRequestConfig, isAxiosError } from "axios";
|
||||
import * as Keychain from "react-native-keychain";
|
||||
|
||||
/**
|
||||
@@ -14,10 +14,19 @@ export async function apiCall<T>(
|
||||
data?: any,
|
||||
config?: AxiosRequestConfig
|
||||
): Promise<T | null> {
|
||||
// --- Request Logging ---
|
||||
console.log("--- API Request ---");
|
||||
console.log(`[${method}] ${url}`);
|
||||
if (data) {
|
||||
console.log("Payload:", JSON.stringify(data, null, 2));
|
||||
}
|
||||
console.log("-------------------");
|
||||
|
||||
try {
|
||||
// Get saved credentials from Keychain
|
||||
const creds = await Keychain.getGenericPassword();
|
||||
console.log("hihihi", creds);
|
||||
console.log("Keychain Credentials Found:", creds); // Log if creds were found
|
||||
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
...(creds ? { Authorization: `Bearer ${creds.password}` } : {}),
|
||||
@@ -32,22 +41,37 @@ export async function apiCall<T>(
|
||||
headers,
|
||||
});
|
||||
|
||||
// --- Response Logging ---
|
||||
console.log(`--- API Response: [${response.status}] ${url} ---`);
|
||||
// Uncomment the line below to see the full response data in logs
|
||||
// console.log("Response Data:", JSON.stringify(response.data, null, 2));
|
||||
console.log("---------------------------------------");
|
||||
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
if (error.response) {
|
||||
// Server responded with a status other than 2xx
|
||||
console.error(
|
||||
"API Error:",
|
||||
`Status: ${error.response.status}`,
|
||||
`Data: ${JSON.stringify(error.response.data)}`
|
||||
);
|
||||
} else if (error.request) {
|
||||
// Request was made but no response received
|
||||
console.error("API Error: No response received", error.request);
|
||||
console.error("--- API Error ---");
|
||||
console.error(`Request Failed: [${method}] ${url}`);
|
||||
|
||||
if (isAxiosError(error)) {
|
||||
if (error.response) {
|
||||
// Server responded with a status other than 2xx
|
||||
console.error(`Status: ${error.response.status}`);
|
||||
console.error("Data:", JSON.stringify(error.response.data, null, 2));
|
||||
console.error("Headers:", JSON.stringify(error.response.headers, null, 2));
|
||||
} else if (error.request) {
|
||||
// Request was made but no response received
|
||||
console.error("No response received. This could be a network issue or CORS problem.");
|
||||
} else {
|
||||
// Something else went wrong while setting up the request
|
||||
console.error("Error setting up request:", error.message);
|
||||
}
|
||||
} else {
|
||||
// Something else went wrong while setting up the request
|
||||
console.error("API Error:", error.message);
|
||||
// Non-Axios error
|
||||
console.error("An unexpected error occurred:", error.message);
|
||||
}
|
||||
return null; // return null so the caller can handle it
|
||||
console.error("-----------------");
|
||||
|
||||
// Re-throw the error so that the calling function can handle it if needed
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,6 @@ export const GET_JOINED_GROUP_URL = `${BASE_URL}fund/my/join/groups`
|
||||
export const PUT_USER_PROFILE_IMG = `${BASE_URL}user/update/userImg`
|
||||
export const PUT_USER_PROFILE = `${BASE_URL}user/profile/update`
|
||||
export const PUT_USER_STATUS = `${BASE_URL}user/profile/status`
|
||||
export const USER_REQUEST = `${BASE_URL}fund/my-requests`
|
||||
export const GROUP_ALL_MEMBER = `${BASE_URL}fund/group/all/member`
|
||||
export const UPDATE_BANK_URL = `${BASE_URL}user/bank/update`;
|
||||
|
||||
@@ -58,4 +58,23 @@ export const fetchUserProfile = async () => {
|
||||
console.error("❌ Error fetching profile:", error);
|
||||
Alert.alert("Error", "Could not connect to server");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// src/utils/dateFormatter.ts
|
||||
|
||||
export const formatDate = (dateString: string): string => {
|
||||
const date = new Date(dateString);
|
||||
|
||||
if (isNaN(date.getTime())) return "Invalid Date";
|
||||
|
||||
const options: Intl.DateTimeFormatOptions = {
|
||||
day: "2-digit",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
hour12: true,
|
||||
};
|
||||
|
||||
return new Intl.DateTimeFormat("en-GB", options).format(date);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user