Repository navigation
Add user invitation system with UI and auto-accept feature #114
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c7ffd5f
Add user invitation UI
ATechAdventurer 04f7495
Implement invite system with CRUD operations and auto-accept feature
ATechAdventurer 5a278b1
Update app/lib/services/inviteService.ts
ATechAdventurer d836515
Update app/api/invites/[inviteId]/route.ts
ATechAdventurer ca68958
Update app/api/domain-invites/[domainId]/route.ts
ATechAdventurer 488b780
Update app/api/invites/[inviteId]/route.ts
ATechAdventurer 411ba97
Fix updatedAt field to auto-update in UserInvite model
ATechAdventurer c32fa6a
Format invite creation date in UsersDetails component
ATechAdventurer 0fe74cf
Refactor UsersTab to use useCallback for back navigation
ATechAdventurer f7bcb4b
Enhance userService to include role management and improve user profi…
ATechAdventurer dfd39ba
Add pending invites management to UsersTab component. Implemented fet…
ATechAdventurer 57a8843
Merge branch 'dev' into cameron/eng-884-new-invite-flow
ATechAdventurer 4df993d
Refactor user invite terminology to member invite in UsersDetails and…
ATechAdventurer 4bb2570
Implement user invitation flow enhancements in UsersDetails component…
ATechAdventurer 9fe4bfd
Refactor error handling in invite API routes to use scoped logger for…
ATechAdventurer 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
|
|
||
| export async function DELETE(_request: NextRequest, { params: _params }: { params: { domainId: string } }) { | ||
| // Return error since domain invites are not implemented yet | ||
| return NextResponse.json({ success: false, error: 'Domain invites are coming soon' }, { status: 501 }); | ||
| } |
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,11 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
|
|
||
| export async function GET(_request: NextRequest) { | ||
| // Return empty array for now since domain invites are "Coming Soon" | ||
| return NextResponse.json({ success: true, domainInvites: [] }); | ||
| } | ||
|
|
||
| export async function POST(_request: NextRequest) { | ||
| // Return error since domain invites are not implemented yet | ||
| return NextResponse.json({ success: false, error: 'Domain invites are coming soon' }, { status: 501 }); | ||
| } | ||
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,31 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
| import { requireUserAbility } from '~/auth/session'; | ||
| import { PermissionAction, PermissionResource } from '@prisma/client'; | ||
| import { inviteService } from '~/lib/services/inviteService'; | ||
|
|
||
| export async function DELETE(request: NextRequest, { params }: { params: { inviteId: string } }) { | ||
| try { | ||
| const { userAbility } = await requireUserAbility(request); | ||
|
|
||
| if (!userAbility.can(PermissionAction.delete, PermissionResource.AdminApp)) { | ||
| return NextResponse.json({ success: false, error: 'Forbidden' }, { status: 403 }); | ||
| } | ||
|
|
||
| const { inviteId } = params; | ||
|
|
||
| await inviteService.deleteInvite(inviteId); | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| message: 'Invite removed successfully', | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error deleting invite:', error); | ||
|
bears4barrett marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (error instanceof Error && error.message === 'Invite not found') { | ||
| return NextResponse.json({ success: false, error: 'Invite not found' }, { status: 404 }); | ||
| } | ||
|
|
||
| return NextResponse.json({ success: false, error: 'Failed to remove invite' }, { status: 500 }); | ||
| } | ||
| } | ||
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,45 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
| import { z } from 'zod'; | ||
| import { requireUserAbility } from '~/auth/session'; | ||
| import { inviteService } from '~/lib/services/inviteService'; | ||
|
|
||
| const acceptInviteSchema = z.object({ | ||
| inviteId: z.string().min(1, 'Invite ID is required'), | ||
| }); | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| const { userId } = await requireUserAbility(request); | ||
|
|
||
| const body = await request.json(); | ||
| const parsedBody = acceptInviteSchema.safeParse(body); | ||
|
|
||
| if (!parsedBody.success) { | ||
| return NextResponse.json({ success: false, error: parsedBody.error.flatten().fieldErrors }, { status: 400 }); | ||
| } | ||
|
|
||
| const { inviteId } = parsedBody.data; | ||
|
|
||
| await inviteService.acceptInvite(inviteId, userId); | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| message: 'Invite accepted successfully', | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error accepting invite:', error); | ||
|
|
||
| if (error instanceof Error) { | ||
| if ( | ||
| error.message.includes('not found') || | ||
| error.message.includes('no longer valid') || | ||
| error.message.includes('expired') || | ||
| error.message.includes('does not match') | ||
| ) { | ||
| return NextResponse.json({ success: false, error: error.message }, { status: 400 }); | ||
| } | ||
| } | ||
|
ATechAdventurer marked this conversation as resolved.
|
||
|
|
||
| return NextResponse.json({ success: false, error: 'Failed to accept invite' }, { status: 500 }); | ||
| } | ||
| } | ||
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,74 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
| import { z } from 'zod'; | ||
| import { requireUserAbility } from '~/auth/session'; | ||
| import { PermissionAction, PermissionResource } from '@prisma/client'; | ||
| import { inviteService } from '~/lib/services/inviteService'; | ||
| import { InviteStatus } from '@prisma/client'; | ||
|
|
||
| const createInviteSchema = z.object({ | ||
| email: z.string().email('Invalid email address'), | ||
| roleId: z.string().min(1, 'Role ID is required'), | ||
| }); | ||
|
|
||
| export async function GET(request: NextRequest) { | ||
| try { | ||
| const { userAbility } = await requireUserAbility(request); | ||
|
|
||
| if (!userAbility.can(PermissionAction.read, PermissionResource.AdminApp)) { | ||
| return NextResponse.json({ success: false, error: 'Forbidden' }, { status: 403 }); | ||
| } | ||
|
|
||
| const { searchParams } = new URL(request.url); | ||
| const status = searchParams.get('status') as InviteStatus; | ||
|
|
||
| if (status && !Object.values(InviteStatus).includes(status)) { | ||
| return NextResponse.json({ success: false, error: 'Invalid status' }, { status: 400 }); | ||
| } | ||
|
|
||
| const invites = status | ||
| ? await inviteService.getInvitesByStatus(status) | ||
| : await inviteService.getInvitesByStatus(InviteStatus.PENDING); | ||
|
|
||
| return NextResponse.json({ success: true, invites }); | ||
| } catch (error) { | ||
| console.error('Error fetching invites:', error); | ||
| return NextResponse.json({ success: false, error: 'Failed to fetch invites' }, { status: 500 }); | ||
| } | ||
| } | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| const { userAbility, userId } = await requireUserAbility(request); | ||
|
|
||
| if (!userAbility.can(PermissionAction.create, PermissionResource.AdminApp)) { | ||
| return NextResponse.json({ success: false, error: 'Forbidden' }, { status: 403 }); | ||
| } | ||
|
|
||
| const body = await request.json(); | ||
| const parsedBody = createInviteSchema.safeParse(body); | ||
|
|
||
| if (!parsedBody.success) { | ||
| return NextResponse.json({ success: false, error: parsedBody.error.flatten().fieldErrors }, { status: 400 }); | ||
| } | ||
|
|
||
| const { email, roleId } = parsedBody.data; | ||
|
|
||
| const invite = await inviteService.createInvite(email, roleId, userId); | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| invite, | ||
| message: 'Invitation sent successfully', | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error creating invite:', error); | ||
|
|
||
| if (error instanceof Error) { | ||
| if (error.message.includes('already exists') || error.message.includes('already a pending invite')) { | ||
| return NextResponse.json({ success: false, error: error.message }, { status: 400 }); | ||
| } | ||
| } | ||
|
ATechAdventurer marked this conversation as resolved.
|
||
|
|
||
| return NextResponse.json({ success: false, error: 'Failed to create invite' }, { status: 500 }); | ||
| } | ||
| } | ||
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
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.