feat: update UI
This commit is contained in:
+109
-29
@@ -1,5 +1,19 @@
|
||||
import { api } from './api'
|
||||
import type { LoginResponse, Project, ProjectMember, MemberRole, Account, MenuItem, Role, SaveRoleRequest } from '../types'
|
||||
import type {
|
||||
LoginResponse,
|
||||
Project,
|
||||
ProjectMember,
|
||||
MemberRole,
|
||||
UserListItem,
|
||||
MenuItem,
|
||||
Role,
|
||||
SaveRoleRequest,
|
||||
MasterDataItem,
|
||||
SaveMasterDataRequest,
|
||||
PagedResult,
|
||||
UserRoleDetail,
|
||||
User,
|
||||
} from '../types'
|
||||
|
||||
export async function login(username: string, password: string): Promise<LoginResponse> {
|
||||
const { data } = await api.post<LoginResponse>('/api/auth/login', { username, password })
|
||||
@@ -7,36 +21,65 @@ export async function login(username: string, password: string): Promise<LoginRe
|
||||
}
|
||||
|
||||
export async function getMenu(): Promise<MenuItem[]> {
|
||||
const { data } = await api.get<MenuItem[]>('/api/menu')
|
||||
const { data } = await api.get<MenuItem[]>('/api/settings/permission/menu')
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getRoles(): Promise<Role[]> {
|
||||
const { data } = await api.get<Role[]>('/api/roles')
|
||||
export async function getRoles(page = 1, pageSize = 20): Promise<PagedResult<Role>> {
|
||||
const { data } = await api.get<PagedResult<Role>>('/api/settings/permission', { params: { page, pageSize } })
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getRole(id: string): Promise<Role> {
|
||||
const { data } = await api.get<Role>(`/api/roles/${id}`)
|
||||
const { data } = await api.get<Role>(`/api/settings/permission/${id}`)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function createRole(payload: SaveRoleRequest): Promise<Role> {
|
||||
const { data } = await api.post<Role>('/api/roles', payload)
|
||||
const { data } = await api.post<Role>('/api/settings/permission', payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function updateRole(id: string, payload: SaveRoleRequest): Promise<Role> {
|
||||
const { data } = await api.put<Role>(`/api/roles/${id}`, payload)
|
||||
const { data } = await api.put<Role>(`/api/settings/permission/${id}`, payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function deleteRole(id: string): Promise<void> {
|
||||
await api.delete(`/api/roles/${id}`)
|
||||
await api.delete(`/api/settings/permission/${id}`)
|
||||
}
|
||||
|
||||
export async function getProjects(): Promise<Project[]> {
|
||||
const { data } = await api.get<Project[]>('/api/projects')
|
||||
export async function getMasterDataList(group?: string, page = 1, pageSize = 20): Promise<PagedResult<MasterDataItem>> {
|
||||
const { data } = await api.get<PagedResult<MasterDataItem>>('/api/masterdata', { params: { group, page, pageSize } })
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getMasterDataByGroup(group: string): Promise<MasterDataItem[]> {
|
||||
const { data } = await api.get<MasterDataItem[]>(`/api/masterdata/groups/${group}`)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getMasterDataOptions(group: string): Promise<{ label: string; value: string }[]> {
|
||||
const items = await getMasterDataByGroup(group)
|
||||
return items.map((i) => ({ label: i.label, value: i.value }))
|
||||
}
|
||||
|
||||
export async function createMasterData(payload: SaveMasterDataRequest): Promise<MasterDataItem> {
|
||||
const { data } = await api.post<MasterDataItem>('/api/masterdata', payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function updateMasterData(id: string, payload: SaveMasterDataRequest): Promise<MasterDataItem> {
|
||||
const { data } = await api.put<MasterDataItem>(`/api/masterdata/${id}`, payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function deleteMasterData(id: string): Promise<void> {
|
||||
await api.delete(`/api/masterdata/${id}`)
|
||||
}
|
||||
|
||||
export async function getProjects(page = 1, pageSize = 20): Promise<PagedResult<Project>> {
|
||||
const { data } = await api.get<PagedResult<Project>>('/api/projects', { params: { page, pageSize } })
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -72,8 +115,8 @@ export async function deleteProject(id: string): Promise<void> {
|
||||
await api.delete(`/api/projects/${id}`)
|
||||
}
|
||||
|
||||
export async function getMembers(projectId: string): Promise<ProjectMember[]> {
|
||||
const { data } = await api.get<ProjectMember[]>(`/api/projects/${projectId}/members`)
|
||||
export async function getMembers(projectId: string, page = 1, pageSize = 20): Promise<PagedResult<ProjectMember>> {
|
||||
const { data } = await api.get<PagedResult<ProjectMember>>(`/api/projects/${projectId}/members`, { params: { page, pageSize } })
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -90,38 +133,75 @@ export async function removeMember(projectId: string, userId: string): Promise<v
|
||||
await api.delete(`/api/projects/${projectId}/members/${userId}`)
|
||||
}
|
||||
|
||||
export async function getUsers(q?: string) {
|
||||
const { data } = await api.get('/api/users', { params: { q } })
|
||||
export async function updateMemberDocumentPermissions(
|
||||
projectId: string,
|
||||
userId: string,
|
||||
payload: {
|
||||
canViewDocuments: boolean
|
||||
canCreateDocuments: boolean
|
||||
canEditDocuments: boolean
|
||||
canDeleteDocuments: boolean
|
||||
},
|
||||
): Promise<ProjectMember> {
|
||||
const { data } = await api.put<ProjectMember>(`/api/projects/${projectId}/members/${userId}/document-permissions`, payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getAccounts(q?: string): Promise<Account[]> {
|
||||
const { data } = await api.get<Account[]>('/api/accounts', { params: { q } })
|
||||
export async function getProfile(): Promise<User> {
|
||||
const { data } = await api.get<User>('/api/auth/me')
|
||||
return data
|
||||
}
|
||||
|
||||
export async function createAccount(payload: {
|
||||
export async function getUsers(q?: string): Promise<User[]> {
|
||||
const { data } = await api.get<User[]>('/api/users/list', { params: { q } })
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getUsersPaged(q?: string, page = 1, pageSize = 20): Promise<PagedResult<UserListItem>> {
|
||||
const { data } = await api.get<PagedResult<UserListItem>>('/api/users', { params: { q, page, pageSize } })
|
||||
return data
|
||||
}
|
||||
|
||||
export async function createUser(payload: {
|
||||
username: string
|
||||
displayName: string
|
||||
password: string
|
||||
roleId: string
|
||||
}): Promise<Account> {
|
||||
const { data } = await api.post<Account>('/api/accounts', payload)
|
||||
roleId?: string
|
||||
}): Promise<UserListItem> {
|
||||
const { data } = await api.post<UserListItem>('/api/users', payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function updateAccount(
|
||||
export async function updateUser(
|
||||
id: string,
|
||||
payload: { displayName: string; roleId: string; isActive: boolean },
|
||||
): Promise<Account> {
|
||||
const { data } = await api.put<Account>(`/api/accounts/${id}`, payload)
|
||||
payload: { displayName: string; roleId?: string; isActive: boolean },
|
||||
): Promise<UserListItem> {
|
||||
const { data } = await api.put<UserListItem>(`/api/users/${id}`, payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function deleteAccount(id: string): Promise<void> {
|
||||
await api.delete(`/api/accounts/${id}`)
|
||||
export async function deleteUser(id: string): Promise<void> {
|
||||
await api.delete(`/api/users/${id}`)
|
||||
}
|
||||
|
||||
export async function resetAccountPassword(id: string, newPassword: string): Promise<void> {
|
||||
await api.post(`/api/accounts/${id}/reset-password`, { newPassword })
|
||||
}
|
||||
export async function resetUserPassword(id: string, newPassword: string): Promise<void> {
|
||||
await api.post(`/api/users/${id}/reset-password`, { newPassword })
|
||||
}
|
||||
|
||||
export async function getUserRoles(userId: string): Promise<UserRoleDetail> {
|
||||
const { data } = await api.get<UserRoleDetail>(`/api/users/${userId}/roles`)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function assignUserRole(userId: string, roleId: string): Promise<void> {
|
||||
await api.post(`/api/users/${userId}/roles`, { roleId })
|
||||
}
|
||||
|
||||
export async function unassignUserRole(userId: string, roleId: string): Promise<void> {
|
||||
await api.delete(`/api/users/${userId}/roles/${roleId}`)
|
||||
}
|
||||
|
||||
export async function getUserPermissions(userId: string): Promise<MenuItem[]> {
|
||||
const { data } = await api.get<MenuItem[]>(`/api/users/${userId}/permissions`)
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { api } from './api'
|
||||
import type { DocumentItem, DocumentNode, DocumentType, Task, TaskPriority, TaskStatus } from '../types'
|
||||
import type { DocumentItem, DocumentNode, DocumentType, PagedResult, Task, TaskPriority, TaskStatus } from '../types'
|
||||
|
||||
export async function getDocumentTree(projectId: string): Promise<DocumentNode[]> {
|
||||
const { data } = await api.get<DocumentNode[]>(`/api/projects/${projectId}/documents`)
|
||||
@@ -44,8 +44,10 @@ export async function searchDocuments(q: string): Promise<DocumentNode[]> {
|
||||
export async function getTasks(
|
||||
projectId: string,
|
||||
filters?: { status?: string; priority?: string; assigneeId?: string },
|
||||
): Promise<Task[]> {
|
||||
const { data } = await api.get<Task[]>(`/api/projects/${projectId}/tasks`, { params: filters })
|
||||
page = 1,
|
||||
pageSize = 20,
|
||||
): Promise<PagedResult<Task>> {
|
||||
const { data } = await api.get<PagedResult<Task>>(`/api/projects/${projectId}/tasks`, { params: { ...filters, page, pageSize } })
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -91,4 +93,4 @@ export async function deleteTask(id: string): Promise<void> {
|
||||
export async function searchTasks(q: string): Promise<Task[]> {
|
||||
const { data } = await api.get<Task[]>('/api/tasks/search', { params: { q } })
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user