Skip to content
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

Adding an admin page to manage a specific user's status #521

Merged
merged 2 commits into from
Jan 8, 2023

Conversation

fozziethebeat
Copy link
Collaborator

This includes:

  • A new web API route for updating the user's role
  • A new page that displays a user's data in a form and allows updating the role via a selector
  • Use of a new form library that can support error handling and supposedly simplifies things (Formik)
  • A prisma seed library to inject a bunch of fake users into the database

Not done yet:

  • pagination in the admin user page
  • nice styling. The manage user page looks...odd

@fozziethebeat fozziethebeat marked this pull request as ready for review January 8, 2023 07:23
Copy link
Collaborator

@AbdBarho AbdBarho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formik is okay, I used it one or two times before.

return (
<>
<Head>
<title>Open Assistant</title>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manage Users - Open Assistant

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

initialValues={user}
onSubmit={(values) => {
trigger(values);
}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: onSubmit:trigger

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm run build really didn't like that due to some type issues. Will leave as is for now.

Comment on lines 8 to 14
const token = await getToken({ req });

// Return nothing if the user isn't registered or if the user isn't an admin.
if (!token || token.role !== "admin") {
res.status(403).end();
return;
}
Copy link
Collaborator

@AbdBarho AbdBarho Jan 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we extract these to a middleware?

maybe something like:

const handler = withAdmin(async (token, req, res) => {
...
});

or maybe

const handler = withRole("admin", async (token, req, res) => {
...
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I looked at using the actual middleware.ts but it looks a bit too messy. A wrapper is a lot cleaner. makes me miss RedwoodJS where they built this into the graphQL handler.

@AbdBarho AbdBarho merged commit af1e9c3 into main Jan 8, 2023
@AbdBarho AbdBarho deleted the 237-manage-user-page branch January 8, 2023 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants