import { RadioGroup } from '@headlessui/react'; import { Info } from 'phosphor-react'; import { useLibraryMutation, useLibraryQuery } from '@sd/client'; import { Button, Dialog, Tooltip, UseDialogProps, useDialog } from '@sd/ui'; import { PasswordInput, Switch, useZodForm, z } from '@sd/ui/src/forms'; import { showAlertDialog } from '~/components'; import { usePlatform } from '~/util/Platform'; const schema = z.object({ type: z.union([z.literal('password'), z.literal('key')]), outputPath: z.string(), mountAssociatedKey: z.boolean(), password: z.string(), saveToKeyManager: z.boolean() }); interface Props extends UseDialogProps { location_id: number; path_id: number; } export default (props: Props) => { const platform = usePlatform(); const mountedUuids = useLibraryQuery(['keys.listMounted'], { onSuccess: (data) => { hasMountedKeys = data.length > 0 ? true : false; if (!hasMountedKeys) { form.setValue('type', 'password'); } else { form.setValue('type', 'key'); } } }); let hasMountedKeys = mountedUuids.data !== undefined && mountedUuids.data.length > 0 ? true : false; const decryptFile = useLibraryMutation('files.decryptFiles', { onSuccess: () => { showAlertDialog({ title: 'Success', value: 'The decryption job has started successfully. You may track the progress in the job overview panel.' }); }, onError: () => { showAlertDialog({ title: 'Error', value: 'The decryption job failed to start.' }); } }); const form = useZodForm({ defaultValues: { type: hasMountedKeys ? 'key' : 'password', saveToKeyManager: true, outputPath: '', password: '', mountAssociatedKey: true }, schema }); return ( decryptFile.mutateAsync({ location_id: props.location_id, path_id: props.path_id, output_path: data.outputPath !== '' ? data.outputPath : null, mount_associated_key: data.mountAssociatedKey, password: data.type === 'password' ? data.password : null, save_to_library: data.type === 'password' ? data.saveToKeyManager : null }) } title="Decrypt a file" description="Leave the output file blank for the default." loading={decryptFile.isLoading} ctaLabel="Decrypt" >

Key Type

form.setValue('type', e)} className="mt-2 flex flex-row gap-2" > {({ checked }) => ( )} {({ checked }) => ( )} {form.watch('type') === 'key' && (
form.setValue('mountAssociatedKey', e)} /> Automatically mount key
)} {form.watch('type') === 'password' && ( <>
Save to Key Manager
)}

Output file

); };