-
Notifications
You must be signed in to change notification settings - Fork 0
#239 Allow Admins To Create User Accounts #249
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
Open
b-at-neu
wants to merge
9
commits into
dev
Choose a base branch
from
239-allow-admins-to-create-user-accounts
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a6726fb
Extract upsertAppUser helper from resolveRealUser, add createUserSche…
b-at-neu c29cdbc
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b-at-neu 471490a
#239 address review feedback
b-at-neu 30d2da7
#239 address review feedback
b-at-neu 06e2b01
#239 address review feedback
b-at-neu 1ec2b88
#239 address review feedback
b-at-neu 2a8deef
#239 revert to option a: prisma-only pre-invite, no admin api call
b-at-neu 87c7419
#239 address review feedback
b-at-neu fe5fa58
Merge branch 'dev' into 239-allow-admins-to-create-user-accounts
b-at-neu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| 'use client'; | ||
|
|
||
| import type { ReactNode } from 'react'; | ||
|
|
||
| import { toast } from 'sonner'; | ||
| import type { z } from 'zod/v4'; | ||
|
|
||
| import { createUser } from '@/prisma/actions/users'; | ||
|
|
||
| import { createUserSchema } from '@/lib/constants'; | ||
|
|
||
| import { Checkbox } from '@/components/ui/checkbox'; | ||
| import { | ||
| FormControl, | ||
| FormField, | ||
| FormItem, | ||
| FormLabel, | ||
| FormMessage, | ||
| } from '@/components/ui/form'; | ||
| import { FormDialog } from '@/components/ui/form-dialog'; | ||
| import { Input } from '@/components/ui/input'; | ||
|
|
||
| type CreateUserFormValues = z.infer<typeof createUserSchema>; | ||
|
|
||
| const defaultValues: CreateUserFormValues = { | ||
| email: '', | ||
| name: '', | ||
| isAdmin: false, | ||
| }; | ||
|
|
||
| interface CreateUserDialogProps { | ||
| trigger: ReactNode; | ||
| } | ||
|
|
||
| export function CreateUserDialog({ trigger }: CreateUserDialogProps) { | ||
| async function onSubmit(data: CreateUserFormValues): Promise<boolean> { | ||
| try { | ||
| const result = await createUser(data); | ||
| if (result?.error) { | ||
| toast.error(result.error); | ||
| return false; | ||
| } | ||
| toast.success(data.isAdmin ? 'Admin user created.' : 'User created.'); | ||
| return true; | ||
| } catch { | ||
| toast.error('Something went wrong. Please try again.'); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <FormDialog | ||
| trigger={trigger} | ||
| title="Create User" | ||
| schema={createUserSchema} | ||
| defaultValues={defaultValues} | ||
| onSubmit={onSubmit} | ||
| submitLabel="Create user" | ||
| > | ||
| <FormField | ||
| name="email" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>Email</FormLabel> | ||
| <FormControl> | ||
| <Input type="email" placeholder="user@example.com" {...field} /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
|
|
||
| <FormField | ||
| name="name" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>Name</FormLabel> | ||
| <FormControl> | ||
| <Input placeholder="Optional" {...field} /> | ||
| </FormControl> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
|
|
||
| <FormField | ||
| name="isAdmin" | ||
| render={({ field }) => ( | ||
| <FormItem className="flex flex-row items-center gap-3"> | ||
| <FormControl> | ||
| <Checkbox | ||
| checked={field.value} | ||
| onCheckedChange={field.onChange} | ||
| /> | ||
| </FormControl> | ||
| <FormLabel>Admin</FormLabel> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| </FormDialog> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20260627000000_make_neon_auth_id_nullable/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "User" ALTER COLUMN "neonAuthId" DROP NOT NULL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.