Skip to content
Prev Previous commit
Next Next commit
idk
  • Loading branch information
f0ssel committed Nov 14, 2022
commit 8a0093225f2fa205380a152c576355d69becbcb4
4 changes: 2 additions & 2 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ export const getApiKey = async (): Promise<TypesGen.GenerateAPIKeyResponse> => {

export const getUsers = async (
options: TypesGen.UsersRequest,
): Promise<TypesGen.User[]> => {
): Promise<TypesGen.GetUsersResponse> => {
const url = getURLWithSearchParams("/api/v2/users", options)
const response = await axios.get<TypesGen.User[]>(url.toString())
const response = await axios.get<TypesGen.GetUsersResponse>(url.toString())
return response.data
}

Expand Down
54 changes: 6 additions & 48 deletions site/src/xServices/users/usersXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const usersMachine =
events: {} as UsersEvent,
services: {} as {
getUsers: {
data: TypesGen.User[]
data: TypesGen.GetUsersResponse
}
createUser: {
data: TypesGen.User
Expand All @@ -132,46 +132,11 @@ export const usersMachine =
updateUserRoles: {
data: TypesGen.User
}
getUserCount: {
data: TypesGen.UserCountResponse
}
},
},
predictableActionArguments: true,
id: "usersState",
type: "parallel",
states: {
count: {
initial: "gettingCount",
states: {
idle: {},
gettingCount: {
entry: "clearGetCountError",
invoke: {
src: "getUserCount",
id: "getUserCount",
onDone: [
{
target: "idle",
actions: "assignCount",
},
],
onError: [
{
target: "idle",
actions: "assignGetCountError",
},
],
},
},
},
on: {
UPDATE_FILTER: {
target: ".gettingCount",
actions: ["assignFilter", "sendResetPage"],
},
},
},
users: {
initial: "startingPagination",
states: {
Expand Down Expand Up @@ -235,6 +200,10 @@ export const usersMachine =
target: "gettingUsers",
actions: "updateURL",
},
UPDATE_FILTER: {
target: "gettingUsers",
actions: ["assignFilter", "sendResetPage"],
},
},
},
confirmUserSuspension: {
Expand Down Expand Up @@ -404,9 +373,6 @@ export const usersMachine =
limit,
})
},
getUserCount: (context) => {
return API.getUserCount(queryToFilter(context.filter))
},
suspendUser: (context) => {
if (!context.userIdToSuspend) {
throw new Error("userIdToSuspend is undefined")
Expand Down Expand Up @@ -462,17 +428,9 @@ export const usersMachine =
userIdToUpdateRoles: (_) => undefined,
}),
assignUsers: assign({
users: (_, event) => event.data,
}),
assignCount: assign({
users: (_, event) => event.data.users,
count: (_, event) => event.data.count,
}),
assignGetCountError: assign({
getCountError: (_, event) => event.data,
}),
clearGetCountError: assign({
getCountError: (_) => undefined,
}),
assignFilter: assign({
filter: (_, event) => event.query,
}),
Expand Down