Skip to content

Feature/68 add edit user#75

Open
Berny-ft wants to merge 4 commits into
developfrom
feature/68-add-edit-user
Open

Feature/68 add edit user#75
Berny-ft wants to merge 4 commits into
developfrom
feature/68-add-edit-user

Conversation

@Berny-ft
Copy link
Copy Markdown
Contributor

Closes #68

Overview

Admins can manage users from /users: create accounts with email, password, name, and role, optionally grant complimentary subscription months (Stripe trial on STRIPE_PRICE_ID), and edit existing users’ email and role from the table pencil action.

Backend

  • createUserAdmin / updateUserAdmin server actions with Zod validation and requireAdmin()
  • Supabase Admin API for auth (createUser / updateUserById) and profiles sync in Drizzle
  • listUsersWithEmails() joins auth.users for real emails and subscription status for Active/Inactive
  • grantComplimentarySubscription() for optional trial months; syncStripeData keeps subscriptions in sync

Frontend

  • Add user dialog (with confirm AlertDialog) and edit user dialog (confirm before save)
  • Controlled form fields; remount on dialog close so validation errors and inputs do not persist
  • Add user button above the filter row, right-aligned, brand color #0040A1
  • shadcn alert-dialog component added for confirmations

Env / setup: SUPABASE_SECRET_KEY (admin client) and STRIPE_PRICE_ID must be set; Stripe product/price must be active for complimentary grants to succeed.

Testing

Manually tested the creation and the modification of users.

Screenshots / Screencasts

image image image image

when you modify the user's email it won't update on the stripe side; I'm not sure that is needed since there's an id tying the two together

Checklist

  • Code is neat, readable, and works
  • Code is commented where appropriate and well-documented
  • Commit messages follow our guidelines
  • Issue number is linked
  • Branch is linked
  • Reviewers are assigned (one of your tech leads)

Berny-ft added 3 commits May 22, 2026 17:14
Add server actions and Zod schemas for creating and updating users via
Supabase Admin API, with profile sync in Drizzle. Add create/edit dialogs
and wire the table edit action to EditUserDialog.
Add subscription_months to the create-user flow and grantComplimentarySubscription
via STRIPE_PRICE_ID trial. Treat trialing subscriptions as active in the users list
and return a generic error when Stripe grant fails after user creation.
Add AlertDialog confirmation before create and save. Remount form state on
dialog close so errors and inputs reset. Align action errors with login/discounts
patterns and block Stripe-internal messages from the UI. Place Add user above
filters with brand styling.
Copilot AI review requested due to automatic review settings May 25, 2026 04:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds admin-facing user management under /users, including creating new users (optionally with complimentary Stripe trial months) and editing existing users’ email/role, backed by new server actions and supporting UI dialogs.

Changes:

  • Added admin server actions (createUserAdmin, updateUserAdmin) with Zod validation and Supabase Admin API integration.
  • Added Stripe helper to grant complimentary subscription trials and updated user listing to treat trialing as Active.
  • Implemented Create/Edit user dialogs and wired the table “edit” (pencil) action to open the edit flow.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
utils/supabase/admin.ts Adds a Supabase Admin client factory for server-side admin operations.
lib/stripe.ts Adds complimentary subscription grant helper and sync step.
components/ui/alert-dialog.tsx Introduces shadcn-style AlertDialog component for confirmation modals.
app/(authenticated)/users/schema.ts Adds Zod schemas for create/update admin user actions.
app/(authenticated)/users/queries.ts Treats trialing subscription status as Active in the users list.
app/(authenticated)/users/actions.ts Implements admin create/update user server actions (Supabase + Drizzle + Stripe trial grant).
app/(authenticated)/users/_components/users-columns.tsx Refactors columns into a factory and wires edit button click handling.
app/(authenticated)/users/_components/users-client.tsx Adds Create/Edit dialogs and connects edit action state to the table.
app/(authenticated)/users/_components/user-admin-dialog.tsx Implements the Create User and Edit User dialog UIs with confirmation prompts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const admin = createAdminClient();
const { error: authError } = await admin.auth.admin.updateUserById(
user_id,
{ email, app_metadata: { user_role: role } },
updatedAt: new Date(),
},
});
} catch {
Comment on lines +168 to +174
} catch {
return {
errors: {
_form: [
"User was created, but the complimentary subscription could not be added. Please try again or contact support.",
],
},
Comment thread lib/stripe.ts
Comment on lines +355 to +359
limit: 1,
});

const status = existing.data[0]?.status;
if (status === "active" || status === "trialing") {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants