import { useQueryClient } from '@tanstack/react-query'; import { ArrowsClockwise, Clipboard, Eye, EyeSlash, Info } from 'phosphor-react'; import { useState } from 'react'; import { Algorithm, HASHING_ALGOS, HashingAlgoSlug, hashingAlgoSlugSchema, useBridgeMutation, usePlausibleEvent } from '@sd/client'; import { Button, CheckBox, Dialog, Select, SelectOption, Tooltip, UseDialogProps, forms, useDialog } from '@sd/ui'; import { PasswordMeter } from '~/components/PasswordMeter'; import { generatePassword } from '~/util'; const { Input, z, useZodForm } = forms; const schema = z.object({ name: z.string(), password: z.string(), password_validate: z.string(), algorithm: z.string(), hashing_algorithm: hashingAlgoSlugSchema, share_telemetry: z.boolean() }); export default (props: UseDialogProps) => { const dialog = useDialog(props); const submitPlausibleEvent = usePlausibleEvent(); const form = useZodForm({ schema, defaultValues: { password: '', algorithm: 'XChaCha20Poly1305', hashing_algorithm: 'Argon2id-s' } }); const [showMasterPassword1, setShowMasterPassword1] = useState(false); const [showMasterPassword2, setShowMasterPassword2] = useState(false); const MP1CurrentEyeIcon = showMasterPassword1 ? EyeSlash : Eye; const MP2CurrentEyeIcon = showMasterPassword2 ? EyeSlash : Eye; const queryClient = useQueryClient(); const createLibrary = useBridgeMutation('library.create', { onSuccess: (library) => { queryClient.setQueryData(['library.list'], (libraries: any) => [ ...(libraries || []), library ]); submitPlausibleEvent({ event: { type: 'libraryCreate' } }); }, onError: (err: any) => { console.error(err); } }); const onSubmit = form.handleSubmit(async (data) => { if (data.password !== data.password_validate) { alert('Passwords are not the same'); } else { await createLibrary.mutateAsync({ ...data, algorithm: data.algorithm as Algorithm, hashing_algorithm: HASHING_ALGOS[data.hashing_algorithm], auth: { type: 'Password', value: data.password } }); } }); return (
Share anonymous usage
{/* TODO: Proper UI for this. Maybe checkbox for encrypted or not and then reveal these fields. Select encrypted by default. */} {/* Make the secret key field empty to skip key setup. */}

Key Manager

} />
setShowMasterPassword2(!showMasterPassword2)} size="icon"> } {...form.register('password_validate')} />
Encryption
Hashing
); };