import { IconLoader2 as Loader2, IconPencil as Pencil, IconAlertTriangle as TriangleAlert, } from '@tabler/icons-react'; import { useMutation } from '@tanstack/react-query'; import { useState } from 'react'; import { useNavigate, useParams } from 'react-router'; import { toast } from 'sonner'; import { PageHeader } from '@/components/PageHeader'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogTitle, } from '@/components/ui/alert-dialog'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { useOrganizations } from '@/hooks/useOrganizations'; import { apiJson } from '@/lib/api'; import { ContentPanel } from '../../components/ContentPanel'; async function deleteOrganization(orgId: string): Promise { await apiJson( `/api/v1/organizations/${orgId}`, { method: 'DELETE' }, 'Failed to delete organization' ); } export default function OrgDetails() { const { orgId } = useParams<{ orgId: string }>(); const navigate = useNavigate(); const { organizations, refresh, isLoading: orgsLoading } = useOrganizations(); const [isEditing, setIsEditing] = useState(false); const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); const organization = organizations.find((org) => org.id === orgId); const isLastOrg = organizations.length <= 1; const deleteMutation = useMutation({ mutationFn: () => deleteOrganization(orgId ?? ''), onSuccess: async () => { await refresh(); navigate('/dashboard'); toast.success('Organization deleted'); }, onError: (error: Error) => { toast.error(error.message); }, }); if (orgsLoading) { return ( <> ); } if (!organization) { return ( <>

The organization you're looking for doesn't exist or you don't have access.

); } return ( <>

{organization.name}

Manage your organization's settings and information

Organization Information Basic details about this organization.
{!isEditing && ( )}

The slug is used in URLs and cannot be changed.

{organization.plan}

{isEditing && (
)}
Organization ID Your unique organization identifier. {organization.id} Danger Zone Irreversible and destructive actions.

Delete Organization

Permanently delete this organization and all its data. This action cannot be undone.

Delete "{organization.name}"? {isLastOrg ? 'You cannot delete your only organization. Create another organization first.' : 'This action cannot be undone. All members will be removed and all organization data will be permanently deleted.'} Cancel {!isLastOrg && ( deleteMutation.mutate()} > {deleteMutation.isPending && } Delete organization )} ); }