users page added and functional with basic mui table components

This commit is contained in:
Carter 2024-11-25 14:14:04 -06:00
parent d050fdee55
commit dd522732db
7 changed files with 547 additions and 183 deletions

View file

@ -11,20 +11,21 @@ import { AxiosResponse } from "axios";
import { pond } from "protobuf-ts/pond";
import { User } from "../../models/user";
import { Scope } from "models";
import { or } from "utils/types";
// export interface ListUsersResponse {
// users: User[];
// nextOffset: number;
// total: number;
// }
export interface ListUsersResponse {
users: User[];
nextOffset: number;
total: number;
}
export interface IUserAPIContext {
// listUsers: (
// limit: number,
// offset: number,
// order?: "asc" | "desc",
// by?: string,
// search?: string
// ) => Promise<ListUsersResponse>;
listUsers: (
limit: number,
offset: number,
order?: "asc" | "desc",
by?: string,
search?: string
) => Promise<ListUsersResponse>;
// listProfiles: () => Promise<pond.UserProfile[]>;
listObjectUsers: (scope: Scope) => Promise<any>;
updateObjectUsers: (scope: Scope, users: pond.IUser[]) => Promise<any>;
@ -56,39 +57,39 @@ export default function UserProvider(props: PropsWithChildren<any>) {
const { get, put } = useHTTP();
const [{ as }] = useGlobalState();
// const listUsers = (
// limit: number,
// offset: number,
// order?: "asc" | "desc",
// by?: string,
// search?: string
// ): Promise<ListUsersResponse> => {
// return new Promise((resolve, reject) => {
// get(
// pondURL(
// "/users?limit=" +
// limit +
// "&offset=" +
// offset +
// ("&order=" + (order ? order : "asc")) +
// ("&by=" + (by ? by : "name")) +
// (search ? "&search=" + search : "")
// )
// )
// .then((res: any) => {
// let users: User[] = [];
// if (res && res.data && res.data.users) {
// res.data.users.forEach((raw: any) => users.push(User.any(raw)));
// }
// resolve({
// users: users,
// nextOffset: or(res.data.nextOffset, 0),
// total: or(res.data.total, 0)
// });
// })
// .catch((err: any) => reject(err));
// });
// };
const listUsers = (
limit: number,
offset: number,
order?: "asc" | "desc",
by?: string,
search?: string
): Promise<ListUsersResponse> => {
return new Promise((resolve, reject) => {
get(
pondURL(
"/users?limit=" +
limit +
"&offset=" +
offset +
("&order=" + (order ? order : "asc")) +
("&by=" + (by ? by : "name")) +
(search ? "&search=" + search : "")
)
)
.then((res: any) => {
let users: User[] = [];
if (res && res.data && res.data.users) {
res.data.users.forEach((raw: any) => users.push(User.any(raw)));
}
resolve({
users: users,
nextOffset: or(res.data.nextOffset, 0),
total: or(res.data.total, 0)
});
})
.catch((err: any) => reject(err));
});
};
// const listProfiles = (): Promise<pond.UserProfile[]> => {
// return new Promise((resolve, reject) => {
@ -230,7 +231,7 @@ export default function UserProvider(props: PropsWithChildren<any>) {
return (
<UserAPIContext.Provider
value={{
// listUsers,
listUsers,
// listProfiles,
listObjectUsers,
updateObjectUsers,