Skip to content

Commit

Permalink
Merge pull request #51 from Saasfy/delete-invite
Browse files Browse the repository at this point in the history
feat(web): implement invite removing
  • Loading branch information
IKatsuba authored May 8, 2024
2 parents 14c8b53 + cd951c7 commit 0013d0c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
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 });
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TrashIcon } from 'lucide-react';

import { Tables } from '@saasfy/supabase';
import { Button } from '@saasfy/ui/button';
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@saasfy/ui/table';

import { RemoveInviteButton } from './remove-invite-button';

export function InviteTable({ invites }: { invites: Tables<'workspace_invites'>[] | null }) {
if (!invites?.length) {
return <div className="p-6 text-center text-gray-400">No invites found.</div>;
Expand All @@ -28,9 +27,7 @@ export function InviteTable({ invites }: { invites: Tables<'workspace_invites'>[
<TableCell>{invite.role}</TableCell>
<TableCell>{invite.expires}</TableCell>
<TableCell>
<Button variant="destructive" size="icon">
<TrashIcon className="w-4 h-4" />
</Button>
<RemoveInviteButton inviteId={invite.id} />
</TableCell>
</TableRow>
))}
Expand Down
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>
);
}

0 comments on commit 0013d0c

Please sign in to comment.