feat: add user and role view sheets with detailed information display
- Created UserViewSheet component to display user details including username, full name, role, status, and timestamps. - Created RoleViewSheet component to display role details including name, level, status, creation date, and associated permissions. - Introduced permissions configuration in a new permissions.ts file, defining categories and permission codes for better management. - Implemented middleware for authentication, ensuring access control for protected routes.
This commit is contained in:
@@ -1,41 +1,38 @@
|
||||
import { api } from '@/lib/api'
|
||||
import type {
|
||||
PaginatedResponse,
|
||||
UserResponse,
|
||||
RoleResponse,
|
||||
PermissionResponse,
|
||||
} from '@/types/api'
|
||||
|
||||
import type { PageParams } from './master'
|
||||
import type { UserResponse, RoleResponse, PermissionResponse } from '@/types/api'
|
||||
|
||||
// ─── Users ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface UserBody {
|
||||
export interface CreateUserBody {
|
||||
username: string
|
||||
password: string
|
||||
fullName: string
|
||||
roleId: string
|
||||
reportsToUserId?: string | null
|
||||
password?: string
|
||||
isActive?: boolean
|
||||
}
|
||||
|
||||
export interface UserListParams extends PageParams {
|
||||
roleId?: string
|
||||
search?: string
|
||||
export interface UpdateUserBody {
|
||||
fullName: string
|
||||
}
|
||||
|
||||
export const users = {
|
||||
list: (params?: UserListParams) =>
|
||||
api.get<PaginatedResponse<UserResponse>>('/users', { params }).then(r => r.data),
|
||||
list: () =>
|
||||
api.get<UserResponse[]>('/users').then(r => r.data),
|
||||
|
||||
get: (id: string) =>
|
||||
api.get<UserResponse>(`/users/${id}`).then(r => r.data),
|
||||
|
||||
create: (body: UserBody) =>
|
||||
create: (body: CreateUserBody) =>
|
||||
api.post<UserResponse>('/users', body).then(r => r.data),
|
||||
|
||||
update: (id: string, body: Partial<UserBody>) =>
|
||||
update: (id: string, body: UpdateUserBody) =>
|
||||
api.put<UserResponse>(`/users/${id}`, body).then(r => r.data),
|
||||
|
||||
assignRole: (id: string, roleId: string) =>
|
||||
api.put<UserResponse>(`/users/${id}/role`, { roleId }).then(r => r.data),
|
||||
|
||||
deactivate: (id: string) =>
|
||||
api.delete(`/users/${id}`),
|
||||
}
|
||||
|
||||
// ─── Roles ────────────────────────────────────────────────────────────────────
|
||||
@@ -43,11 +40,6 @@ export const users = {
|
||||
export interface RoleBody {
|
||||
name: string
|
||||
level: number
|
||||
isActive?: boolean
|
||||
}
|
||||
|
||||
export interface RoleWithPermissions extends RoleResponse {
|
||||
permissions: PermissionResponse[]
|
||||
}
|
||||
|
||||
export const roles = {
|
||||
@@ -55,16 +47,22 @@ export const roles = {
|
||||
api.get<RoleResponse[]>('/roles').then(r => r.data),
|
||||
|
||||
get: (id: string) =>
|
||||
api.get<RoleWithPermissions>(`/roles/${id}`).then(r => r.data),
|
||||
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: Partial<RoleBody>) =>
|
||||
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 ──────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user