chore: vaults improvements
This commit is contained in:
@@ -123,7 +123,7 @@ const Vaults = () => {
|
|||||||
<PreferencesGroup>
|
<PreferencesGroup>
|
||||||
<PreferencesSegment>
|
<PreferencesSegment>
|
||||||
<Title>Incoming Invites</Title>
|
<Title>Incoming Invites</Title>
|
||||||
<div className="my-2 flex flex-col">
|
<div className="my-2 flex flex-col gap-3.5">
|
||||||
{invites.map((invite) => {
|
{invites.map((invite) => {
|
||||||
return <InviteItem inviteRecord={invite} key={invite.invite.uuid} />
|
return <InviteItem inviteRecord={invite} key={invite.invite.uuid} />
|
||||||
})}
|
})}
|
||||||
@@ -134,7 +134,7 @@ const Vaults = () => {
|
|||||||
<PreferencesGroup>
|
<PreferencesGroup>
|
||||||
<PreferencesSegment>
|
<PreferencesSegment>
|
||||||
<Title>Contacts</Title>
|
<Title>Contacts</Title>
|
||||||
<div className="my-2 flex flex-col">
|
<div className="my-2 flex flex-col gap-3.5">
|
||||||
{contacts.map((contact) => {
|
{contacts.map((contact) => {
|
||||||
return <ContactItem contact={contact} key={contact.uuid} />
|
return <ContactItem contact={contact} key={contact.uuid} />
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FunctionComponent, useCallback, useEffect, useMemo, useState } from 'react'
|
import { FunctionComponent, useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import Modal, { ModalAction } from '@/Components/Modal/Modal'
|
import Modal, { ModalAction } from '@/Components/Modal/Modal'
|
||||||
import DecoratedInput from '@/Components/Input/DecoratedInput'
|
import DecoratedInput from '@/Components/Input/DecoratedInput'
|
||||||
import { useApplication } from '@/Components/ApplicationProvider'
|
import { useApplication } from '@/Components/ApplicationProvider'
|
||||||
@@ -27,14 +27,17 @@ const EditVaultModal: FunctionComponent<Props> = ({ onCloseDialog, existingVault
|
|||||||
|
|
||||||
const existingVault = useItem<VaultListingInterface>(existingVaultUuid)
|
const existingVault = useItem<VaultListingInterface>(existingVaultUuid)
|
||||||
|
|
||||||
const [name, setName] = useState<string>('')
|
const [name, setName] = useState('')
|
||||||
const [description, setDescription] = useState<string>('')
|
const [description, setDescription] = useState('')
|
||||||
const [members, setMembers] = useState<SharedVaultUserServerHash[]>([])
|
const [members, setMembers] = useState<SharedVaultUserServerHash[]>([])
|
||||||
const [invites, setInvites] = useState<SharedVaultInviteServerHash[]>([])
|
const [invites, setInvites] = useState<SharedVaultInviteServerHash[]>([])
|
||||||
const [isAdmin, setIsAdmin] = useState<boolean>(true)
|
const [isAdmin, setIsAdmin] = useState(true)
|
||||||
const [passwordType, setPasswordType] = useState<KeySystemPasswordType>(KeySystemPasswordType.Randomized)
|
const [passwordType, setPasswordType] = useState<KeySystemPasswordType>(KeySystemPasswordType.Randomized)
|
||||||
const [keyStorageMode, setKeyStorageMode] = useState<KeySystemRootKeyStorageMode>(KeySystemRootKeyStorageMode.Synced)
|
const [keyStorageMode, setKeyStorageMode] = useState<KeySystemRootKeyStorageMode>(KeySystemRootKeyStorageMode.Synced)
|
||||||
const [customPassword, setCustomPassword] = useState<string | undefined>(undefined)
|
const [customPassword, setCustomPassword] = useState<string | undefined>(undefined)
|
||||||
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
|
|
||||||
|
const nameInputRef = useRef<HTMLInputElement>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (existingVault) {
|
if (existingVault) {
|
||||||
@@ -77,6 +80,11 @@ const EditVaultModal: FunctionComponent<Props> = ({ onCloseDialog, existingVault
|
|||||||
|
|
||||||
const saveExistingVault = useCallback(
|
const saveExistingVault = useCallback(
|
||||||
async (vault: VaultListingInterface) => {
|
async (vault: VaultListingInterface) => {
|
||||||
|
if (!name) {
|
||||||
|
nameInputRef.current?.focus()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (vault.name !== name || vault.description !== description) {
|
if (vault.name !== name || vault.description !== description) {
|
||||||
await application.vaults.changeVaultNameAndDescription(vault, {
|
await application.vaults.changeVaultNameAndDescription(vault, {
|
||||||
name: name,
|
name: name,
|
||||||
@@ -114,11 +122,18 @@ const EditVaultModal: FunctionComponent<Props> = ({ onCloseDialog, existingVault
|
|||||||
newStorageMode: isChangingKeyStorageMode ? keyStorageMode : undefined,
|
newStorageMode: isChangingKeyStorageMode ? keyStorageMode : undefined,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleDialogClose()
|
||||||
},
|
},
|
||||||
[application.vaults, customPassword, description, keyStorageMode, name, passwordType],
|
[application.vaults, customPassword, description, handleDialogClose, keyStorageMode, name, passwordType],
|
||||||
)
|
)
|
||||||
|
|
||||||
const createNewVault = useCallback(async () => {
|
const createNewVault = useCallback(async () => {
|
||||||
|
if (!name) {
|
||||||
|
nameInputRef.current?.focus()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (passwordType === KeySystemPasswordType.UserInputted) {
|
if (passwordType === KeySystemPasswordType.UserInputted) {
|
||||||
if (!customPassword) {
|
if (!customPassword) {
|
||||||
throw new Error('Custom key is not set')
|
throw new Error('Custom key is not set')
|
||||||
@@ -140,13 +155,17 @@ const EditVaultModal: FunctionComponent<Props> = ({ onCloseDialog, existingVault
|
|||||||
}, [application.vaults, customPassword, description, handleDialogClose, keyStorageMode, name, passwordType])
|
}, [application.vaults, customPassword, description, handleDialogClose, keyStorageMode, name, passwordType])
|
||||||
|
|
||||||
const handleSubmit = useCallback(async () => {
|
const handleSubmit = useCallback(async () => {
|
||||||
|
if (isSubmitting) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setIsSubmitting(true)
|
||||||
if (existingVault) {
|
if (existingVault) {
|
||||||
await saveExistingVault(existingVault)
|
await saveExistingVault(existingVault)
|
||||||
} else {
|
} else {
|
||||||
await createNewVault()
|
await createNewVault()
|
||||||
}
|
}
|
||||||
handleDialogClose()
|
setIsSubmitting(false)
|
||||||
}, [existingVault, handleDialogClose, saveExistingVault, createNewVault])
|
}, [isSubmitting, existingVault, saveExistingVault, createNewVault])
|
||||||
|
|
||||||
const modalActions = useMemo(
|
const modalActions = useMemo(
|
||||||
(): ModalAction[] => [
|
(): ModalAction[] => [
|
||||||
@@ -155,6 +174,7 @@ const EditVaultModal: FunctionComponent<Props> = ({ onCloseDialog, existingVault
|
|||||||
onClick: handleSubmit,
|
onClick: handleSubmit,
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
mobileSlot: 'right',
|
mobileSlot: 'right',
|
||||||
|
disabled: isSubmitting,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Cancel',
|
label: 'Cancel',
|
||||||
@@ -163,7 +183,7 @@ const EditVaultModal: FunctionComponent<Props> = ({ onCloseDialog, existingVault
|
|||||||
mobileSlot: 'left',
|
mobileSlot: 'left',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[existingVault, handleDialogClose, handleSubmit],
|
[existingVault, handleDialogClose, handleSubmit, isSubmitting],
|
||||||
)
|
)
|
||||||
|
|
||||||
if (existingVault && application.vaultLocks.isVaultLocked(existingVault)) {
|
if (existingVault && application.vaultLocks.isVaultLocked(existingVault)) {
|
||||||
@@ -180,7 +200,7 @@ const EditVaultModal: FunctionComponent<Props> = ({ onCloseDialog, existingVault
|
|||||||
|
|
||||||
<DecoratedInput
|
<DecoratedInput
|
||||||
className={{ container: 'mt-4' }}
|
className={{ container: 'mt-4' }}
|
||||||
id="vault-name-input"
|
ref={nameInputRef}
|
||||||
value={name}
|
value={name}
|
||||||
placeholder="Vault Name"
|
placeholder="Vault Name"
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
@@ -190,7 +210,6 @@ const EditVaultModal: FunctionComponent<Props> = ({ onCloseDialog, existingVault
|
|||||||
|
|
||||||
<DecoratedInput
|
<DecoratedInput
|
||||||
className={{ container: 'mt-4' }}
|
className={{ container: 'mt-4' }}
|
||||||
id="vault-email-input"
|
|
||||||
value={description}
|
value={description}
|
||||||
placeholder="Vault description"
|
placeholder="Vault description"
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user