Compare commits

...

2 Commits

Author SHA1 Message Date
Mohamed Maoulainine Maoulainine
8024b8070b merge: enstrpenrue issuees
Some checks failed
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 40s
CI / build (push) Failing after 10s
Format / formatting (pull_request) Successful in 5s
2025-04-29 00:34:41 +02:00
Mohamed Maoulainine Maoulainine
008e003207 fix: conflict on Apis 2025-04-29 00:32:03 +02:00
4 changed files with 9 additions and 40 deletions

View File

@ -7,7 +7,7 @@ import {
defaultApiSuccessHandler,
} from "@/services/api";
// Admin API
// Admin API
function getPendingAccounts(
onSuccessHandler?: (response: AxiosResponse) => void,
onErrorHandler?: (error: AxiosError) => void

View File

@ -1,42 +1,11 @@
import { type AxiosError, type AxiosResponse } from "axios";
import Project from "@/ApiClasses/Project";
import SectionCell from "@/ApiClasses/SectionCell";
import {
axiosInstance,
defaultApiErrorHandler,
defaultApiSuccessHandler,
} from "@/services/api";
import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api"
axiosInstance.interceptors.response.use(
(response) => response, // Directly return successful responses.
async (error) => {
const originalRequest = error.config;
if (
((error.response && error.response.status === 401) ||
error.code == "ERR_NETWORK") &&
!originalRequest._retry &&
store.authenticated
) {
originalRequest._retry = true; // Mark the request as retried to avoid infinite loops.
try {
await store.refreshUserToken();
// Update the authorization header with the new access token.
axiosInstance.defaults.headers.common["Authorization"] =
`Bearer ${store.user.token}`;
return axiosInstance(originalRequest); // Retry the original request with the new access token.
} catch (refreshError) {
// Handle refresh token errors by clearing stored tokens and redirecting to the login page.
console.error("Token refresh failed:", refreshError);
localStorage.removeItem("accessToken");
localStorage.removeItem("refreshToken");
router.push("/login");
return Promise.reject(refreshError);
}
}
return Promise.reject(error); // For all other errors, return the error as is.
}
);
// Entrepreneurs API
// Entrepreneurs API
function requestProjectCreation(
projectDetails: Project, // Replace 'any' with a proper type for project details if available
onSuccessHandler?: (response: AxiosResponse) => void,
@ -61,12 +30,12 @@ function requestProjectCreation(
}
function addSectionCell(
sectionCellDetails: SectionCell,
sectionCellDetails: SectionCell, // Replace 'any' with a proper type for section cell details if available
onSuccessHandler?: (response: AxiosResponse) => void,
onErrorHandler?: (error: AxiosError) => void
): void {
axiosInstance
.post("/entrepreneur/sectionCells", sectionCellDetails.toPlainObject()) // <-- Ici
.post("/entrepreneur/sectionCells", sectionCellDetails.toPlainObject())
.then((response) => {
if (onSuccessHandler) {
onSuccessHandler(response);

View File

@ -6,7 +6,7 @@ import {
defaultApiSuccessHandler,
} from "@/services/api";
// Shared API
// Shared API
function getSectionCellsByDate(
projectId: number,
sectionId: number,

View File

@ -6,7 +6,7 @@ import {
defaultApiSuccessHandler,
} from "@/services/api";
// Unauth API
// Unauth API
function finalizeAccount(
onSuccessHandler?: (response: AxiosResponse) => void,
onErrorHandler?: (error: AxiosError) => void