diff --git a/assets/src/components/admin/Users.js b/assets/src/components/admin/Users.js
index 48eaffdc..895239ed 100644
--- a/assets/src/components/admin/Users.js
+++ b/assets/src/components/admin/Users.js
@@ -1,5 +1,5 @@
import React, { Component } from "react"
-import { Query } from "react-apollo"
+import { Mutation, Query } from "react-apollo"
import Paper from "@material-ui/core/Paper"
import Table from "@material-ui/core/Table"
@@ -15,6 +15,8 @@ import Loader from "components/Loader"
import EditRecord from "./EditRecord"
import { LIST_USERS } from "queries/users"
+import { UPDATE_USER } from "mutations/user"
+import { CURRENT_USER } from "queries/users"
import {
page,
@@ -34,8 +36,10 @@ export default class Users extends Component {
pageSize: 10
}
- handleEditClick = user => e => {
- this.setState({ user, isEditing: true })
+ handleChangeRoleClick = ( user, UpdateUser ) => e => {
+ UpdateUser({
+ variables: { id: parseInt(user.id), admin: user.admin }
+ })
}
onClose = () => this.setState({ isEditing: false })
@@ -78,47 +82,58 @@ export default class Users extends Component {
editableFields={this.state.editableFields}
/>
)}
-
-
-
- ID
- Email
- Admin
- {/* Actions */}
-
-
-
- {users.entries.map(user => (
-
- {user.id}
- {user.email}
-
- {(user.admin && "Yes") || "-"}
-
- {/*
-
- */}
-
- ))}
-
-
-
-
-
-
-
+
+ {({ data, error, loading }) => {
+ const currentuser = data.currentUser
+
+ return (
+
+
+ ID
+ Email
+ Admin
+ Actions
+
+
+
+ {users.entries.map(user => (
+
+ {user.id}
+ {user.email}
+
+ {(user.admin && "Yes") || "No"}
+
+
+
+ {(UpdateUser, { data }) => (
+
+ )}
+
+
+
+ ))}
+
+
+
+
+
+
+
)
+ }}
+
)
}}
diff --git a/assets/src/mutations/user.js b/assets/src/mutations/user.js
new file mode 100644
index 00000000..e3453931
--- /dev/null
+++ b/assets/src/mutations/user.js
@@ -0,0 +1,15 @@
+import gql from "graphql-tag"
+
+export const UPDATE_USER = gql`
+mutation updateUser(
+ $id: ID!
+ $admin: Boolean!
+) {
+ updateUser(
+ id: $id
+ admin: $admin
+ ) {
+ id
+ admin
+ }
+}`
\ No newline at end of file
diff --git a/lib/orcasite/accounts/user.ex b/lib/orcasite/accounts/user.ex
index a91bd11d..b2428a36 100644
--- a/lib/orcasite/accounts/user.ex
+++ b/lib/orcasite/accounts/user.ex
@@ -19,7 +19,7 @@ defmodule Orcasite.Accounts.User do
def changeset(%User{} = user, attrs) do
user
- |> cast(attrs, [:email, :first_name, :last_name])
+ |> cast(attrs, [:email, :first_name, :last_name, :admin])
|> validate_required([:email])
|> update_change(:email, &String.downcase/1)
|> validate_format(:email, ~r/^.+@.+$/)
diff --git a/lib/orcasite_web/graphql/resolvers/accounts.ex b/lib/orcasite_web/graphql/resolvers/accounts.ex
index 4758b565..e320097a 100644
--- a/lib/orcasite_web/graphql/resolvers/accounts.ex
+++ b/lib/orcasite_web/graphql/resolvers/accounts.ex
@@ -45,7 +45,7 @@ defmodule OrcasiteWeb.Resolvers.Accounts do
def update_user(%{id: user_id, admin: admin}, %{context: %{current_user: current_user}}) do
with user <- Accounts.get_user!(user_id),
- {:ok, user} <- Accounts.update_user(user, %{admin: admin}, current_user) do
+ {:ok, user} <- Accounts.update_user(user, %{admin: !admin}, current_user) do
{:ok, user}
else
error -> error
diff --git a/lib/orcasite_web/graphql/schema.ex b/lib/orcasite_web/graphql/schema.ex
index 5f7eb80a..e91c1789 100644
--- a/lib/orcasite_web/graphql/schema.ex
+++ b/lib/orcasite_web/graphql/schema.ex
@@ -65,7 +65,7 @@ defmodule OrcasiteWeb.Schema do
@desc "Update user details"
field :update_user, :user do
- arg(:id)
+ arg(:id, :id)
arg(:admin, :boolean)
resolve(&Resolvers.Accounts.update_user/2)
end