Files
tolaria/src/components/WorkspaceSettingsSection.tsx

76 lines
2.7 KiB
TypeScript
Raw Normal View History

2026-05-14 17:17:54 +02:00
import { useState } from 'react'
import { TooltipProvider } from './ui/tooltip'
2026-05-11 16:37:06 +02:00
import { ConfirmDeleteDialog } from './ConfirmDeleteDialog'
2026-05-14 17:17:54 +02:00
import { SettingsGroup, SettingsSwitchRow } from './SettingsControls'
2026-05-11 16:37:06 +02:00
import { createTranslator, type AppLocale } from '../lib/i18n'
import type { VaultOption } from './status-bar/types'
import { workspaceIdentityFromVault } from '../utils/workspaces'
2026-05-14 17:17:54 +02:00
import { WorkspaceSettingsRows } from './WorkspaceSettingsRows'
2026-05-11 16:37:06 +02:00
interface WorkspaceSettingsSectionProps {
defaultWorkspacePath?: string | null
enabled: boolean
locale: AppLocale
onEnabledChange: (enabled: boolean) => void
onRemoveVault?: (path: string) => void
2026-05-14 17:17:54 +02:00
onReorderVaults?: (orderedPaths: string[]) => void
2026-05-11 16:37:06 +02:00
onSetDefaultWorkspace?: (path: string) => void
onUpdateWorkspaceIdentity?: (path: string, patch: Partial<VaultOption>) => void
vaults: VaultOption[]
}
export function WorkspaceSettingsSection({
defaultWorkspacePath,
enabled,
locale,
onEnabledChange,
onRemoveVault,
2026-05-14 17:17:54 +02:00
onReorderVaults,
2026-05-11 16:37:06 +02:00
onSetDefaultWorkspace,
onUpdateWorkspaceIdentity,
vaults,
}: WorkspaceSettingsSectionProps) {
const t = createTranslator(locale)
const [vaultPendingRemoval, setVaultPendingRemoval] = useState<VaultOption | null>(null)
const pendingRemovalIdentity = vaultPendingRemoval ? workspaceIdentityFromVault(vaultPendingRemoval, { defaultWorkspacePath }) : null
return (
<TooltipProvider>
<SettingsGroup>
<SettingsSwitchRow
label={t('settings.workspaces.enable')}
description={t('settings.workspaces.enableDescription')}
checked={enabled}
onChange={onEnabledChange}
testId="settings-multi-workspace-enabled"
/>
{enabled && (
2026-05-14 17:17:54 +02:00
<WorkspaceSettingsRows
defaultWorkspacePath={defaultWorkspacePath}
locale={locale}
onRemoveVault={onRemoveVault}
onReorderVaults={onReorderVaults}
onSetDefaultWorkspace={onSetDefaultWorkspace}
onUpdateWorkspaceIdentity={onUpdateWorkspaceIdentity}
setVaultPendingRemoval={setVaultPendingRemoval}
vaults={vaults}
/>
2026-05-11 16:37:06 +02:00
)}
</SettingsGroup>
<ConfirmDeleteDialog
open={!!vaultPendingRemoval}
title={t('status.vault.removeConfirmTitle')}
message={t('status.vault.removeConfirmMessage', { label: pendingRemovalIdentity?.label ?? '' })}
confirmLabel={t('status.vault.removeConfirmAction')}
onCancel={() => setVaultPendingRemoval(null)}
onConfirm={() => {
if (vaultPendingRemoval) {
onRemoveVault?.(vaultPendingRemoval.path)
}
setVaultPendingRemoval(null)
}}
/>
</TooltipProvider>
)
}