ui(admin): add role select for user management
This commit is contained in:
parent
58f0bbbb9b
commit
25feeaa9f5
16 changed files with 202 additions and 52 deletions
|
@ -16,7 +16,7 @@ export default (filters?: Filters): Promise<Database[]> => {
|
|||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get('/api/application/databases', { params: { ...params } })
|
||||
http.get('/api/application/databases', { params })
|
||||
.then(response => resolve(
|
||||
(response.data.data || []).map(rawDataToDatabase)
|
||||
))
|
||||
|
|
|
@ -16,7 +16,7 @@ export default (filters?: Filters): Promise<Location[]> => {
|
|||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get('/api/application/locations', { params: { ...params } })
|
||||
http.get('/api/application/locations', { params })
|
||||
.then(response => resolve(
|
||||
(response.data.data || []).map(rawDataToLocation)
|
||||
))
|
||||
|
|
24
resources/scripts/api/admin/roles/searchRoles.ts
Normal file
24
resources/scripts/api/admin/roles/searchRoles.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import http from '@/api/http';
|
||||
import { Role, rawDataToRole } from '@/api/admin/roles/getRoles';
|
||||
|
||||
interface Filters {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export default (filters?: Filters): Promise<Role[]> => {
|
||||
const params = {};
|
||||
if (filters !== undefined) {
|
||||
Object.keys(filters).forEach(key => {
|
||||
// @ts-ignore
|
||||
params['filter[' + key + ']'] = filters[key];
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get('/api/application/roles', { params })
|
||||
.then(response => resolve(
|
||||
(response.data.data || []).map(rawDataToRole)
|
||||
))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -2,6 +2,8 @@ import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/
|
|||
import { useContext } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import { createContext } from '@/api/admin';
|
||||
import { rawDataToDatabase } from '@/api/admin/databases/getDatabases';
|
||||
import { Role } from '@/api/admin/roles/getRoles';
|
||||
|
||||
export interface User {
|
||||
id: number;
|
||||
|
@ -12,13 +14,17 @@ export interface User {
|
|||
firstName: string;
|
||||
lastName: string;
|
||||
language: string;
|
||||
adminRoleId: number | null;
|
||||
rootAdmin: boolean;
|
||||
tfa: boolean;
|
||||
avatarURL: string;
|
||||
roleId: number | null;
|
||||
roleName: string | null;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
relationships: {
|
||||
role: Role | undefined;
|
||||
};
|
||||
}
|
||||
|
||||
export const rawDataToUser = ({ attributes }: FractalResponseData): User => ({
|
||||
|
@ -30,13 +36,17 @@ export const rawDataToUser = ({ attributes }: FractalResponseData): User => ({
|
|||
firstName: attributes.first_name,
|
||||
lastName: attributes.last_name,
|
||||
language: attributes.language,
|
||||
adminRoleId: attributes.admin_role_id,
|
||||
rootAdmin: attributes.root_admin,
|
||||
tfa: attributes['2fa'],
|
||||
avatarURL: attributes.avatar_url,
|
||||
roleId: attributes.role_id,
|
||||
roleName: attributes.role_name,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
|
||||
relationships: {
|
||||
role: attributes.relationships?.role !== undefined && attributes.relationships?.role.object !== 'null_resource' ? rawDataToDatabase(attributes.relationships.role as FractalResponseData) : undefined,
|
||||
},
|
||||
});
|
||||
|
||||
export interface Filters {
|
||||
|
|
|
@ -7,7 +7,7 @@ export interface Values {
|
|||
firstName: string;
|
||||
lastName: string;
|
||||
password: string;
|
||||
roleId: number | null;
|
||||
adminRoleId: number | null;
|
||||
}
|
||||
|
||||
export default (id: number, values: Partial<Values>, include: string[] = []): Promise<User> => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue