added team model, loading user with team
This commit is contained in:
parent
f602a22b1b
commit
5977aa8edf
5 changed files with 118 additions and 46 deletions
|
|
@ -2,11 +2,12 @@ import { createContext, useContext, useReducer, Dispatch } from "react";
|
|||
// import { User } from "../models";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { User } from "../models/user";
|
||||
import { Team } from "../models/team";
|
||||
|
||||
export interface GlobalState {
|
||||
// tags: Tag[];
|
||||
user: User;
|
||||
// team: Team;
|
||||
team: Team;
|
||||
as: string;
|
||||
// firmware: Map<string, Firmware>;
|
||||
// newStructure: boolean;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ import { createContext, PropsWithChildren, useContext } from "react";
|
|||
// import { AxiosResponse } from "axios";
|
||||
import { useHTTP } from "../http";
|
||||
import { pondURL } from "./pond";
|
||||
import { AxiosResponse } from "axios";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { User } from "../../models/user";
|
||||
|
||||
// export interface ListUsersResponse {
|
||||
// users: User[];
|
||||
|
|
@ -25,12 +28,12 @@ export interface IUserAPIContext {
|
|||
// listProfiles: () => Promise<pond.UserProfile[]>;
|
||||
// listObjectUsers: (scope: Scope) => Promise<any>;
|
||||
// updateObjectUsers: (scope: Scope, users: pond.IUser[]) => Promise<any>;
|
||||
getUser: (id: string) => Promise<any>;
|
||||
// getUserWithTeam: (
|
||||
// id: string,
|
||||
// team?: string,
|
||||
// scope?: Scope
|
||||
// ) => Promise<AxiosResponse<pond.GetUserWithTeamResponse>>;
|
||||
getUser: (id: string) => Promise<User>;
|
||||
getUserWithTeam: (
|
||||
id: string,
|
||||
team?: string,
|
||||
scope?: any
|
||||
) => Promise<AxiosResponse<pond.GetUserWithTeamResponse>>;
|
||||
// getProfile: (id: string) => Promise<pond.UserProfile>;
|
||||
// getUsers: (ids: string[]) => Promise<User[]>;
|
||||
// getProfiles: (ids: string[]) => Promise<pond.UserProfile[]>;
|
||||
|
|
@ -122,26 +125,26 @@ export default function UserProvider(props: PropsWithChildren<any>) {
|
|||
});
|
||||
};
|
||||
|
||||
// const getUserWithTeam = (
|
||||
// id: string,
|
||||
// team?: string,
|
||||
// scope?: Scope
|
||||
// ): Promise<AxiosResponse<pond.GetUserWithTeamResponse>> => {
|
||||
// let partial = "/userWithTeam/" + id;
|
||||
// if (scope) partial += "?kind=" + scope.kind + "&key=" + scope.key;
|
||||
// if (team) {
|
||||
// if (partial.includes("?")) {
|
||||
// partial += "&team=" + team;
|
||||
// } else {
|
||||
// partial += "?team=" + team;
|
||||
// }
|
||||
// }
|
||||
// return new Promise(function(resolve, reject) {
|
||||
// get(pondURL(partial))
|
||||
// .then((response: any) => resolve(response))
|
||||
// .catch((error: any) => reject(error));
|
||||
// });
|
||||
// };
|
||||
const getUserWithTeam = (
|
||||
id: string,
|
||||
team?: string,
|
||||
scope?: any
|
||||
): Promise<AxiosResponse<pond.GetUserWithTeamResponse>> => {
|
||||
let partial = "/userWithTeam/" + id;
|
||||
if (scope) partial += "?kind=" + scope.kind + "&key=" + scope.key;
|
||||
if (team) {
|
||||
if (partial.includes("?")) {
|
||||
partial += "&team=" + team;
|
||||
} else {
|
||||
partial += "?team=" + team;
|
||||
}
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
get(pondURL(partial))
|
||||
.then((response: any) => resolve(response))
|
||||
.catch((error: any) => reject(error));
|
||||
});
|
||||
};
|
||||
|
||||
// const getProfile = (id: string): Promise<pond.UserProfile> => {
|
||||
// return new Promise((resolve, reject) => {
|
||||
|
|
@ -218,7 +221,7 @@ export default function UserProvider(props: PropsWithChildren<any>) {
|
|||
// listObjectUsers,
|
||||
// updateObjectUsers,
|
||||
getUser,
|
||||
// getUserWithTeam,
|
||||
getUserWithTeam,
|
||||
// getProfile,
|
||||
// getUsers,
|
||||
// getProfiles,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue