Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add export password modal and update dark mode UI in all modals (#2413)

Leendert de Borstee4db50c5807
diff --git a/apps/web/src/components/email/EmailModal.tsx b/apps/web/src/components/email/EmailModal.tsx
index be1d99e0a..97ae2c07d 100644
--- a/apps/web/src/components/email/EmailModal.tsx
+++ b/apps/web/src/components/email/EmailModal.tsx
@@ -1,9 +1,10 @@
import { downloadBytes } from '@aliasvault/client/utilities/FileDownload';
-import React, { useCallback, useEffect, useRef, useState } from 'react';
+import React, { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import SkeletonBase from '@/components/loading/SkeletonBase';
+import Modal from '@/components/shared/Modal';
import ModalHeaderAction from '@/components/shared/ModalHeaderAction';
import { useConfirmModal } from '@/context/ConfirmModalContext';
import { useDb } from '@/context/DbContext';
@@ -43,7 +44,6 @@ const EmailModal: React.FC<EmailModalProps> = ({ email, onClose, onEmailDeleted,
const { showConfirmation } = useConfirmModal();
const [isBodyLoading, setIsBodyLoading] = useState(false);
const [item, setItem] = useState<{ ref: ItemRef; name: string } | null>(null);
- const panelRef = useRef<HTMLDivElement>(null);
const onBodyLoading = useCallback((loading: boolean): void => setIsBodyLoading(loading), []);
const { emailBody, availableModes, formatLabel, cycleViewMode } = useEmailBody(email, onBodyLoading);
@@ -78,11 +78,6 @@ const EmailModal: React.FC<EmailModalProps> = ({ email, onClose, onEmailDeleted,
/**
* Close on a click on the backdrop. The confirm modal renders outside the panel, so its clicks must not close.
*/
- const onBackdropClick = (event: React.MouseEvent<HTMLDivElement>): void => {
- if (event.target === event.currentTarget) {
- onClose();
- }
- };
/**
* Delete the email after confirmation.
@@ -136,111 +131,109 @@ const EmailModal: React.FC<EmailModalProps> = ({ email, onClose, onEmailDeleted,
};
return (
- <div className="modal-dialog fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center" onClick={onBackdropClick}>
- <div ref={panelRef} id="emailModal" className="relative bg-white dark:bg-gray-800 w-3/4 flex flex-col rounded-lg shadow-xl max-h-[90vh] border border-gray-200 dark:border-gray-700">
- <div className="p-4 border-b border-gray-200 dark:border-gray-700">
- <div className="flex items-center justify-between gap-3 mb-3">
- <h2 className="text-2xl font-bold text-gray-900 dark:text-gray-100 truncate min-w-0">
- {email === null
- ? <SkeletonLine height={28} widthClass="w-3/4" />
- : email.isSpamOk
- ? <a target="_blank" rel="noreferrer" href={`https://spamok.com/${email.toLocal}/${email.id}`} className="hover:underline">{email.subject}</a>
- : <span>{email.subject}</span>}
- </h2>
- <div className="flex items-center gap-1 flex-shrink-0">
- {availableModes.length > 1 && (
- <ModalHeaderAction onClick={cycleViewMode} title={t('sharedResources.EmailFormatSwitchTitle')}>{formatLabel}</ModalHeaderAction>
- )}
- {email !== null && (
- <ModalHeaderAction onClick={() => void showDeleteConfirmation()} title={t('components.main.email.emailModal.DeleteButton')} variant="danger">
- <svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
- </svg>
- </ModalHeaderAction>
- )}
- <ModalHeaderAction onClick={onClose} title={t('sharedResources.Close')}>
+ <Modal id="emailModal" onBackdropClick={onClose} panelClassName="w-3/4 flex flex-col max-h-[90vh]">
+ <div className="p-4 border-b border-gray-200 dark:border-gray-700">
+ <div className="flex items-center justify-between gap-3 mb-3">
+ <h2 className="text-2xl font-bold text-gray-900 dark:text-gray-100 truncate min-w-0">
+ {email === null
+ ? <SkeletonLine height={28} widthClass="w-3/4" />
+ : email.isSpamOk
+ ? <a target="_blank" rel="noreferrer" href={`https://spamok.com/${email.toLocal}/${email.id}`} className="hover:underline">{email.subject}</a>
+ : <span>{email.subject}</span>}
+ </h2>
+ <div className="flex items-center gap-1 flex-shrink-0">
+ {availableModes.length > 1 && (
+ <ModalHeaderAction onClick={cycleViewMode} title={t('sharedResources.EmailFormatSwitchTitle')}>{formatLabel}</ModalHeaderAction>
+ )}
+ {email !== null && (
+ <ModalHeaderAction onClick={() => void showDeleteConfirmation()} title={t('components.main.email.emailModal.DeleteButton')} variant="danger">
<svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12" />
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
</ModalHeaderAction>
- </div>
- </div>
- <div className="grid grid-cols-1 sm:grid-cols-2 gap-x-4 text-sm text-gray-500 dark:text-gray-400">
- {email === null ? (
- <>
- <div className="space-y-2">
- <SkeletonLine height={16} widthClass="w-1/2" />
- <SkeletonLine height={16} widthClass="w-1/2" />
- </div>
- <div className="space-y-2 mt-2 sm:mt-0">
- <SkeletonLine height={16} widthClass="w-1/3" />
- <SkeletonLine height={16} widthClass="w-1/4" />
- </div>
- </>
- ) : (
- <>
- <div className="space-y-1">
- <p>{t('components.main.email.emailModal.FromLabel')} {email.fromLocal}@{email.fromDomain}</p>
- <p>{t('components.main.email.emailModal.ToLabel')} {email.toLocal}@{email.toDomain}</p>
- </div>
- <div className="space-y-1 mt-1 sm:mt-0">
- <p>{t('components.main.email.emailModal.DateLabel')} {new Date(email.dateSystem).toLocaleString()}</p>
- {showItemLink && (item !== null && item.name.length > 0 ? (
- <p>
- <span className="font-medium">{t('sharedResources.EmailItemLabel')}</span>{' '}
- <button type="button" onClick={() => navigate(itemRoute(item.ref))} className="text-primary-600 hover:underline dark:text-primary-400 cursor-pointer">{item.name}</button>
- </p>
- ) : (
- <p>
- <span className="font-medium">{t('sharedResources.EmailItemLabel')}</span>{' '}
- <span className="text-gray-400 dark:text-gray-500">{t('sharedResources.EmailItemNone')}</span>
- </p>
- ))}
- </div>
- </>
)}
+ <ModalHeaderAction onClick={onClose} title={t('sharedResources.Close')}>
+ <svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12" />
+ </svg>
+ </ModalHeaderAction>
</div>
</div>
-
- <div className="flex-1 overflow-y-auto p-4">
- <div className="text-gray-700 dark:text-gray-300">
- {/* Mount only once the body exists to prevent browsers from dropping a srcdoc change made while the initial empty srcdoc still loads. */}
- {email === null || isBodyLoading || emailBody === '' ? (
- <div className="space-y-3" style={{ height: '500px' }}>
- <SkeletonLine height={16} widthClass="w-11/12" />
- <SkeletonLine height={16} widthClass="w-full" />
- <SkeletonLine height={16} widthClass="w-10/12" />
- <SkeletonLine height={16} widthClass="w-5/6" />
- <SkeletonLine height={16} widthClass="w-2/3" />
+ <div className="grid grid-cols-1 sm:grid-cols-2 gap-x-4 text-sm text-gray-500 dark:text-gray-400">
+ {email === null ? (
+ <>
+ <div className="space-y-2">
+ <SkeletonLine height={16} widthClass="w-1/2" />
+ <SkeletonLine height={16} widthClass="w-1/2" />
</div>
- ) : (
- <div>
- <iframe title="email" className="w-full overscroll-y-auto bg-white rounded" style={{ height: '500px' }} srcDoc={emailBody} sandbox="allow-popups allow-popups-to-escape-sandbox"></iframe>
+ <div className="space-y-2 mt-2 sm:mt-0">
+ <SkeletonLine height={16} widthClass="w-1/3" />
+ <SkeletonLine height={16} widthClass="w-1/4" />
</div>
- )}
- </div>
- <div className="mt-4">
- {email !== null && email.attachments.length > 0 && (
- <div className="border-t border-gray-200 dark:border-gray-600 pt-4">
- <h3 className="text-sm font-medium text-gray-500 dark:text-gray-400 mb-2">{t('components.main.email.emailModal.AttachmentsLabel')}</h3>
- <div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
- {email.attachments.map((attachment) => (
- <div key={attachment.index} className="flex items-center space-x-2">
- <svg className="w-4 h-4 text-gray-500 dark:text-gray-400 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path>
- </svg>
- <button type="button" onClick={() => void downloadAttachment(attachment)} className="text-primary-600 hover:underline text-sm truncate dark:text-primary-400 attachment-link">
+ </>
+ ) : (
+ <>
+ <div className="space-y-1">
+ <p>{t('components.main.email.emailModal.FromLabel')} {email.fromLocal}@{email.fromDomain}</p>
+ <p>{t('components.main.email.emailModal.ToLabel')} {email.toLocal}@{email.toDomain}</p>
+ </div>
+ <div className="space-y-1 mt-1 sm:mt-0">
+ <p>{t('components.main.email.emailModal.DateLabel')} {new Date(email.dateSystem).toLocaleString()}</p>
+ {showItemLink && (item !== null && item.name.length > 0 ? (
+ <p>
+ <span className="font-medium">{t('sharedResources.EmailItemLabel')}</span>{' '}
+ <button type="button" onClick={() => navigate(itemRoute(item.ref))} className="text-primary-600 hover:underline dark:text-primary-400 cursor-pointer">{item.name}</button>
+ </p>
+ ) : (
+ <p>
+ <span className="font-medium">{t('sharedResources.EmailItemLabel')}</span>{' '}
+ <span className="text-gray-400 dark:text-gray-500">{t('sharedResources.EmailItemNone')}</span>
+ </p>
+ ))}
+ </div>
+ </>
+ )}
+ </div>
+ </div>
+
+ <div className="flex-1 overflow-y-auto p-4">
+ <div className="text-gray-700 dark:text-gray-300">
+ {/* Mount only once the body exists to prevent browsers from dropping a srcdoc change made while the initial empty srcdoc still loads. */}
+ {email === null || isBodyLoading || emailBody === '' ? (
+ <div className="space-y-3" style={{ height: '500px' }}>
+ <SkeletonLine height={16} widthClass="w-11/12" />
+ <SkeletonLine height={16} widthClass="w-full" />
+ <SkeletonLine height={16} widthClass="w-10/12" />
+ <SkeletonLine height={16} widthClass="w-5/6" />
+ <SkeletonLine height={16} widthClass="w-2/3" />
+ </div>
+ ) : (
+ <div>
+ <iframe title="email" className="w-full overscroll-y-auto bg-white rounded" style={{ height: '500px' }} srcDoc={emailBody} sandbox="allow-popups allow-popups-to-escape-sandbox"></iframe>
+ </div>
+ )}
+ </div>
+ <div className="mt-4">
+ {email !== null && email.attachments.length > 0 && (
+ <div className="border-t border-gray-200 dark:border-gray-600 pt-4">
+ <h3 className="text-sm font-medium text-gray-500 dark:text-gray-400 mb-2">{t('components.main.email.emailModal.AttachmentsLabel')}</h3>
+ <div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
+ {email.attachments.map((attachment) => (
+ <div key={attachment.index} className="flex items-center space-x-2">
+ <svg className="w-4 h-4 text-gray-500 dark:text-gray-400 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path>
+ </svg>
+ <button type="button" onClick={() => void downloadAttachment(attachment)} className="text-primary-600 hover:underline text-sm truncate dark:text-primary-400 attachment-link">
({Math.ceil(attachment.size / 1024)} KB) {attachment.filename}
- </button>
- </div>
- ))}
- </div>
+ </button>
+ </div>
+ ))}
</div>
- )}
- </div>
+ </div>
+ )}
</div>
</div>
- </div>
+ </Modal>
);
};
diff --git a/apps/web/src/components/items/FieldHistoryModal.tsx b/apps/web/src/components/items/FieldHistoryModal.tsx
index e7a7fb5d0..aee0c985f 100644
--- a/apps/web/src/components/items/FieldHistoryModal.tsx
+++ b/apps/web/src/components/items/FieldHistoryModal.tsx
@@ -1,10 +1,10 @@
-import React, { useCallback, useEffect, useRef, useState } from 'react';
+import React, { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import CopyPasteFormRow from '@/components/forms/CopyPasteFormRow';
import CopyPastePasswordFormRow from '@/components/forms/CopyPastePasswordFormRow';
+import Modal from '@/components/shared/Modal';
import { useDb } from '@/context/DbContext';
-import { useClickOutside } from '@/hooks/useClickOutside';
import { useVaultMutate } from '@/hooks/useVaultMutate';
import type { ItemRef } from '@aliasvault/client/database/ItemRef';
@@ -45,9 +45,6 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({ item, fieldKey, f
const [isLoading, setIsLoading] = useState(true);
const [records, setRecords] = useState<FieldHistory[]>([]);
const [confirmDeleteId, setConfirmDeleteId] = useState<string | null>(null);
- const panelRef = useRef<HTMLDivElement>(null);
-
- useClickOutside([panelRef], onClose, true);
/**
* Load the history records.
@@ -85,73 +82,71 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({ item, fieldKey, f
};
return (
- <div className="modal-dialog fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center">
- <div ref={panelRef} id="fieldHistoryModal" className="relative bg-white dark:bg-gray-800 w-full max-w-2xl flex flex-col rounded-lg shadow-xl max-h-[90vh] border-2 border-gray-300 dark:border-gray-600">
- <div className="p-4 border-b border-gray-200 dark:border-gray-700">
- <div className="flex items-center justify-between">
- <h2 className="text-xl font-bold text-gray-900 dark:text-white">
- {t('components.fields.fieldHistoryModal.HistoryTitle')} - {fieldLabel}
- </h2>
- <button type="button" onClick={onClose} className="text-gray-400 hover:text-gray-500 dark:hover:text-gray-300" title={t('sharedResources.Close')} aria-label={t('sharedResources.Close')}>
- <svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12" />
- </svg>
- </button>
- </div>
+ <Modal id="fieldHistoryModal" onBackdropClick={onClose} panelClassName="w-full max-w-2xl flex flex-col max-h-[90vh]">
+ <div className="p-4 border-b border-gray-200 dark:border-gray-700">
+ <div className="flex items-center justify-between">
+ <h2 className="text-xl font-bold text-gray-900 dark:text-white">
+ {t('components.fields.fieldHistoryModal.HistoryTitle')} - {fieldLabel}
+ </h2>
+ <button type="button" onClick={onClose} className="text-gray-400 hover:text-gray-500 dark:hover:text-gray-300" title={t('sharedResources.Close')} aria-label={t('sharedResources.Close')}>
+ <svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12" />
+ </svg>
+ </button>
</div>
+ </div>
- <div className="flex-1 overflow-y-auto p-4">
- {isLoading ? (
- <div className="flex justify-center items-center py-8">
- <svg className="animate-spin h-8 w-8 text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
- <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
- <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
- </svg>
- </div>
- ) : records.length === 0 ? (
- <p className="text-gray-500 dark:text-gray-400 text-center py-8">{t('components.fields.fieldHistoryModal.NoHistoryAvailable')}</p>
- ) : (
- <div className="space-y-4">
- {records.map((record) => {
- const values = parseValueSnapshot(record.ValueSnapshot);
- return (
- <div key={record.Id} className="border border-gray-200 dark:border-gray-700 rounded-lg p-4">
- <div className="flex items-center justify-between mb-2">
- <div className="text-sm text-gray-500 dark:text-gray-400">{formatDate(record.ChangedAt)}</div>
- {confirmDeleteId === record.Id ? (
- <div className="flex items-center gap-2">
- <span className="text-xs text-gray-500 dark:text-gray-400">{t('components.fields.fieldHistoryModal.DeleteConfirm')}</span>
- <button type="button" onClick={() => void deleteRecord(record.Id)} className="text-xs px-2 py-1 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 font-medium">
- {t('sharedResources.Confirm')}
- </button>
- <button type="button" onClick={() => setConfirmDeleteId(null)} className="text-xs px-2 py-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200">
- {t('sharedResources.Cancel')}
- </button>
- </div>
- ) : (
- <button type="button" onClick={() => setConfirmDeleteId(record.Id)} className="text-gray-500 hover:text-red-600 dark:text-gray-400 dark:hover:text-red-400 transition-colors" title={t('sharedResources.Delete')}>
- <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">
- <path strokeLinecap="round" strokeLinejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
- </svg>
+ <div className="flex-1 overflow-y-auto p-4">
+ {isLoading ? (
+ <div className="flex justify-center items-center py-8">
+ <svg className="animate-spin h-8 w-8 text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
+ <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
+ <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
+ </svg>
+ </div>
+ ) : records.length === 0 ? (
+ <p className="text-gray-500 dark:text-gray-400 text-center py-8">{t('components.fields.fieldHistoryModal.NoHistoryAvailable')}</p>
+ ) : (
+ <div className="space-y-4">
+ {records.map((record) => {
+ const values = parseValueSnapshot(record.ValueSnapshot);
+ return (
+ <div key={record.Id} className="border border-gray-200 dark:border-gray-700 rounded-lg p-4">
+ <div className="flex items-center justify-between mb-2">
+ <div className="text-sm text-gray-500 dark:text-gray-400">{formatDate(record.ChangedAt)}</div>
+ {confirmDeleteId === record.Id ? (
+ <div className="flex items-center gap-2">
+ <span className="text-xs text-gray-500 dark:text-gray-400">{t('components.fields.fieldHistoryModal.DeleteConfirm')}</span>
+ <button type="button" onClick={() => void deleteRecord(record.Id)} className="text-xs px-2 py-1 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 font-medium">
+ {t('sharedResources.Confirm')}
+ </button>
+ <button type="button" onClick={() => setConfirmDeleteId(null)} className="text-xs px-2 py-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200">
+ {t('sharedResources.Cancel')}
</button>
- )}
- </div>
- {values.map((value, index) => (
- <div key={index} className="mb-2 last:mb-0">
- {isHidden
- ? <CopyPastePasswordFormRow id={`history-${record.Id}-${index}`} label="" value={value} />
- : <CopyPasteFormRow id={`history-${record.Id}-${index}`} label="" value={value} />}
</div>
- ))}
+ ) : (
+ <button type="button" onClick={() => setConfirmDeleteId(record.Id)} className="text-gray-500 hover:text-red-600 dark:text-gray-400 dark:hover:text-red-400 transition-colors" title={t('sharedResources.Delete')}>
+ <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
+ </svg>
+ </button>
+ )}
</div>
- );
- })}
- </div>
- )}
- </div>
-
+ {values.map((value, index) => (
+ <div key={index} className="mb-2 last:mb-0">
+ {isHidden
+ ? <CopyPastePasswordFormRow id={`history-${record.Id}-${index}`} label="" value={value} />
+ : <CopyPasteFormRow id={`history-${record.Id}-${index}`} label="" value={value} />}
+ </div>
+ ))}
+ </div>
+ );
+ })}
+ </div>
+ )}
</div>
- </div>
+
+ </Modal>
);
};
diff --git a/apps/web/src/components/settings/PasswordSettingsPopup.tsx b/apps/web/src/components/settings/PasswordSettingsPopup.tsx
index 45f65724d..3d7d301e4 100644
--- a/apps/web/src/components/settings/PasswordSettingsPopup.tsx
+++ b/apps/web/src/components/settings/PasswordSettingsPopup.tsx
@@ -1,13 +1,13 @@
import { lengthToSlider, SLIDER_MAX, SLIDER_MIN, sliderToLength } from '@aliasvault/client/utilities/PasswordLengthSlider';
import { getLanguageInfo, MAX_WORD_COUNT, MIN_WORD_COUNT, resolveDefaultLanguage } from '@aliasvault/models/defaults';
-import React, { useEffect, useMemo, useRef, useState } from 'react';
+import React, { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import CopyPasteFormRow from '@/components/forms/CopyPasteFormRow';
+import Modal from '@/components/shared/Modal';
import { useDb } from '@/context/DbContext';
import { useLoading } from '@/context/LoadingContext';
import { useNotifications } from '@/context/NotificationContext';
-import { useClickOutside } from '@/hooks/useClickOutside';
import { usePasswordConfig } from '@/hooks/usePasswordConfig';
import { useVaultMutate } from '@/hooks/useVaultMutate';
@@ -75,12 +75,9 @@ const PasswordSettingsPopup: React.FC<PasswordSettingsPopupProps> = ({ passwordS
const { executeVaultMutationAsync } = useVaultMutate();
const { settings, previewPassword, dicewareLanguages, handleSettingChange, handleRefreshPreview } = usePasswordConfig({ ...passwordSettings });
const [sliderValue, setSliderValue] = useState(lengthToSlider(passwordSettings.Length));
- const panelRef = useRef<HTMLDivElement>(null);
const isDiceware = settings.Type === 'diceware';
const tk = 'components.main.settings.passwordSettingsPopup';
- useClickOutside([panelRef], onClose, true);
-
// The "auto" language shown when the user has not picked one explicitly, resolved like the Rust core does.
const effectiveLanguage = useMemo(() => resolveDefaultLanguage(i18n.language, dicewareLanguages), [dicewareLanguages, i18n.language]);
const selectedLanguage = settings.Language && settings.Language.length > 0 ? settings.Language : effectiveLanguage;
@@ -136,95 +133,93 @@ const PasswordSettingsPopup: React.FC<PasswordSettingsPopupProps> = ({ passwordS
};
return (
- <div className="modal-dialog fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center">
- <div ref={panelRef} id="passwordSettingsModal" className="relative top-20 mx-auto p-5 pt-0 shadow-lg rounded-md bg-white dark:bg-gray-800 border-2 border-gray-300 dark:border-gray-400 w-96 max-w-[90vw]">
- <div className="m-2">
- <div className="flex border-b border-gray-200 dark:border-gray-700">
- <button type="button" onClick={() => handleSettingChange('Type', 'basic')} className={tabClasses('basic')}>{t(`${tk}.PasswordTypeBasic`)}</button>
- <button type="button" onClick={() => handleSettingChange('Type', 'diceware')} className={tabClasses('diceware')}>{t(`${tk}.PasswordTypeDiceware`)}</button>
- </div>
+ <Modal id="passwordSettingsModal" onBackdropClick={onClose} panelClassName="p-5 pt-0 w-96 max-w-full">
+ <div className="m-2">
+ <div className="flex border-b border-gray-200 dark:border-gray-700">
+ <button type="button" onClick={() => handleSettingChange('Type', 'basic')} className={tabClasses('basic')}>{t(`${tk}.PasswordTypeBasic`)}</button>
+ <button type="button" onClick={() => handleSettingChange('Type', 'diceware')} className={tabClasses('diceware')}>{t(`${tk}.PasswordTypeDiceware`)}</button>
+ </div>
- <div className="mt-4 space-y-4">
- <div>
- <label className="block text-sm font-medium text-gray-700 dark:text-gray-300">{t(`${tk}.PreviewLabel`)}</label>
- <div className="mt-1 flex">
- <div className="flex-grow"><CopyPasteFormRow id="preview-password" value={previewPassword} /></div>
- <button type="button" className="ml-2 px-3 py-2 text-sm text-gray-500 dark:text-white bg-gray-200 hover:bg-gray-300 focus:ring-4 focus:outline-none focus:ring-gray-300 font-medium rounded-md dark:bg-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-800" onClick={handleRefreshPreview}>
- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
- </svg>
- </button>
- </div>
+ <div className="mt-4 space-y-4">
+ <div>
+ <label className="block text-sm font-medium text-gray-700 dark:text-gray-300">{t(`${tk}.PreviewLabel`)}</label>
+ <div className="mt-1 flex">
+ <div className="flex-grow"><CopyPasteFormRow id="preview-password" value={previewPassword} /></div>
+ <button type="button" className="ml-2 px-3 py-2 text-sm text-gray-500 dark:text-white bg-gray-200 hover:bg-gray-300 focus:ring-4 focus:outline-none focus:ring-gray-300 font-medium rounded-md dark:bg-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-800" onClick={handleRefreshPreview}>
+ <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
+ </svg>
+ </button>
</div>
+ </div>
- {!isDiceware ? (
- <>
- <div>
- <label htmlFor="password-length" className="block text-sm font-medium text-gray-700 dark:text-gray-300">{t(`${tk}.PasswordLengthLabel`, { 0: settings.Length })}</label>
- <input type="range" id="password-length" min={SLIDER_MIN} max={SLIDER_MAX} step="0.1" className="mt-1 w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700 av-range-slider" value={sliderValue} onChange={(e) => {
- const value = Number.parseFloat(e.target.value);
- setSliderValue(value);
- handleSettingChange('Length', sliderToLength(value));
- }} />
- </div>
+ {!isDiceware ? (
+ <>
+ <div>
+ <label htmlFor="password-length" className="block text-sm font-medium text-gray-700 dark:text-gray-300">{t(`${tk}.PasswordLengthLabel`, { 0: settings.Length })}</label>
+ <input type="range" id="password-length" min={SLIDER_MIN} max={SLIDER_MAX} step="0.1" className="mt-1 w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700 av-range-slider" value={sliderValue} onChange={(e) => {
+ const value = Number.parseFloat(e.target.value);
+ setSliderValue(value);
+ handleSettingChange('Length', sliderToLength(value));
+ }} />
+ </div>
- <div className="grid grid-cols-2 gap-2">
- <button type="button" className={toggleClasses(settings.UseLowercase)} title={t(`${tk}.IncludeLowercaseLabel`)} onClick={() => handleSettingChange('UseLowercase', !settings.UseLowercase)}><span className="font-mono text-base">a-z</span></button>
- <button type="button" className={toggleClasses(settings.UseUppercase)} title={t(`${tk}.IncludeUppercaseLabel`)} onClick={() => handleSettingChange('UseUppercase', !settings.UseUppercase)}><span className="font-mono text-base">A-Z</span></button>
- <button type="button" className={toggleClasses(settings.UseNumbers)} title={t(`${tk}.IncludeNumbersLabel`)} onClick={() => handleSettingChange('UseNumbers', !settings.UseNumbers)}><span className="font-mono text-base">0-9</span></button>
- <button type="button" className={toggleClasses(settings.UseSpecialChars)} title={t(`${tk}.IncludeSpecialCharsLabel`)} onClick={() => handleSettingChange('UseSpecialChars', !settings.UseSpecialChars)}><span className="font-mono text-base">!@#</span></button>
- </div>
+ <div className="grid grid-cols-2 gap-2">
+ <button type="button" className={toggleClasses(settings.UseLowercase)} title={t(`${tk}.IncludeLowercaseLabel`)} onClick={() => handleSettingChange('UseLowercase', !settings.UseLowercase)}><span className="font-mono text-base">a-z</span></button>
+ <button type="button" className={toggleClasses(settings.UseUppercase)} title={t(`${tk}.IncludeUppercaseLabel`)} onClick={() => handleSettingChange('UseUppercase', !settings.UseUppercase)}><span className="font-mono text-base">A-Z</span></button>
+ <button type="button" className={toggleClasses(settings.UseNumbers)} title={t(`${tk}.IncludeNumbersLabel`)} onClick={() => handleSettingChange('UseNumbers', !settings.UseNumbers)}><span className="font-mono text-base">0-9</span></button>
+ <button type="button" className={toggleClasses(settings.UseSpecialChars)} title={t(`${tk}.IncludeSpecialCharsLabel`)} onClick={() => handleSettingChange('UseSpecialChars', !settings.UseSpecialChars)}><span className="font-mono text-base">!@#</span></button>
+ </div>
- <div className="flex items-center">
- <input id="use-non-ambiguous" type="checkbox" className="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded dark:bg-gray-700 dark:border-gray-600" checked={settings.UseNonAmbiguousChars} onChange={e => handleSettingChange('UseNonAmbiguousChars', e.target.checked)} />
- <label htmlFor="use-non-ambiguous" className="ml-2 block text-sm text-gray-700 dark:text-gray-300">{t(`${tk}.AvoidAmbiguousCharsLabel`)}</label>
- </div>
- </>
- ) : (
- <>
- <div>
- <div className="flex items-center justify-between mb-2">
- <label htmlFor="diceware-word-count" className="text-sm font-medium text-gray-700 dark:text-gray-300">{t(`${tk}.WordCountLabel`)}</label>
- <span className="text-sm text-gray-600 dark:text-gray-400 font-mono">{settings.WordCount}</span>
- </div>
- <input type="range" id="diceware-word-count" min={MIN_WORD_COUNT} max={MAX_WORD_COUNT} step="1" className="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700 av-range-slider" value={settings.WordCount} onChange={e => handleSettingChange('WordCount', Number.parseInt(e.target.value, 10))} />
+ <div className="flex items-center">
+ <input id="use-non-ambiguous" type="checkbox" className="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded dark:bg-gray-700 dark:border-gray-600" checked={settings.UseNonAmbiguousChars} onChange={e => handleSettingChange('UseNonAmbiguousChars', e.target.checked)} />
+ <label htmlFor="use-non-ambiguous" className="ml-2 block text-sm text-gray-700 dark:text-gray-300">{t(`${tk}.AvoidAmbiguousCharsLabel`)}</label>
+ </div>
+ </>
+ ) : (
+ <>
+ <div>
+ <div className="flex items-center justify-between mb-2">
+ <label htmlFor="diceware-word-count" className="text-sm font-medium text-gray-700 dark:text-gray-300">{t(`${tk}.WordCountLabel`)}</label>
+ <span className="text-sm text-gray-600 dark:text-gray-400 font-mono">{settings.WordCount}</span>
</div>
+ <input type="range" id="diceware-word-count" min={MIN_WORD_COUNT} max={MAX_WORD_COUNT} step="1" className="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700 av-range-slider" value={settings.WordCount} onChange={e => handleSettingChange('WordCount', Number.parseInt(e.target.value, 10))} />
+ </div>
- <div className="grid grid-cols-3 gap-2">
- <button type="button" className={optionClasses(settings.Capitalization !== DEFAULT_CAPITALIZATION)} title={t(`${tk}.Capitalization${settings.Capitalization ?? DEFAULT_CAPITALIZATION}`)} onClick={() => handleSettingChange('Capitalization', cycle(CAPITALIZATION_OPTIONS, settings.Capitalization))}>
- <span className="font-mono text-base">{capitalizationGlyph(settings.Capitalization)}</span>
- </button>
- <button type="button" className={optionClasses(settings.Separator !== DEFAULT_SEPARATOR)} title={`${t(`${tk}.SeparatorLabel`)}: ${t(`${tk}.Separator${settings.Separator ?? DEFAULT_SEPARATOR}`)}`} onClick={() => handleSettingChange('Separator', cycle(SEPARATOR_OPTIONS, settings.Separator))}>
- <span className="font-mono text-base">{separatorGlyph(settings.Separator)}</span>
- </button>
- <button type="button" className={optionClasses(settings.Salt !== DEFAULT_SALT)} title={`${t(`${tk}.SaltLabel`)}: ${t(`${tk}.Salt${settings.Salt ?? DEFAULT_SALT}`)}`} onClick={() => handleSettingChange('Salt', cycle(SALT_OPTIONS, settings.Salt))}>
- <span className="font-mono text-base">{saltGlyph(settings.Salt)}</span>
- </button>
- </div>
+ <div className="grid grid-cols-3 gap-2">
+ <button type="button" className={optionClasses(settings.Capitalization !== DEFAULT_CAPITALIZATION)} title={t(`${tk}.Capitalization${settings.Capitalization ?? DEFAULT_CAPITALIZATION}`)} onClick={() => handleSettingChange('Capitalization', cycle(CAPITALIZATION_OPTIONS, settings.Capitalization))}>
+ <span className="font-mono text-base">{capitalizationGlyph(settings.Capitalization)}</span>
+ </button>
+ <button type="button" className={optionClasses(settings.Separator !== DEFAULT_SEPARATOR)} title={`${t(`${tk}.SeparatorLabel`)}: ${t(`${tk}.Separator${settings.Separator ?? DEFAULT_SEPARATOR}`)}`} onClick={() => handleSettingChange('Separator', cycle(SEPARATOR_OPTIONS, settings.Separator))}>
+ <span className="font-mono text-base">{separatorGlyph(settings.Separator)}</span>
+ </button>
+ <button type="button" className={optionClasses(settings.Salt !== DEFAULT_SALT)} title={`${t(`${tk}.SaltLabel`)}: ${t(`${tk}.Salt${settings.Salt ?? DEFAULT_SALT}`)}`} onClick={() => handleSettingChange('Salt', cycle(SALT_OPTIONS, settings.Salt))}>
+ <span className="font-mono text-base">{saltGlyph(settings.Salt)}</span>
+ </button>
+ </div>
- <div>
- <label htmlFor="diceware-language" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{t(`${tk}.LanguageLabel`)}</label>
- <select id="diceware-language" className="w-full px-3 py-2 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md text-gray-900 dark:text-white focus:ring-primary-500 focus:border-primary-500" value={selectedLanguage} onChange={e => handleSettingChange('Language', e.target.value)}>
- {dicewareLanguages.map(language => <option key={language} value={language}>{getLanguageInfo(language).label}</option>)}
- </select>
- </div>
- </>
- )}
+ <div>
+ <label htmlFor="diceware-language" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{t(`${tk}.LanguageLabel`)}</label>
+ <select id="diceware-language" className="w-full px-3 py-2 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md text-gray-900 dark:text-white focus:ring-primary-500 focus:border-primary-500" value={selectedLanguage} onChange={e => handleSettingChange('Language', e.target.value)}>
+ {dicewareLanguages.map(language => <option key={language} value={language}>{getLanguageInfo(language).label}</option>)}
+ </select>
+ </div>
+ </>
+ )}
- <div className="flex justify-end pt-4 gap-2">
- {isTemporary && (
- <button type="button" className="px-4 py-2 bg-gray-200 text-gray-800 dark:bg-gray-700 dark:text-white rounded-md hover:bg-gray-300 dark:hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-500" onClick={onSaveTemporary}>
- {t(`${tk}.UseJustOnceButton`)}
- </button>
- )}
- <button type="button" id="save-button" className="px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 dark:bg-primary-700 dark:hover:bg-primary-600" onClick={() => void onSaveGlobal()}>
- {t(`${tk}.SaveGloballyButton`)}
+ <div className="flex justify-end pt-4 gap-2">
+ {isTemporary && (
+ <button type="button" className="px-4 py-2 bg-gray-200 text-gray-800 dark:bg-gray-700 dark:text-white rounded-md hover:bg-gray-300 dark:hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-500" onClick={onSaveTemporary}>
+ {t(`${tk}.UseJustOnceButton`)}
</button>
- </div>
+ )}
+ <button type="button" id="save-button" className="px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 dark:bg-primary-700 dark:hover:bg-primary-600" onClick={() => void onSaveGlobal()}>
+ {t(`${tk}.SaveGloballyButton`)}
+ </button>
</div>
</div>
</div>
- </div>
+ </Modal>
);
};
diff --git a/apps/web/src/components/settings/importexport/ExportPasswordModal.tsx b/apps/web/src/components/settings/importexport/ExportPasswordModal.tsx
new file mode 100644
index 000000000..2f0f72046
--- /dev/null
+++ b/apps/web/src/components/settings/importexport/ExportPasswordModal.tsx
@@ -0,0 +1,148 @@
+import { MIN_ACCEPTED_PASSWORD_LENGTH } from '@aliasvault/client/utilities/PasswordStrength';
+import React, { useEffect, useRef, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import AlertMessageError from '@/components/alerts/AlertMessageError';
+import PasswordInputField from '@/components/auth/PasswordInputField';
+import FormModal from '@/components/shared/FormModal';
+import PasswordStrengthIndicator from '@/components/shared/PasswordStrengthIndicator';
+
+const VALIDATION_DEBOUNCE_MS = 800;
+
+type ExportPasswordModalProps = {
+ isOpen: boolean;
+ title: string;
+ description: string;
+ errorMessage?: string;
+ onPasswordSubmitted: (password: string) => void;
+ onClose: () => void;
+};
+
+/**
+ * Asks for the password an encrypted (.avex) export is protected with.
+ */
+const ExportPasswordModal: React.FC<ExportPasswordModalProps> = ({ isOpen, title, description, errorMessage = '', onPasswordSubmitted, onClose }) => {
+ const { t } = useTranslation();
+ const tk = 'pages.main.settings.importExport.components.exportPasswordModal';
+ const [exportPassword, setExportPassword] = useState('');
+ const [confirmPassword, setConfirmPassword] = useState('');
+ const [validationError, setValidationError] = useState('');
+ const debounceTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
+
+ // Start clean every time the modal closes.
+ useEffect(() => {
+ if (!isOpen) {
+ setExportPassword('');
+ setConfirmPassword('');
+ setValidationError('');
+ }
+ }, [isOpen]);
+
+ /**
+ * Check length and match.
+ */
+ const validate = (password: string, confirm: string): void => {
+ if (password.trim().length > 0 && password.length < MIN_ACCEPTED_PASSWORD_LENGTH) {
+ setValidationError(t('validationMessages.PasswordMinLengthGeneric', { 0: MIN_ACCEPTED_PASSWORD_LENGTH }));
+ return;
+ }
+ if (confirm.trim().length > 0 && password !== confirm) {
+ setValidationError(t('validationMessages.PasswordsDoNotMatchGeneric'));
+ return;
+ }
+ setValidationError('');
+ };
+
+ /**
+ * Validate after a typing pause.
+ */
+ const handleExportPasswordChange = (value: string): void => {
+ setExportPassword(value);
+ setValidationError('');
+ if (debounceTimer.current) {
+ clearTimeout(debounceTimer.current);
+ }
+ debounceTimer.current = setTimeout(() => validate(value, confirmPassword), VALIDATION_DEBOUNCE_MS);
+ };
+
+ /**
+ * Validate right away.
+ */
+ const handleConfirmPasswordChange = (value: string): void => {
+ setConfirmPassword(value);
+ validate(exportPassword, value);
+ };
+
+ const isPasswordValid = exportPassword.length > 0 && confirmPassword.length > 0 && exportPassword === confirmPassword && validationError.length === 0 && exportPassword.length >= MIN_ACCEPTED_PASSWORD_LENGTH;
+
+ /**
+ * Hand the password to the parent.
+ */
+ const handleSubmit = (): void => {
+ if (!isPasswordValid) {
+ return;
+ }
+ onPasswordSubmitted(exportPassword);
+ setExportPassword('');
+ setConfirmPassword('');
+ setValidationError('');
+ };
+
+ /**
+ * Enter submits, Escape closes.
+ */
+ const handleKeyDown = (e: React.KeyboardEvent): void => {
+ if (e.key === 'Enter' && isPasswordValid) {
+ handleSubmit();
+ } else if (e.key === 'Escape') {
+ onClose();
+ }
+ };
+
+ return (
+ <FormModal
+ isOpen={isOpen}
+ title={title}
+ maxWidth="md"
+ showDefaultFooter={false}
+ onClose={onClose}
+ closeOnOverlayClick={false}
+ submitOnEnter={false}
+ icon={(
+ <svg className="h-6 w-6 text-orange-600 dark:text-orange-400" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5m-13.5-9L12 3m0 0l4.5 4.5M12 3v13.5" />
+ </svg>
+ )}
+ footerContent={(
+ <>
+ <button type="button" onClick={handleSubmit} disabled={!isPasswordValid} className="inline-flex w-full justify-center rounded-md bg-primary-600 hover:bg-primary-700 px-3 py-2 text-sm font-semibold text-white shadow-sm sm:w-auto disabled:opacity-50 disabled:cursor-not-allowed">
+ {t(`${tk}.CreateEncryptedExportButton`)}
+ </button>
+ <button type="button" onClick={onClose} className="mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:mt-0 sm:w-auto dark:bg-gray-700 dark:text-white dark:ring-gray-600 dark:hover:bg-gray-600">
+ {t('sharedResources.Cancel')}
+ </button>
+ </>
+ )}>
+ <div onKeyDown={handleKeyDown}>
+ <p className="text-sm text-gray-500 dark:text-gray-400 mb-4">{description}</p>
+
+ {errorMessage.length > 0 && <AlertMessageError message={errorMessage} hasTopMargin={false} />}
+
+ <div className="mb-4">
+ <label htmlFor="exportPassword" className="block text-sm font-medium text-gray-900 dark:text-white mb-2">{t(`${tk}.ExportPasswordLabel`)}</label>
+ <PasswordInputField id="exportPassword" value={exportPassword} onValueChange={handleExportPasswordChange} autoFocus={true} />
+ <PasswordStrengthIndicator password={exportPassword} />
+ </div>
+
+ <div className="mb-4">
+ <label htmlFor="confirmExportPassword" className="block text-sm font-medium text-gray-900 dark:text-white mb-2">{t(`${tk}.ConfirmExportPasswordLabel`)}</label>
+ <PasswordInputField id="confirmExportPassword" value={confirmPassword} onValueChange={handleConfirmPasswordChange} />
+ </div>
+
+ {validationError.length > 0 && <div className="mt-2 text-sm text-red-600 dark:text-red-400">{validationError}</div>}
+ </div>
+ </FormModal>
+ );
+};
+
+export default ExportPasswordModal;
diff --git a/apps/web/src/components/settings/importexport/ImportServiceCard.tsx b/apps/web/src/components/settings/importexport/ImportServiceCard.tsx
index 6af1752de..368b753ea 100644
--- a/apps/web/src/components/settings/importexport/ImportServiceCard.tsx
+++ b/apps/web/src/components/settings/importexport/ImportServiceCard.tsx
@@ -10,10 +10,10 @@ import { useNavigate } from 'react-router-dom';
import LoadingIndicator from '@/components/loading/LoadingIndicator';
import Button from '@/components/shared/Button';
+import Modal from '@/components/shared/Modal';
import { useDb } from '@/context/DbContext';
import { useNotifications } from '@/context/NotificationContext';
import { useWebApi } from '@/context/WebApiContext';
-import { useClickOutside } from '@/hooks/useClickOutside';
import { useVaultMutate } from '@/hooks/useVaultMutate';
import { delay } from '@/utils/Delay';
@@ -200,7 +200,6 @@ const ImportServiceCard: React.FC<ImportServiceCardProps> = ({ serviceName, desc
const uploadedFilename = useRef<string | null>(null);
const uploadedFileSize = useRef(0);
- const modalRef = useRef<HTMLDivElement>(null);
const fileInputRef = useRef<HTMLInputElement>(null);
/**
@@ -266,8 +265,6 @@ const ImportServiceCard: React.FC<ImportServiceCardProps> = ({ serviceName, desc
uploadedFileSize.current = 0;
}, []);
- useClickOutside([modalRef], closeModal, isModalOpen && !isImporting);
-
/**
* Drop the credentials the vault already holds and determine what is left for the preview.
*/
@@ -640,7 +637,7 @@ const ImportServiceCard: React.FC<ImportServiceCardProps> = ({ serviceName, desc
{showFailureDetails && (
<div className="mt-2 ml-7 flex items-start gap-2">
<textarea readOnly rows={4} value={buildFailureDetailsText()} className="flex-1 text-xs font-mono p-2 rounded border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-900 text-gray-800 dark:text-gray-200 leading-snug" />
- <button type="button" onClick={() => void copyToClipboard(buildFailureDetailsText())} title={t(`${tk}.ImportErrorCopyDetailsButton`)} className="shrink-0 inline-flex items-center gap-1 px-2.5 py-1.5 text-xs font-medium rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700">
+ <button type="button" onClick={() => void copyToClipboard(buildFailureDetailsText())} title={t(`${tk}.ImportErrorCopyDetailsButton`)} className="shrink-0 inline-flex items-center gap-1 px-2.5 py-1.5 text-xs font-medium rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-600">
<svg xmlns="http://www.w3.org/2000/svg" className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2" aria-hidden="true">
<path strokeLinecap="round" strokeLinejoin="round" d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 0 1-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 0 1 1.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 0 0-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 0 1-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H9.75" />
</svg>
@@ -779,32 +776,30 @@ const ImportServiceCard: React.FC<ImportServiceCardProps> = ({ serviceName, desc
</div>
{isModalOpen && (
- <div className="modal-dialog fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-start justify-center" onKeyDown={handleModalKeyDown}>
- <div ref={modalRef} id="importServiceModal" className="relative mt-[160px] mb-8 mx-auto p-5 shadow-lg rounded-md bg-white dark:bg-gray-800 border-2 border-gray-300 dark:border-gray-400 md:min-w-[32rem]">
- <div className="bg-white dark:bg-gray-800 rounded-lg p-4 w-full mx-auto">
- <div className="flex justify-between items-center mb-4">
- <div className="flex">
- <img src={logoUrl} alt={`${serviceName} logo`} className="w-8 h-8 float-left mr-4" />
- <h3 className="text-xl font-semibold dark:text-white">{t(`${tk}.ImportFromServiceTitle`, { 0: serviceName })}</h3>
- </div>
- <button type="button" onClick={closeModal} className="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300">
- <svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12"></path>
- </svg>
- </button>
- </div>
-
- <div className="w-full bg-gray-200 rounded-full h-2.5 mb-4 dark:bg-gray-700">
- <div className="bg-primary-600 h-2.5 rounded-full transition-all duration-300" style={{ width: `${progressPercentage}%` }}></div>
+ <Modal id="importServiceModal" position="top" onKeyDown={handleModalKeyDown} onBackdropClick={currentStep === ImportStep.FileUpload && !isImporting ? closeModal : undefined} panelClassName="p-5 md:min-w-[32rem]">
+ <div className="p-4 w-full mx-auto">
+ <div className="flex justify-between items-center mb-4">
+ <div className="flex">
+ <img src={logoUrl} alt={`${serviceName} logo`} className="w-8 h-8 float-left mr-4" />
+ <h3 className="text-xl font-semibold dark:text-white">{t(`${tk}.ImportFromServiceTitle`, { 0: serviceName })}</h3>
</div>
+ <button type="button" onClick={closeModal} className="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300">
+ <svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12"></path>
+ </svg>
+ </button>
+ </div>
- {currentStep === ImportStep.FileUpload && renderFileUploadStep()}
- {currentStep === ImportStep.PasswordInput && renderPasswordInputStep()}
- {currentStep === ImportStep.Preview && renderPreviewStep()}
- {currentStep === ImportStep.Confirm && renderConfirmStep()}
+ <div className="w-full bg-gray-200 rounded-full h-2.5 mb-4 dark:bg-gray-700">
+ <div className="bg-primary-600 h-2.5 rounded-full transition-all duration-300" style={{ width: `${progressPercentage}%` }}></div>
</div>
+
+ {currentStep === ImportStep.FileUpload && renderFileUploadStep()}
+ {currentStep === ImportStep.PasswordInput && renderPasswordInputStep()}
+ {currentStep === ImportStep.Preview && renderPreviewStep()}
+ {currentStep === ImportStep.Confirm && renderConfirmStep()}
</div>
- </div>
+ </Modal>
)}
</>
);
diff --git a/apps/web/src/components/shared/ConfirmModal.tsx b/apps/web/src/components/shared/ConfirmModal.tsx
index a3a367c49..4799bdde9 100644
--- a/apps/web/src/components/shared/ConfirmModal.tsx
+++ b/apps/web/src/components/shared/ConfirmModal.tsx
@@ -1,4 +1,6 @@
-import React from 'react';
+import React, { useEffect } from 'react';
+
+import Modal from '@/components/shared/Modal';
type ConfirmModalProps = {
title: string;
@@ -10,15 +12,29 @@ type ConfirmModalProps = {
};
/**
- * Confirm dialog.
+ * Confirm dialog. A backdrop click or Escape counts as cancel.
*/
-const ConfirmModal: React.FC<ConfirmModalProps> = ({ title, message, confirmText, cancelText, onClose }) => (
- <div id="confirm-modal" className="fixed inset-0 z-[1000] bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full flex items-center justify-center">
- <div className="relative p-5 border w-96 shadow-lg rounded-md bg-white">
+const ConfirmModal: React.FC<ConfirmModalProps> = ({ title, message, confirmText, cancelText, onClose }) => {
+ useEffect(() => {
+ /**
+ * Escape cancels. Caught before it reaches the document, so a modal underneath does not close too.
+ */
+ const onKeyDown = (e: KeyboardEvent): void => {
+ if (e.key === 'Escape') {
+ e.stopPropagation();
+ onClose(false);
+ }
+ };
+ window.addEventListener('keydown', onKeyDown, true);
+ return (): void => window.removeEventListener('keydown', onKeyDown, true);
+ }, [onClose]);
+
+ return (
+ <Modal id="confirm-modal" zIndexClass="z-[1000]" panelClassName="p-5 w-96 max-w-full" onBackdropClick={() => onClose(false)}>
<div className="mt-3 text-center">
- <h3 className="text-lg leading-6 font-medium text-gray-900">{title}</h3>
+ <h3 className="text-lg leading-6 font-medium text-gray-900 dark:text-white">{title}</h3>
<div className="mt-2 px-7 py-3">
- <p className="text-sm text-gray-500">
+ <p className="text-sm text-gray-500 dark:text-gray-300">
{message.split('\n').map((line, index) => (
<React.Fragment key={index}>
{index > 0 && <br />}
@@ -28,18 +44,18 @@ const ConfirmModal: React.FC<ConfirmModalProps> = ({ title, message, confirmText
</p>
</div>
<div className="items-center px-4 py-3">
- <button id="confirmButton" className="px-4 py-2 bg-primary-500 text-white text-base font-medium rounded-md w-full shadow-sm hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-300" onClick={() => onClose(true)}>
+ <button id="confirmButton" className="px-4 py-2 bg-primary-500 text-white text-base font-medium rounded-md w-full shadow-sm hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800" onClick={() => onClose(true)}>
{confirmText}
</button>
{cancelText && (
- <button id="cancelButton" className="mt-3 px-4 py-2 bg-gray-300 text-gray-800 text-base font-medium rounded-md w-full shadow-sm hover:bg-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300" onClick={() => onClose(false)}>
+ <button id="cancelButton" className="mt-3 px-4 py-2 bg-gray-300 text-gray-800 text-base font-medium rounded-md w-full shadow-sm hover:bg-gray-400 focus:outline-none focus:ring-2 focus:ring-gray-300 dark:bg-gray-500 dark:text-white dark:hover:bg-gray-600 dark:focus:ring-gray-400" onClick={() => onClose(false)}>
{cancelText}
</button>
)}
</div>
</div>
- </div>
- </div>
-);
+ </Modal>
+ );
+};
export default ConfirmModal;
diff --git a/apps/web/src/components/shared/FormModal.tsx b/apps/web/src/components/shared/FormModal.tsx
index 95aeac57a..0b21b3c80 100644
--- a/apps/web/src/components/shared/FormModal.tsx
+++ b/apps/web/src/components/shared/FormModal.tsx
@@ -1,6 +1,8 @@
import React, { useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
+import Modal from '@/components/shared/Modal';
+
type FormModalProps = {
isOpen: boolean;
title?: string;
@@ -69,61 +71,55 @@ const FormModal: React.FC<FormModalProps> = ({
};
return (
- <div className="fixed inset-0 z-50 overflow-y-auto">
- <div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
- <div className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity dark:bg-gray-900 dark:bg-opacity-75" onClick={() => closeOnOverlayClick && onClose()}></div>
-
- <div ref={panelRef} onKeyDown={handleKeyDown} tabIndex={0} className={`relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all sm:my-8 sm:w-full ${getMaxWidthClass(maxWidth)} dark:bg-gray-800`}>
- <div className="px-4 pb-4 pt-5 sm:p-6">
- <div className="sm:flex sm:items-start">
- {icon && (
- <div className={`mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full ${iconBackgroundClass} sm:mx-0 sm:h-10 sm:w-10`}>
- {icon}
- </div>
- )}
- <div className={`${icon ? 'mt-3 text-center sm:ml-4 sm:mt-0 sm:text-left' : ''} flex-1`}>
- {title && (
- <h3 className="text-lg font-semibold leading-6 text-gray-900 dark:text-white">
- {title}
- </h3>
- )}
- <div className={title ? 'mt-4' : ''}>
- {children}
- </div>
- </div>
+ <Modal panelRef={panelRef} tabIndex={0} onKeyDown={handleKeyDown} onBackdropClick={closeOnOverlayClick ? onClose : undefined} panelClassName={`w-full overflow-hidden text-left outline-none ${getMaxWidthClass(maxWidth)}`}>
+ <div className="px-4 pb-4 pt-5 sm:p-6">
+ <div className="sm:flex sm:items-start">
+ {icon && (
+ <div className={`mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full ${iconBackgroundClass} sm:mx-0 sm:h-10 sm:w-10`}>
+ {icon}
</div>
-
- {footerContent ? (
- <div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse gap-2">
- {footerContent}
- </div>
- ) : showDefaultFooter && (
- <div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse gap-2">
- <button
- type="button"
- onClick={onConfirm}
- disabled={isLoading || confirmDisabled}
- className={`inline-flex w-full justify-center rounded-md ${confirmButtonClass} px-3 py-2 text-sm font-semibold text-white shadow-sm sm:w-auto disabled:opacity-50 disabled:cursor-not-allowed`}>
- {isLoading && (
- <svg className="animate-spin -ml-1 mr-2 h-4 w-4 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
- <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
- <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
- </svg>
- )}
- {confirmText ?? t('sharedResources.Confirm')}
- </button>
- <button
- type="button"
- onClick={onClose}
- className="mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:mt-0 sm:w-auto dark:bg-gray-700 dark:text-white dark:ring-gray-600 dark:hover:bg-gray-600">
- {cancelText ?? t('sharedResources.Cancel')}
- </button>
- </div>
+ )}
+ <div className={`${icon ? 'mt-3 text-center sm:ml-4 sm:mt-0 sm:text-left' : ''} flex-1`}>
+ {title && (
+ <h3 className="text-lg font-semibold leading-6 text-gray-900 dark:text-white">
+ {title}
+ </h3>
)}
+ <div className={title ? 'mt-4' : ''}>
+ {children}
+ </div>
</div>
</div>
+
+ {footerContent ? (
+ <div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse gap-2">
+ {footerContent}
+ </div>
+ ) : showDefaultFooter && (
+ <div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse gap-2">
+ <button
+ type="button"
+ onClick={onConfirm}
+ disabled={isLoading || confirmDisabled}
+ className={`inline-flex w-full justify-center rounded-md ${confirmButtonClass} px-3 py-2 text-sm font-semibold text-white shadow-sm sm:w-auto disabled:opacity-50 disabled:cursor-not-allowed`}>
+ {isLoading && (
+ <svg className="animate-spin -ml-1 mr-2 h-4 w-4 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
+ <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
+ <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
+ </svg>
+ )}
+ {confirmText ?? t('sharedResources.Confirm')}
+ </button>
+ <button
+ type="button"
+ onClick={onClose}
+ className="mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:mt-0 sm:w-auto dark:bg-gray-700 dark:text-white dark:ring-gray-600 dark:hover:bg-gray-600">
+ {cancelText ?? t('sharedResources.Cancel')}
+ </button>
+ </div>
+ )}
</div>
- </div>
+ </Modal>
);
};
diff --git a/apps/web/src/components/shared/Modal.tsx b/apps/web/src/components/shared/Modal.tsx
new file mode 100644
index 000000000..0c78f031d
--- /dev/null
+++ b/apps/web/src/components/shared/Modal.tsx
@@ -0,0 +1,40 @@
+import React from 'react';
+
+type ModalProps = {
+ children: React.ReactNode;
+ id?: string;
+ panelRef?: React.Ref<HTMLDivElement>;
+ /** Size and layout of the panel, e.g. `w-full max-w-2xl flex flex-col`. */
+ panelClassName?: string;
+ position?: 'center' | 'top';
+ zIndexClass?: string;
+ tabIndex?: number;
+ onBackdropClick?: () => void;
+ onKeyDown?: (e: React.KeyboardEvent) => void;
+};
+
+/**
+ * Backdrop and panel surface shared by every modal.
+ */
+const Modal: React.FC<ModalProps> = ({ children, id, panelRef, panelClassName = '', position = 'center', zIndexClass = 'z-50', tabIndex, onBackdropClick, onKeyDown }) => {
+ /**
+ * Only a click that lands on the backdrop counts, not one that bubbles up from the panel.
+ */
+ const handleBackdropClick = (e: React.MouseEvent<HTMLDivElement>): void => {
+ if (e.target === e.currentTarget) {
+ onBackdropClick?.();
+ }
+ };
+
+ return (
+ <div className={`fixed inset-0 ${zIndexClass} overflow-y-auto bg-gray-600/50 backdrop-blur-sm dark:bg-black/80`} onKeyDown={onKeyDown}>
+ <div className={`flex min-h-full justify-center p-4 ${position === 'top' ? 'items-start pt-40 pb-8' : 'items-center'}`} onClick={handleBackdropClick}>
+ <div ref={panelRef} id={id} tabIndex={tabIndex} className={`relative rounded-lg border border-gray-200 bg-white shadow-xl dark:border-gray-600 dark:bg-gray-800 dark:shadow-2xl ${panelClassName}`}>
+ {children}
+ </div>
+ </div>
+ </div>
+ );
+};
+
+export default Modal;
diff --git a/apps/web/src/components/shared/PasswordConfirmationModal.tsx b/apps/web/src/components/shared/PasswordConfirmationModal.tsx
index b5d34b2d8..d2ad259c1 100644
--- a/apps/web/src/components/shared/PasswordConfirmationModal.tsx
+++ b/apps/web/src/components/shared/PasswordConfirmationModal.tsx
@@ -58,6 +58,7 @@ const PasswordConfirmationModal: React.FC<PasswordConfirmationModalProps> = ({ i
confirmDisabled={password.length === 0}
onConfirm={handleConfirm}
onClose={handleClose}
+ closeOnOverlayClick={false}
submitOnEnter={true}
icon={(
<svg className="h-6 w-6 text-orange-600 dark:text-orange-400" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">