Skip to content

Commit b71ede5

Browse files
committed
Update roles to fetch the site roles
1 parent cabe385 commit b71ede5

File tree

5 files changed

+26
-31
lines changed

5 files changed

+26
-31
lines changed

site/src/api/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export const suspendUser = async (userId: TypesGen.User["id"]): Promise<TypesGen
159159
export const updateUserPassword = async (password: string, userId: TypesGen.User["id"]): Promise<undefined> =>
160160
axios.put(`/api/v2/users/${userId}/password`, { password })
161161

162-
export const getOrganizationRoles = async (organizationId: string): Promise<Array<TypesGen.Role>> => {
163-
const response = await axios.get<Array<TypesGen.Role>>(`/api/v2/organizations/${organizationId}/members/roles`)
162+
export const getSiteRoles = async (): Promise<Array<TypesGen.Role>> => {
163+
const response = await axios.get<Array<TypesGen.Role>>(`/api/v2/users/roles`)
164164
return response.data
165165
}

site/src/components/UsersTable/UsersTable.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Box from "@material-ui/core/Box"
2+
import MenuItem from "@material-ui/core/MenuItem"
3+
import Select from "@material-ui/core/Select"
24
import Table from "@material-ui/core/Table"
35
import TableBody from "@material-ui/core/TableBody"
46
import TableCell from "@material-ui/core/TableCell"
@@ -48,7 +50,15 @@ export const UsersTable: React.FC<UsersTableProps> = ({ users, roles, onSuspendU
4850
<TableCell>
4951
<UserCell Avatar={{ username: u.username }} primaryText={u.username} caption={u.email} />{" "}
5052
</TableCell>
51-
<TableCell>{roles.map((r) => r.display_name)}</TableCell>
53+
<TableCell>
54+
<Select multiple value={[]}>
55+
{roles.map((r) => (
56+
<MenuItem key={r.name} value={r.name}>
57+
{r.display_name}
58+
</MenuItem>
59+
))}
60+
</Select>
61+
</TableCell>
5262
<TableCell>
5363
<TableRowMenu
5464
data={u}

site/src/pages/UsersPage/UsersPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const Language = {
1616
const useRoles = () => {
1717
const xServices = useContext(XServiceContext)
1818
const [authState] = useActor(xServices.authXService)
19-
const [rolesState, rolesSend] = useActor(xServices.rolesXService)
19+
const [rolesState, rolesSend] = useActor(xServices.siteRolesXService)
2020
const { roles } = rolesState.context
2121
const { me } = authState.context
2222

site/src/xServices/StateContext.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useNavigate } from "react-router"
44
import { ActorRefFrom } from "xstate"
55
import { authMachine } from "./auth/authXService"
66
import { buildInfoMachine } from "./buildInfo/buildInfoXService"
7-
import { rolesMachine } from "./roles/rolesXService"
7+
import { siteRolesMachine } from "./roles/siteRolesXService"
88
import { usersMachine } from "./users/usersXService"
99
import { workspaceMachine } from "./workspace/workspaceXService"
1010

@@ -13,7 +13,7 @@ interface XServiceContextType {
1313
buildInfoXService: ActorRefFrom<typeof buildInfoMachine>
1414
usersXService: ActorRefFrom<typeof usersMachine>
1515
workspaceXService: ActorRefFrom<typeof workspaceMachine>
16-
rolesXService: ActorRefFrom<typeof rolesMachine>
16+
siteRolesXService: ActorRefFrom<typeof siteRolesMachine>
1717
}
1818

1919
/**
@@ -39,7 +39,7 @@ export const XServiceProvider: React.FC = ({ children }) => {
3939
buildInfoXService: useInterpret(buildInfoMachine),
4040
usersXService: useInterpret(() => usersMachine.withConfig({ actions: { redirectToUsersPage } })),
4141
workspaceXService: useInterpret(workspaceMachine),
42-
rolesXService: useInterpret(rolesMachine),
42+
siteRolesXService: useInterpret(siteRolesMachine),
4343
}}
4444
>
4545
{children}

site/src/xServices/roles/rolesXService.ts renamed to site/src/xServices/roles/siteRolesXService.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,34 @@ import * as API from "../../api"
33
import * as TypesGen from "../../api/typesGenerated"
44
import { displayError } from "../../components/GlobalSnackbar/utils"
55

6-
type RolesContext = {
6+
type SiteRolesContext = {
77
roles?: TypesGen.Role[]
88
getRolesError: Error | unknown
9-
organizationId?: string
109
}
1110

12-
type RolesEvent = {
11+
type SiteRolesEvent = {
1312
type: "GET_ROLES"
1413
organizationId: string
1514
}
1615

17-
export const rolesMachine = createMachine(
16+
export const siteRolesMachine = createMachine(
1817
{
19-
id: "rolesState",
18+
id: "siteRolesState",
2019
initial: "idle",
2120
schema: {
22-
context: {} as RolesContext,
23-
events: {} as RolesEvent,
21+
context: {} as SiteRolesContext,
22+
events: {} as SiteRolesEvent,
2423
services: {
2524
getRoles: {
2625
data: {} as TypesGen.Role[],
2726
},
2827
},
2928
},
30-
tsTypes: {} as import("./rolesXService.typegen").Typegen0,
29+
tsTypes: {} as import("./siteRolesXService.typegen").Typegen0,
3130
states: {
3231
idle: {
3332
on: {
34-
GET_ROLES: {
35-
target: "gettingRoles",
36-
actions: ["assignOrganizationId"],
37-
},
33+
GET_ROLES: "gettingRoles",
3834
},
3935
},
4036
gettingRoles: {
@@ -61,23 +57,12 @@ export const rolesMachine = createMachine(
6157
assignGetRolesError: assign({
6258
getRolesError: (_, event) => event.data,
6359
}),
64-
assignOrganizationId: assign({
65-
organizationId: (_, event) => event.organizationId,
66-
}),
6760
displayGetRolesError: () => {
6861
displayError("Error on get the roles.")
6962
},
7063
},
7164
services: {
72-
getRoles: (ctx) => {
73-
const { organizationId } = ctx
74-
75-
if (!organizationId) {
76-
throw new Error("organizationId not defined")
77-
}
78-
79-
return API.getOrganizationRoles(organizationId)
80-
},
65+
getRoles: () => API.getSiteRoles(),
8166
},
8267
},
8368
)

0 commit comments

Comments
 (0)