Add loading UserList for admin user
This commit is contained in:
parent
ba054ef2b9
commit
ac3450239e
4 changed files with 22 additions and 10 deletions
8
frontend/src/api/dtos/UserListResponse.ts
Normal file
8
frontend/src/api/dtos/UserListResponse.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
import {UserDto} from "./UserDto.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API response for delivering a list of users
|
||||||
|
*/
|
||||||
|
export class UserListResponse {
|
||||||
|
valueList: UserDto[] = [];
|
||||||
|
}
|
||||||
|
|
@ -3,13 +3,14 @@ import type {UserDto} from "../dtos/UserDto";
|
||||||
import type {CreateUserRequest} from "../dtos/CreateUserRequest.ts";
|
import type {CreateUserRequest} from "../dtos/CreateUserRequest.ts";
|
||||||
import type {ChangeUserPasswordRequest} from "../dtos/ChangeUserPasswordRequest.ts";
|
import type {ChangeUserPasswordRequest} from "../dtos/ChangeUserPasswordRequest.ts";
|
||||||
import type {CreateUserResponse} from "../dtos/CreateUserResponse.ts";
|
import type {CreateUserResponse} from "../dtos/CreateUserResponse.ts";
|
||||||
|
import type {UserListResponse} from "../dtos/UserListResponse.ts";
|
||||||
|
|
||||||
export async function fetchCurrentUser(): Promise<UserDto> {
|
export async function fetchCurrentUser(): Promise<UserDto> {
|
||||||
return apiClient.get("/user/me");
|
return apiClient.get("/user/me");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchAllUsers(): Promise<UserDto[]> {
|
export async function fetchAllUsers(): Promise<UserListResponse> {
|
||||||
return apiClient.get("/user/list");
|
return apiClient.get("/user/all");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createUser(dto: CreateUserRequest): Promise<CreateUserResponse> {
|
export async function createUser(dto: CreateUserRequest): Promise<CreateUserResponse> {
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ export function IngredientGroupListEditor({ingredientGroupList, onChange}: Ingre
|
||||||
{ingredientGroupList.map((ingGrp, index) => (
|
{ingredientGroupList.map((ingGrp, index) => (
|
||||||
<IngredientGroupEditorListItem
|
<IngredientGroupEditorListItem
|
||||||
index={index}
|
index={index}
|
||||||
|
key={index}
|
||||||
ingredientGroupModel={ingGrp}
|
ingredientGroupModel={ingGrp}
|
||||||
handleUpdate={handleUpdate}
|
handleUpdate={handleUpdate}
|
||||||
handleRemove={handleRemove}
|
handleRemove={handleRemove}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import {createUser, fetchCurrentUser, updateUser} from "../../api/points/UserPoint";
|
import {createUser, fetchAllUsers, fetchCurrentUser, updateUser} from "../../api/points/UserPoint";
|
||||||
import type {UserDto} from "../../api/dtos/UserDto.ts";
|
import type {UserDto} from "../../api/dtos/UserDto.ts";
|
||||||
import ContentBackground from "../basics/ContentBackground";
|
import ContentBackground from "../basics/ContentBackground";
|
||||||
import ContentBody from "../basics/ContentBody";
|
import ContentBody from "../basics/ContentBody";
|
||||||
|
|
@ -17,6 +17,7 @@ import {getRecipeListUrl} from "../../routes.ts";
|
||||||
import TextLinkButton from "../basics/TextLinkButton.tsx";
|
import TextLinkButton from "../basics/TextLinkButton.tsx";
|
||||||
import SelectField from "../basics/SelectField.tsx";
|
import SelectField from "../basics/SelectField.tsx";
|
||||||
import type {CreateUserResponse} from "../../api/dtos/CreateUserResponse.ts";
|
import type {CreateUserResponse} from "../../api/dtos/CreateUserResponse.ts";
|
||||||
|
import type {UserListResponse} from "../../api/dtos/UserListResponse.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UserManagementPage
|
* UserManagementPage
|
||||||
|
|
@ -50,13 +51,14 @@ export default function UserManagementPage() {
|
||||||
const me = await fetchCurrentUser();
|
const me = await fetchCurrentUser();
|
||||||
setCurrentUser(me);
|
setCurrentUser(me);
|
||||||
|
|
||||||
//if (me.role === "admin") {
|
if (me.role === "admin") {
|
||||||
// const allUsers = await fetchAllUsers();
|
const userResponse: UserListResponse = await fetchAllUsers();
|
||||||
// setUsers(allUsers);
|
setUsers(userResponse.valueList);
|
||||||
//} else {
|
console.log(users)
|
||||||
|
} else {
|
||||||
setUsers([me]);
|
setUsers([me]);
|
||||||
setSelectedUser(me);
|
setSelectedUser(me);
|
||||||
//}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Handles selecting a user from the list */
|
/** Handles selecting a user from the list */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue