import {useState} from 'react'; import {useNavigate} from 'react-router-dom'; import {useMutation} from '@tanstack/react-query'; import {workspaceUpdate, workspaceDelete} from '@/client'; import {useWorkspace} from '@/contexts'; import {Avatar, AvatarFallback, AvatarImage} from '@/components/ui/avatar'; import {Button} from '@/components/ui/button'; import {Input} from '@/components/ui/input'; import {Label} from '@/components/ui/label'; import {toast} from 'sonner'; export function WorkspaceSettings() { const {currentWorkspace, refetch} = useWorkspace(); const navigate = useNavigate(); const [name, setName] = useState(currentWorkspace?.name ?? ''); const [description, setDescription] = useState(currentWorkspace?.description ?? ''); const [avatarUrl, setAvatarUrl] = useState(currentWorkspace?.avatar_url ?? ''); const [billingEmail, setBillingEmail] = useState(currentWorkspace?.billing_email ?? ''); const updateMutation = useMutation({ mutationFn: async () => { await workspaceUpdate({ path: {slug: currentWorkspace!.slug}, body: { name: name || undefined, description: description || undefined, avatar_url: avatarUrl || undefined, billing_email: billingEmail || undefined, }, }); }, onSuccess: () => { toast.success('Workspace updated'); refetch(); }, onError: (err: Error) => { toast.error(err.message || 'Failed to update workspace'); }, }); const deleteMutation = useMutation({ mutationFn: async () => { if (!confirm('Are you sure you want to delete this workspace? This action cannot be undone.')) { throw new Error('cancelled'); } await workspaceDelete({path: {slug: currentWorkspace!.slug}}); }, onSuccess: () => { toast.success('Workspace deleted'); navigate('/'); }, onError: (err: Error) => { if (err.message !== 'cancelled') { toast.error(err.message || 'Failed to delete workspace'); } }, }); if (!currentWorkspace) return null; const isOwner = currentWorkspace.my_role?.toLowerCase() === 'owner'; return (
{currentWorkspace.name}
w/{currentWorkspace.slug}
Enter a URL to an image for the workspace avatar.
Invoices will be sent to this email.
Current Plan
{currentWorkspace.plan}
Delete Workspace
Permanently delete this workspace and all its data. This action cannot be undone.