connect users section api, fixed some ui, added some lang support to missed words

This commit is contained in:
Jelaletdin12
2026-08-18 21:41:13 +05:00
parent 0e75c85fe1
commit 7bb37f9b43
24 changed files with 1871 additions and 1543 deletions

View 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 };