-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from Saasfy/delete-invite
feat(web): implement invite removing
- Loading branch information
Showing
3 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
apps/web/app/api/workspaces/[workspaceSlug]/invites/[inviteId]/route.ts
This file contains 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,17 @@ | ||
import { withWorkspaceOwner } from '@saasfy/api/server'; | ||
import { createAdminClient } from '@saasfy/supabase/server'; | ||
|
||
export const DELETE = withWorkspaceOwner<{ inviteId: string }>(async ({ workspace, params }) => { | ||
const { inviteId } = params; | ||
|
||
const supabase = createAdminClient(); | ||
|
||
await supabase | ||
.from('workspace_invites') | ||
.delete() | ||
.eq('id', inviteId) | ||
.eq('status', 'pending') | ||
.eq('workspace_id', workspace.id); | ||
|
||
return Response.json({ success: true }); | ||
}); |
This file contains 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
28 changes: 28 additions & 0 deletions
28
apps/web/app/app/(dashboard)/[workspaceSlug]/settings/members/remove-invite-button.tsx
This file contains 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,28 @@ | ||
'use client'; | ||
|
||
import { useParams, useRouter } from 'next/navigation'; | ||
|
||
import { TrashIcon } from 'lucide-react'; | ||
|
||
import { Button } from '@saasfy/ui/button'; | ||
|
||
export function RemoveInviteButton({ inviteId }: { inviteId: string }) { | ||
const { workspaceSlug } = useParams(); | ||
const router = useRouter(); | ||
|
||
return ( | ||
<Button | ||
onClick={async () => { | ||
await fetch(`/api/workspaces/${workspaceSlug}/invites/${inviteId}`, { | ||
method: 'DELETE', | ||
}); | ||
|
||
router.refresh(); | ||
}} | ||
variant="destructive" | ||
size="icon" | ||
> | ||
<TrashIcon className="w-4 h-4" /> | ||
</Button> | ||
); | ||
} |