Implemented a Zustand-based project_id store, expanded project selection/switching to persist project_id,

and centralized backend requests via api/apiFetch (including data provider updates) to inject X-Project-ID.
This commit is contained in:
JIANG
2026-02-11 16:29:18 +08:00
parent a2e6c1f416
commit 9d06226cb4
25 changed files with 192 additions and 62 deletions
+18
View File
@@ -0,0 +1,18 @@
import axios from "axios";
import { config } from "@config/config";
import { useProjectStore } from "@/store/projectStore";
export const API_URL = process.env.NEXT_PUBLIC_API_URL || config.BACKEND_URL;
export const api = axios.create({
baseURL: API_URL,
});
api.interceptors.request.use((request) => {
const projectId = useProjectStore.getState().currentProjectId;
if (projectId) {
request.headers = request.headers ?? {};
request.headers["X-Project-ID"] = projectId;
}
return request;
});
+10
View File
@@ -0,0 +1,10 @@
import { useProjectStore } from "@/store/projectStore";
export const apiFetch = (input: RequestInfo | URL, init: RequestInit = {}) => {
const projectId = useProjectStore.getState().currentProjectId;
const headers = new Headers(init.headers ?? {});
if (projectId) {
headers.set("X-Project-ID", projectId);
}
return fetch(input, { ...init, headers });
};