connect users section api, fixed some ui, added some lang support to missed words
This commit is contained in:
55
src/features/shared/api/sharedApi.ts
Normal file
55
src/features/shared/api/sharedApi.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import apiClient from "@/lib/api/client";
|
||||
import { fetchBranches, type BranchListParams, type BranchListResponse } from "@/features/branches/api/branchesApi";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface AddBranchUserPayload {
|
||||
branchId: number;
|
||||
userId: number;
|
||||
}
|
||||
|
||||
// Re-export so shared hooks can import from one place
|
||||
export type { BranchListParams, BranchListResponse };
|
||||
|
||||
// ─── File Upload ──────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Builds the public URL for an uploaded file.
|
||||
* The backend stores files under `{apiOrigin}/file/{filename}`, while the
|
||||
* API base URL itself ends with `/api/admin`.
|
||||
*/
|
||||
export function buildFileUrl(filename: string): string {
|
||||
const apiBase = import.meta.env.VITE_API_BASE_URL || "/api/admin";
|
||||
const origin = apiBase.replace(/\/api\/admin\/?$/, "");
|
||||
return `${origin}/file/${filename}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /file — multipart image upload.
|
||||
* Response envelope: { status, message, code, data: "....png" }.
|
||||
* The axios response interceptor unwraps `data`, so this returns the filename.
|
||||
*/
|
||||
export async function postFile(file: File): Promise<string> {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
const { data } = await apiClient.post<string>("/file", formData, {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
// ─── API Functions ────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* POST /branch-users
|
||||
* Assigns a branch to a user. Used by operators, managers, etc.
|
||||
*/
|
||||
export async function postBranchUser(payload: AddBranchUserPayload): Promise<void> {
|
||||
await apiClient.post("/branch-users", payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy for branch list fetching — kept here so shared hooks
|
||||
* don't import directly from the branches feature.
|
||||
*/
|
||||
export { fetchBranches };
|
||||
Reference in New Issue
Block a user