Skip to content

feat(site): Read users into basic UsersTable #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Set up page
  • Loading branch information
presleyp committed Apr 11, 2022
commit 201b34a1aa2a0f06175683cbaac0946b1bee23eb
2 changes: 1 addition & 1 deletion site/src/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { SettingsPage } from "./pages/settings"
import { TemplatesPage } from "./pages/templates"
import { TemplatePage } from "./pages/templates/[organization]/[template]"
import { CreateWorkspacePage } from "./pages/templates/[organization]/[template]/create"
import { UsersPage } from "./pages/users"
import { UsersPage } from "./pages/UsersPage/UsersPage"
import { WorkspacePage } from "./pages/workspaces/[workspace]"

export const AppRouter: React.FC = () => (
Expand Down
4 changes: 2 additions & 2 deletions site/src/components/ErrorSummary/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from "react"

export interface ErrorSummaryProps {
error: Error | undefined
error: Error | unknown
}

export const ErrorSummary: React.FC<ErrorSummaryProps> = ({ error }) => {
// TODO: More interesting error page

if (typeof error === "undefined") {
if (!(error instanceof Error)) {
return <div>{"Unknown error"}</div>
}

Expand Down
25 changes: 25 additions & 0 deletions site/src/pages/UsersPage/UsersPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useActor } from "@xstate/react"
import React, { useContext } from "react"
import { ErrorSummary } from "../../components/ErrorSummary"
import { UsersTable } from "../../components/UsersTable/UsersTable"
import { XServiceContext } from "../../xServices/StateContext"

export type Role = "Admin" | "Member"

export interface User {
username: string
email: string
siteRole: Role
}

export const UsersPage: React.FC = () => {
const xServices = useContext(XServiceContext)
const [usersState] = useActor(xServices.usersXService)
const { users, getUsersError } = usersState.context

if (usersState.matches("error")) {
return <ErrorSummary error={getUsersError} />
} else {
return <UsersTable users={users} />
}
}
5 changes: 0 additions & 5 deletions site/src/pages/users.tsx

This file was deleted.

7 changes: 5 additions & 2 deletions site/src/xServices/StateContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import React, { createContext } from "react"
import { ActorRefFrom } from "xstate"
import { authMachine } from "./auth/authXService"
import { buildInfoMachine } from "./buildInfo/buildInfoXService"
import { usersMachine } from "./users/usersXService"

interface XServiceContextType {
buildInfoXService: ActorRefFrom<typeof buildInfoMachine>
authXService: ActorRefFrom<typeof authMachine>
buildInfoXService: ActorRefFrom<typeof buildInfoMachine>
usersXService: ActorRefFrom<typeof usersMachine>
}

/**
Expand All @@ -23,8 +25,9 @@ export const XServiceProvider: React.FC = ({ children }) => {
return (
<XServiceContext.Provider
value={{
buildInfoXService: useInterpret(buildInfoMachine),
authXService: useInterpret(authMachine),
buildInfoXService: useInterpret(buildInfoMachine),
usersXService: useInterpret(usersMachine)
}}
>
{children}
Expand Down
7 changes: 5 additions & 2 deletions site/src/xServices/users/usersXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as Types from "../../api/types"

export interface UsersContext {
users: Types.UserResponse[]
pager: Types.Pager
getUsersError: Error | unknown
pager?: Types.Pager
getUsersError?: Error | unknown
}

export type UsersEvent = { type: 'GET_USERS' }
Expand All @@ -24,6 +24,9 @@ export const usersMachine =
},
},
id: "usersState",
context: {
users: [],
},
initial: "gettingUsers",
states: {
gettingUsers: {
Expand Down