Files
ERP_Distribution/distribution_fe/lib/api/users.ts
T
Kalana B. Thilakarathna 531b3a7fef Redesign login UI, add theme toggle, refactor user update
- Redesigned login page with two-panel layout and branding
- Added HexaDistro logo and theme toggle to sidebar/header
- Refactored user update: roles via update endpoint, removed assignRole API/controller
- Extended UpdateUserRequest for username, role, password changes
- UserService.UpdateAsync syncs changes with AuthHex, with rollback
- Stock balances client dedupes by itemId-locationId
- Middleware matcher excludes static assets from auth checks
- Improved localStorage clearing for user context
- Added lucide-react for icons
- Minor UI/code cleanups for consistency and UX
2026-10-19 02:20:14 +05:30

75 lines
2.4 KiB
TypeScript

import { api } from '@/lib/api'
import type { UserResponse, RoleResponse, PermissionResponse } from '@/types/api'
// ─── Users ────────────────────────────────────────────────────────────────────
export interface CreateUserBody {
username: string
password: string
fullName: string
roleId: string
reportsToUserId?: string | null
}
export interface UpdateUserBody {
fullName: string
username?: string
roleId?: string
currentPassword?: string
newPassword?: string
}
export const users = {
list: () =>
api.get<UserResponse[]>('/users').then(r => r.data),
get: (id: string) =>
api.get<UserResponse>(`/users/${id}`).then(r => r.data),
create: (body: CreateUserBody) =>
api.post<UserResponse>('/users', body).then(r => r.data),
update: (id: string, body: UpdateUserBody) =>
api.put<UserResponse>(`/users/${id}`, body).then(r => r.data),
deactivate: (id: string) =>
api.delete(`/users/${id}`),
}
// ─── Roles ────────────────────────────────────────────────────────────────────
export interface RoleBody {
name: string
level: number
}
export const roles = {
list: () =>
api.get<RoleResponse[]>('/roles').then(r => r.data),
get: (id: string) =>
api.get<RoleResponse>(`/roles/${id}`).then(r => r.data),
getPermissions: (id: string) =>
api.get<PermissionResponse[]>(`/roles/${id}/permissions`).then(r => r.data),
create: (body: RoleBody) =>
api.post<RoleResponse>('/roles', body).then(r => r.data),
update: (id: string, body: RoleBody) =>
api.put<RoleResponse>(`/roles/${id}`, body).then(r => r.data),
assignPermissions: (id: string, permissionIds: string[]) =>
api.put(`/roles/${id}/permissions`, { permissionIds }).then(r => r.data),
deactivate: (id: string) =>
api.delete(`/roles/${id}`),
}
// ─── Permissions ──────────────────────────────────────────────────────────────
export const permissions = {
list: () =>
api.get<PermissionResponse[]>('/permissions').then(r => r.data),
}