Skip to content
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

feat(web): implement invite removing #51

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
);
}
Loading