mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 14:06:36 +08:00
4f8970ff5c
- Implemented user API functions for fetching, creating, updating, and managing users. - Created a UsersPage component for displaying and managing users with search and pagination. - Added types for user data and mutation payloads. - Introduced a LegacyRouteRedirect component for handling legacy routes. - Defined settings-related types for better type safety in settings management.
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { apiRequest } from '@/lib/api/client';
|
|
|
|
import type {
|
|
ManageUserAction,
|
|
ManageUserResult,
|
|
UserItem,
|
|
UserMutationPayload,
|
|
} from '@/features/users/types';
|
|
|
|
export function getUsers(page: number) {
|
|
return apiRequest<UserItem[]>(`/user/?p=${page}`);
|
|
}
|
|
|
|
export function searchUsers(keyword: string) {
|
|
return apiRequest<UserItem[]>(`/user/search?keyword=${encodeURIComponent(keyword)}`);
|
|
}
|
|
|
|
export function getUser(id: number) {
|
|
return apiRequest<UserItem>(`/user/${id}`);
|
|
}
|
|
|
|
export function createUser(payload: UserMutationPayload) {
|
|
return apiRequest<void>('/user/', {
|
|
method: 'POST',
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|
|
|
|
export function updateUser(payload: UserMutationPayload & { id: number }) {
|
|
return apiRequest<void>('/user/', {
|
|
method: 'PUT',
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|
|
|
|
export function manageUser(username: string, action: ManageUserAction) {
|
|
return apiRequest<ManageUserResult>('/user/manage', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ username, action }),
|
|
});
|
|
}
|