Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor out isolated logic from ItemAddEdit.tsx (#1404)
Leendert de Borst60114b4c2910
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Forms/AddFieldMenu.tsx b/apps/browser-extension/src/entrypoints/popup/components/Forms/AddFieldMenu.tsxnew file mode 100644index 000000000..01987a085--- /dev/null+++ b/apps/browser-extension/src/entrypoints/popup/components/Forms/AddFieldMenu.tsx@@ -0,0 +1,309 @@+import React, { useState, useCallback, useMemo } from 'react';+import { useTranslation } from 'react-i18next';++import type { FieldType, ItemType } from '@/utils/dist/shared/models/vault';++/**+ * Visibility state for optional sections.+ */+type SectionVisibility = {+ showNotes: boolean;+ show2FA: boolean;+ showAttachments: boolean;+};++/**+ * Callbacks for adding optional sections.+ */+type SectionCallbacks = {+ onAddNotes: () => void;+ onAdd2FA: () => void;+ onAddAttachments: () => void;+ onAddCustomField: (label: string, fieldType: FieldType) => void;+};++type AddFieldMenuProps = {+ itemType: ItemType;+ isEditMode: boolean;+ visibility: SectionVisibility;+ callbacks: SectionCallbacks;+};++/**+ * Menu option for internal use.+ */+type MenuOption = {+ key: string;+ label: string;+ icon: React.ReactNode;+ action: () => void;+};++/**+ * Notes icon for menu option.+ */+const NotesIcon: React.FC = () => (+ <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />+ </svg>+);++/**+ * Lock icon for 2FA menu option.+ */+const LockIcon: React.FC = () => (+ <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />+ </svg>+);++/**+ * Attachment icon for menu option.+ */+const AttachmentIcon: React.FC = () => (+ <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <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" />+ </svg>+);++/**+ * Plus icon for add button and custom field option.+ */+const PlusIcon: React.FC = () => (+ <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6" />+ </svg>+);++/**+ * A dropdown menu for adding optional fields and sections to an item.+ * Includes built-in logic for determining which options to show based on item type.+ * Also includes the custom field modal.+ */+const AddFieldMenu: React.FC<AddFieldMenuProps> = ({+ itemType,+ isEditMode,+ visibility,+ callbacks+}) => {+ const { t } = useTranslation();+ const [isOpen, setIsOpen] = useState(false);+ const [showCustomFieldModal, setShowCustomFieldModal] = useState(false);+ const [customFieldLabel, setCustomFieldLabel] = useState('');+ const [customFieldType, setCustomFieldType] = useState<FieldType>('Text');++ /**+ * Handle opening the custom field modal.+ */+ const handleOpenCustomFieldModal = useCallback((): void => {+ setShowCustomFieldModal(true);+ setIsOpen(false);+ }, []);++ /**+ * Handle adding the custom field.+ */+ const handleAddCustomField = useCallback((): void => {+ if (!customFieldLabel.trim()) {+ return;+ }++ callbacks.onAddCustomField(customFieldLabel, customFieldType);+ setCustomFieldLabel('');+ setCustomFieldType('Text');+ setShowCustomFieldModal(false);+ }, [customFieldLabel, customFieldType, callbacks]);++ /**+ * Handle closing the custom field modal.+ */+ const handleCloseCustomFieldModal = useCallback((): void => {+ setCustomFieldLabel('');+ setCustomFieldType('Text');+ setShowCustomFieldModal(false);+ }, []);++ /**+ * Handle adding notes and closing menu.+ */+ const handleAddNotes = useCallback((): void => {+ callbacks.onAddNotes();+ setIsOpen(false);+ }, [callbacks]);++ /**+ * Handle adding 2FA and closing menu.+ */+ const handleAdd2FA = useCallback((): void => {+ callbacks.onAdd2FA();+ setIsOpen(false);+ }, [callbacks]);++ /**+ * Handle adding attachments and closing menu.+ */+ const handleAddAttachments = useCallback((): void => {+ callbacks.onAddAttachments();+ setIsOpen(false);+ }, [callbacks]);++ /**+ * Build menu options based on item type and current visibility.+ */+ const menuOptions = useMemo((): MenuOption[] => {+ const options: MenuOption[] = [];++ /*+ * Notes option - available for all types when not already shown.+ * In edit mode, notes are always shown if they have content, so we don't need to show the option.+ */+ if (!visibility.showNotes && !isEditMode) {+ options.push({+ key: 'notes',+ label: t('credentials.notes'),+ icon: <NotesIcon />,+ action: handleAddNotes+ });+ }++ // 2FA TOTP option - only for Login and Alias types+ const supports2FA = itemType === 'Login' || itemType === 'Alias';+ if (supports2FA && !visibility.show2FA) {+ options.push({+ key: '2fa',+ label: t('common.twoFactorAuthentication'),+ icon: <LockIcon />,+ action: handleAdd2FA+ });+ }++ // Attachments option - available for all types when not already shown+ if (!visibility.showAttachments) {+ options.push({+ key: 'attachments',+ label: t('common.attachments'),+ icon: <AttachmentIcon />,+ action: handleAddAttachments+ });+ }++ return options;+ }, [itemType, isEditMode, visibility, t, handleAddNotes, handleAdd2FA, handleAddAttachments]);++ return (+ <>+ <div className="relative">+ <button+ type="button"+ onClick={() => setIsOpen(!isOpen)}+ className="w-full px-4 py-3 border-2 border-dashed border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-400 rounded-md hover:border-primary-500 hover:text-primary-600 dark:hover:text-primary-400 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 transition-colors flex items-center justify-center gap-2"+ >+ <PlusIcon />+ </button>++ {/* Dropdown Menu */}+ {isOpen && (+ <>+ <div+ className="fixed inset-0 z-10"+ onClick={() => setIsOpen(false)}+ />+ <div className="absolute bottom-full left-0 right-0 mb-1 z-20 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md shadow-lg overflow-hidden">+ {menuOptions.map((option) => (+ <button+ key={option.key}+ type="button"+ onClick={option.action}+ className="w-full px-4 py-3 text-left hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-3 border-b border-gray-100 dark:border-gray-700 last:border-b-0 text-gray-700 dark:text-gray-300"+ >+ <span className="text-gray-500 dark:text-gray-400">+ {option.icon}+ </span>+ <span>{option.label}</span>+ </button>+ ))}+ {/* Custom field option - always available */}+ <button+ type="button"+ onClick={handleOpenCustomFieldModal}+ className="w-full px-4 py-3 text-left hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-3 border-b border-gray-100 dark:border-gray-700 last:border-b-0 text-gray-700 dark:text-gray-300"+ >+ <span className="text-gray-500 dark:text-gray-400">+ <PlusIcon />+ </span>+ <span>{t('itemTypes.addCustomField')}</span>+ </button>+ </div>+ </>+ )}+ </div>++ {/* Custom Field Modal */}+ {showCustomFieldModal && (+ <div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">+ <div className="bg-white dark:bg-gray-800 rounded-lg shadow-xl p-6 w-96 max-w-full mx-4">+ <h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">+ {t('itemTypes.addCustomField')}+ </h3>++ <div className="space-y-4">+ <div>+ <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">+ {t('itemTypes.fieldLabel')}+ </label>+ <input+ type="text"+ value={customFieldLabel}+ onChange={(e) => setCustomFieldLabel(e.target.value)}+ className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white"+ placeholder={t('itemTypes.enterFieldName')}+ autoFocus+ />+ </div>++ <div>+ <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">+ {t('itemTypes.fieldType')}+ </label>+ <select+ value={customFieldType}+ onChange={(e) => setCustomFieldType(e.target.value as FieldType)}+ className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white"+ >+ <option value="Text">{t('itemTypes.fieldTypes.text')}</option>+ <option value="Hidden">{t('itemTypes.fieldTypes.hidden')}</option>+ <option value="Email">{t('itemTypes.fieldTypes.email')}</option>+ <option value="URL">{t('itemTypes.fieldTypes.url')}</option>+ <option value="Phone">{t('itemTypes.fieldTypes.phone')}</option>+ <option value="Number">{t('itemTypes.fieldTypes.number')}</option>+ <option value="Date">{t('itemTypes.fieldTypes.date')}</option>+ <option value="TextArea">{t('itemTypes.fieldTypes.textArea')}</option>+ </select>+ </div>+ </div>++ <div className="flex gap-3 mt-6">+ <button+ type="button"+ onClick={handleAddCustomField}+ disabled={!customFieldLabel.trim()}+ className="flex-1 px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed"+ >+ {t('common.add')}+ </button>+ <button+ type="button"+ onClick={handleCloseCustomFieldModal}+ className="px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-md hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"+ >+ {t('common.cancel')}+ </button>+ </div>+ </div>+ </div>+ )}+ </>+ );+};++export default AddFieldMenu;diff --git a/apps/browser-extension/src/entrypoints/popup/components/Forms/FormSection.tsx b/apps/browser-extension/src/entrypoints/popup/components/Forms/FormSection.tsxnew file mode 100644index 000000000..62de33b68--- /dev/null+++ b/apps/browser-extension/src/entrypoints/popup/components/Forms/FormSection.tsx@@ -0,0 +1,37 @@+import React from 'react';++type FormSectionProps = {+ title?: string;+ children: React.ReactNode;+ actions?: React.ReactNode;+};++/**+ * A reusable form section container with consistent styling.+ * Used for grouping related form fields with an optional title and action buttons.+ */+const FormSection: React.FC<FormSectionProps> = ({+ title,+ children,+ actions+}) => {+ return (+ <div className="bg-white dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700">+ {title && (+ <h2 className="text-lg font-semibold mb-4 text-gray-900 dark:text-white flex items-center justify-between">+ <span>{title}</span>+ {actions && (+ <div className="flex items-center gap-2">+ {actions}+ </div>+ )}+ </h2>+ )}+ <div className="space-y-4">+ {children}+ </div>+ </div>+ );+};++export default FormSection;diff --git a/apps/browser-extension/src/entrypoints/popup/components/Items/ItemNameInput.tsx b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemNameInput.tsxnew file mode 100644index 000000000..2d27b5978--- /dev/null+++ b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemNameInput.tsx@@ -0,0 +1,193 @@+import React, { useState, useCallback } from 'react';+import { useTranslation } from 'react-i18next';++type Folder = {+ Id: string;+ Name: string;+};++type ItemNameInputProps = {+ inputRef?: React.RefObject<HTMLInputElement | null>;+ value: string;+ onChange: (value: string) => void;+ folders: Folder[];+ selectedFolderId: string | null | undefined;+ onFolderChange: (folderId: string | null) => void;+};++/**+ * Item name input field with an integrated folder selection button and modal.+ * The folder button appears inside the input when folders are available.+ */+const ItemNameInput: React.FC<ItemNameInputProps> = ({+ inputRef,+ value,+ onChange,+ folders,+ selectedFolderId,+ onFolderChange+}) => {+ const { t } = useTranslation();+ const [showFolderModal, setShowFolderModal] = useState(false);++ const selectedFolder = folders.find(f => f.Id === selectedFolderId);+ const hasFolders = folders.length > 0;++ /**+ * Handle folder selection and close the modal.+ */+ const handleSelectFolder = useCallback((folderId: string | null): void => {+ onFolderChange(folderId);+ setShowFolderModal(false);+ }, [onFolderChange]);++ /**+ * Handle name input change.+ */+ const handleNameChange = useCallback((e: React.ChangeEvent<HTMLInputElement>): void => {+ onChange(e.target.value);+ }, [onChange]);++ /**+ * Handle opening folder modal.+ */+ const handleOpenFolderModal = useCallback((): void => {+ setShowFolderModal(true);+ }, []);++ /**+ * Handle closing folder modal.+ */+ const handleCloseFolderModal = useCallback((): void => {+ setShowFolderModal(false);+ }, []);++ return (+ <>+ <div>+ <label htmlFor="itemName" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">+ {t('credentials.itemName')} <span className="text-red-500">*</span>+ </label>+ <div className="relative">+ <input+ ref={inputRef}+ id="itemName"+ type="text"+ value={value}+ onChange={handleNameChange}+ placeholder={t('credentials.itemName')}+ className={`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white ${hasFolders ? 'pr-28' : ''}`}+ required+ />+ {/* Folder Button inside input */}+ {hasFolders && (+ <button+ type="button"+ onClick={handleOpenFolderModal}+ className={`absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-1 px-2 py-1 rounded transition-colors text-xs ${+ selectedFolderId+ ? 'bg-primary-100 dark:bg-primary-900/30 text-primary-600 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-900/50'+ : 'text-gray-400 dark:text-gray-500 hover:text-gray-500 dark:hover:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-600'+ }`}+ title={selectedFolder?.Name || t('items.noFolder')}+ >+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />+ </svg>+ {selectedFolderId && (+ <span className="max-w-16 truncate">+ {selectedFolder?.Name}+ </span>+ )}+ </button>+ )}+ </div>+ </div>++ {/* Folder Selection Modal */}+ {showFolderModal && (+ <div className="fixed inset-0 z-50 overflow-y-auto">+ {/* Backdrop */}+ <div+ className="fixed inset-0 bg-black bg-opacity-80 transition-opacity"+ onClick={handleCloseFolderModal}+ />++ {/* Modal */}+ <div className="fixed inset-0 flex items-center justify-center p-4">+ <div className="relative transform overflow-hidden rounded-lg bg-white dark:bg-gray-800 px-4 pb-4 pt-5 text-left shadow-xl transition-all w-full max-w-sm">+ {/* Close button */}+ <button+ type="button"+ className="absolute right-4 top-4 text-gray-400 hover:text-gray-500 focus:outline-none"+ onClick={handleCloseFolderModal}+ >+ <span className="sr-only">{t('common.close')}</span>+ <svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">+ <path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />+ </svg>+ </button>++ {/* Content */}+ <div className="mb-4">+ <h3 className="text-lg font-semibold leading-6 text-gray-900 dark:text-white">+ {t('items.folder')}+ </h3>+ </div>++ {/* Folder Options */}+ <div className="space-y-1 max-h-64 overflow-y-auto">+ {/* No Folder Option */}+ <button+ type="button"+ onClick={() => handleSelectFolder(null)}+ className={`w-full px-3 py-2 text-left rounded-md flex items-center gap-3 transition-colors ${+ !selectedFolderId+ ? 'bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300'+ : 'text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700'+ }`}+ >+ <svg className={`w-5 h-5 ${!selectedFolderId ? 'text-primary-500' : 'text-gray-400'}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4" />+ </svg>+ <span className="font-medium">{t('items.noFolder')}</span>+ {!selectedFolderId && (+ <svg className="w-5 h-5 ml-auto text-primary-600 dark:text-primary-400" fill="currentColor" viewBox="0 0 20 20">+ <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />+ </svg>+ )}+ </button>++ {/* Folder Options */}+ {folders.map(folder => (+ <button+ key={folder.Id}+ type="button"+ onClick={() => handleSelectFolder(folder.Id)}+ className={`w-full px-3 py-2 text-left rounded-md flex items-center gap-3 transition-colors ${+ selectedFolderId === folder.Id+ ? 'bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300'+ : 'text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700'+ }`}+ >+ <svg className={`w-5 h-5 ${selectedFolderId === folder.Id ? 'text-primary-500' : 'text-gray-400'}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />+ </svg>+ <span className="font-medium">{folder.Name}</span>+ {selectedFolderId === folder.Id && (+ <svg className="w-5 h-5 ml-auto text-primary-600 dark:text-primary-400" fill="currentColor" viewBox="0 0 20 20">+ <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />+ </svg>+ )}+ </button>+ ))}+ </div>+ </div>+ </div>+ </div>+ )}+ </>+ );+};++export default ItemNameInput;diff --git a/apps/browser-extension/src/entrypoints/popup/components/Items/ItemTypeSelector.tsx b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemTypeSelector.tsxnew file mode 100644index 000000000..0d355859e--- /dev/null+++ b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemTypeSelector.tsx@@ -0,0 +1,167 @@+import React from 'react';+import { useTranslation } from 'react-i18next';++import type { ItemType } from '@/utils/dist/shared/models/vault';++/**+ * Item type option configuration.+ */+type ItemTypeOption = {+ type: ItemType;+ titleKey: string;+ iconSvg: React.ReactNode;+};++/**+ * Available item type options with icons.+ */+const ITEM_TYPE_OPTIONS: ItemTypeOption[] = [+ {+ type: 'Login',+ titleKey: 'itemTypes.login.title',+ iconSvg: (+ <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z" />+ </svg>+ )+ },+ {+ type: 'Alias',+ titleKey: 'itemTypes.alias.title',+ iconSvg: (+ <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />+ </svg>+ )+ },+ {+ type: 'CreditCard',+ titleKey: 'itemTypes.creditCard.title',+ iconSvg: (+ <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" />+ </svg>+ )+ },+ {+ type: 'Note',+ titleKey: 'itemTypes.note.title',+ iconSvg: (+ <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />+ </svg>+ )+ }+];++type ItemTypeSelectorProps = {+ selectedType: ItemType;+ isEditMode: boolean;+ showDropdown: boolean;+ onDropdownToggle: (show: boolean) => void;+ onTypeChange: (type: ItemType) => void;+ onRegenerateAlias?: () => void;+};++/**+ * Item type selector component with dropdown menu.+ * Allows selecting between Login, Alias, CreditCard, and Note types.+ */+const ItemTypeSelector: React.FC<ItemTypeSelectorProps> = ({+ selectedType,+ isEditMode,+ showDropdown,+ onDropdownToggle,+ onTypeChange,+ onRegenerateAlias+}) => {+ const { t } = useTranslation();++ const selectedTypeOption = ITEM_TYPE_OPTIONS.find(opt => opt.type === selectedType);++ return (+ <div className="relative">+ <div className="w-full px-4 py-2 bg-primary-50 dark:bg-primary-900/20 border border-primary-200 dark:border-primary-800 rounded-lg flex items-center gap-2">+ <button+ type="button"+ onClick={() => onDropdownToggle(!showDropdown)}+ className="flex-1 flex items-center justify-between hover:opacity-80 transition-opacity"+ >+ <div className="flex items-center gap-2">+ <span className="text-primary-600 dark:text-primary-400">+ {selectedTypeOption?.iconSvg}+ </span>+ <span className="text-primary-700 dark:text-primary-300 font-medium text-sm">+ {isEditMode ? t('itemTypes.editing') : t('itemTypes.creating')} {selectedTypeOption ? t(selectedTypeOption.titleKey) : ''}+ </span>+ </div>+ <svg+ className={`w-4 h-4 text-primary-500 transition-transform ${showDropdown ? 'rotate-180' : ''}`}+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ >+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />+ </svg>+ </button>+ {/* Regenerate alias button - icon only for flexibility */}+ {selectedType === 'Alias' && !isEditMode && onRegenerateAlias && (+ <button+ type="button"+ onClick={(e) => {+ e.stopPropagation();+ onRegenerateAlias();+ }}+ className="flex-shrink-0 p-1.5 text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 hover:bg-primary-100 dark:hover:bg-primary-900/40 rounded transition-colors"+ title={t('itemTypes.regenerateAlias')}+ >+ <svg className='w-4 h-4' viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">+ <path d="M23 4v6h-6"/>+ <path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>+ </svg>+ </button>+ )}+ </div>++ {/* Type Dropdown Menu */}+ {showDropdown && (+ <>+ <div+ className="fixed inset-0 z-10"+ onClick={() => onDropdownToggle(false)}+ />+ <div className="absolute z-20 mt-1 w-full bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md shadow-lg">+ {ITEM_TYPE_OPTIONS.map((option) => (+ <button+ key={option.type}+ type="button"+ onClick={() => onTypeChange(option.type)}+ className={`w-full px-4 py-3 text-left hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-3 border-b border-gray-100 dark:border-gray-700 last:border-b-0 ${+ selectedType === option.type+ ? 'bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300'+ : 'text-gray-900 dark:text-white'+ }`}+ >+ <span className={selectedType === option.type ? 'text-primary-600 dark:text-primary-400' : 'text-gray-500 dark:text-gray-400'}>+ {option.iconSvg}+ </span>+ <span className="font-medium">+ {t(option.titleKey)}+ </span>+ {selectedType === option.type && (+ <svg className="w-5 h-5 ml-auto text-primary-600 dark:text-primary-400" fill="currentColor" viewBox="0 0 20 20">+ <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />+ </svg>+ )}+ </button>+ ))}+ </div>+ </>+ )}+ </div>+ );+};++export default ItemTypeSelector;+export { ITEM_TYPE_OPTIONS };+export type { ItemTypeOption };diff --git a/apps/browser-extension/src/entrypoints/popup/hooks/useAliasGenerator.ts b/apps/browser-extension/src/entrypoints/popup/hooks/useAliasGenerator.tsnew file mode 100644index 000000000..6c98c5006--- /dev/null+++ b/apps/browser-extension/src/entrypoints/popup/hooks/useAliasGenerator.ts@@ -0,0 +1,128 @@+import { useCallback, useState, type Dispatch, type SetStateAction } from 'react';++import { useDb } from '@/entrypoints/popup/context/DbContext';++import { IdentityHelperUtils, CreateIdentityGenerator, convertAgeRangeToBirthdateOptions } from '@/utils/dist/shared/identity-generator';+import { CreatePasswordGenerator } from '@/utils/dist/shared/password-generator';++/**+ * Generated alias data returned by the hook.+ */+type GeneratedAliasData = {+ email: string;+ firstName: string;+ lastName: string;+ nickname: string;+ gender: string;+ birthdate: string;+ username: string;+ password: string;+};++/**+ * Tracking state for last generated values.+ */+type LastGeneratedValues = {+ username: string | null;+ password: string | null;+ email: string | null;+};++/**+ * Hook for generating random alias identity data.+ * Handles identity and password generation based on user preferences.+ */+const useAliasGenerator = (): {+ generateAlias: () => Promise<GeneratedAliasData | null>;+ lastGeneratedValues: LastGeneratedValues;+ setLastGeneratedValues: Dispatch<SetStateAction<LastGeneratedValues>>;+} => {+ const dbContext = useDb();++ const [lastGeneratedValues, setLastGeneratedValues] = useState<LastGeneratedValues>({+ username: null,+ password: null,+ email: null+ });++ /**+ * Initialize generators for random alias generation.+ */+ const initializeGenerators = useCallback(async () => {+ if (!dbContext?.sqliteClient) {+ throw new Error('Database not initialized');+ }++ // Get effective identity language (smart default based on UI language if no explicit override)+ const identityLanguage = await dbContext.sqliteClient.getEffectiveIdentityLanguage();++ // Initialize identity generator based on language+ const identityGenerator = CreateIdentityGenerator(identityLanguage);++ // Initialize password generator with settings from vault+ const passwordSettings = dbContext.sqliteClient.getPasswordSettings();+ const passwordGenerator = CreatePasswordGenerator(passwordSettings);++ return { identityGenerator, passwordGenerator };+ }, [dbContext?.sqliteClient]);++ /**+ * Generate random alias data.+ * Returns the generated data for the caller to use.+ */+ const generateAlias = useCallback(async (): Promise<GeneratedAliasData | null> => {+ if (!dbContext?.sqliteClient) {+ return null;+ }++ try {+ const { identityGenerator, passwordGenerator } = await initializeGenerators();++ // Get gender preference from database+ const genderPreference = dbContext.sqliteClient.getDefaultIdentityGender();++ // Get age range preference and convert to birthdate options+ const ageRange = dbContext.sqliteClient.getDefaultIdentityAgeRange();+ const birthdateOptions = convertAgeRangeToBirthdateOptions(ageRange);++ // Generate identity with gender preference and birthdate options+ const identity = identityGenerator.generateRandomIdentity(genderPreference, birthdateOptions);+ const password = passwordGenerator.generateRandomPassword();++ const defaultEmailDomain = await dbContext.sqliteClient.getDefaultEmailDomain();+ const email = defaultEmailDomain ? `${identity.emailPrefix}@${defaultEmailDomain}` : identity.emailPrefix;++ const generatedData: GeneratedAliasData = {+ email,+ firstName: identity.firstName,+ lastName: identity.lastName,+ nickname: identity.nickName,+ gender: identity.gender,+ birthdate: IdentityHelperUtils.normalizeBirthDateForDisplay(identity.birthDate.toISOString()),+ username: identity.nickName,+ password+ };++ // Update tracking with new generated values+ setLastGeneratedValues({+ username: identity.nickName,+ password: password,+ email: email+ });++ return generatedData;+ } catch (error) {+ console.error('Error generating random alias:', error);+ return null;+ }+ }, [dbContext?.sqliteClient, initializeGenerators]);++ return {+ generateAlias,+ lastGeneratedValues,+ setLastGeneratedValues+ };+};++export default useAliasGenerator;+export type { GeneratedAliasData, LastGeneratedValues };diff --git a/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx b/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsxindex 109c574dd..9285a820b 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx@@ -5,22 +5,25 @@ import { useNavigate, useParams, useSearchParams } from 'react-router-dom';import AttachmentUploader from '@/entrypoints/popup/components/Credentials/Details/AttachmentUploader';import TotpEditor from '@/entrypoints/popup/components/Credentials/Details/TotpEditor';import Modal from '@/entrypoints/popup/components/Dialogs/Modal';+import AddFieldMenu from '@/entrypoints/popup/components/Forms/AddFieldMenu';import EditableFieldLabel from '@/entrypoints/popup/components/Forms/EditableFieldLabel';import { FormInput } from '@/entrypoints/popup/components/Forms/FormInput';+import FormSection from '@/entrypoints/popup/components/Forms/FormSection';import HiddenField from '@/entrypoints/popup/components/Forms/HiddenField';import PasswordField from '@/entrypoints/popup/components/Forms/PasswordField';import HeaderButton from '@/entrypoints/popup/components/HeaderButton';import { HeaderIconType } from '@/entrypoints/popup/components/Icons/HeaderIcons';+import ItemNameInput from '@/entrypoints/popup/components/Items/ItemNameInput';+import ItemTypeSelector from '@/entrypoints/popup/components/Items/ItemTypeSelector';import LoadingSpinner from '@/entrypoints/popup/components/LoadingSpinner';import { useDb } from '@/entrypoints/popup/context/DbContext';import { useHeaderButtons } from '@/entrypoints/popup/context/HeaderButtonsContext';import { useLoading } from '@/entrypoints/popup/context/LoadingContext';+import useAliasGenerator from '@/entrypoints/popup/hooks/useAliasGenerator';import { useVaultMutate } from '@/entrypoints/popup/hooks/useVaultMutate';-import { IdentityHelperUtils, CreateIdentityGenerator, convertAgeRangeToBirthdateOptions } from '@/utils/dist/shared/identity-generator';import type { Item, ItemField, ItemType, FieldType, Attachment, TotpCode } from '@/utils/dist/shared/models/vault';import { getSystemFieldsForItemType, isFieldShownByDefault } from '@/utils/dist/shared/models/vault';-import { CreatePasswordGenerator } from '@/utils/dist/shared/password-generator';// Valid item types from the shared modelconst VALID_ITEM_TYPES: ItemType[] = ['Login', 'Alias', 'CreditCard', 'Note'];@@ -28,62 +31,11 @@ const VALID_ITEM_TYPES: ItemType[] = ['Login', 'Alias', 'CreditCard', 'Note'];// Default item type for new itemsconst DEFAULT_ITEM_TYPE: ItemType = 'Login';-/**- * Item type option configuration.- */-type ItemTypeOption = {- type: ItemType;- titleKey: string;- iconSvg: React.ReactNode;-};--/**- * Available item type options with icons.- */-const ITEM_TYPE_OPTIONS: ItemTypeOption[] = [- {- type: 'Login',- titleKey: 'itemTypes.login.title',- iconSvg: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z" />- </svg>- )- },- {- type: 'Alias',- titleKey: 'itemTypes.alias.title',- iconSvg: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />- </svg>- )- },- {- type: 'CreditCard',- titleKey: 'itemTypes.creditCard.title',- iconSvg: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" />- </svg>- )- },- {- type: 'Note',- titleKey: 'itemTypes.note.title',- iconSvg: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />- </svg>- )- }-];-/*** Temporary custom field definition (before persisting to database)*/type CustomFieldDefinition = {- tempId: string; // Temporary ID until we create the FieldDefinition+ tempId: string;label: string;fieldType: FieldType;isHidden: boolean;@@ -109,9 +61,11 @@ const ItemAddEdit: React.FC = () => {const { executeVaultMutation, syncStatus } = useVaultMutate();const { setHeaderButtons } = useHeaderButtons();const { setIsInitialLoading } = useLoading();+ const { generateAlias, lastGeneratedValues } = useAliasGenerator();++ // Component stateconst [localLoading, setLocalLoading] = useState(true);const [showDeleteModal, setShowDeleteModal] = useState(false);- const [showAddCustomFieldModal, setShowAddCustomFieldModal] = useState(false);const [item, setItem] = useState<Item | null>(null);// Form state for dynamic fields@@ -120,27 +74,15 @@ const ItemAddEdit: React.FC = () => {// Custom field definitions (temporary until saved)const [customFields, setCustomFields] = useState<CustomFieldDefinition[]>([]);- // New custom field form state- const [newCustomFieldLabel, setNewCustomFieldLabel] = useState('');- const [newCustomFieldType, setNewCustomFieldType] = useState<FieldType>('Text');-// Folder selection stateconst [folders, setFolders] = useState<Array<{ Id: string; Name: string }>>([]);- // Type selector dropdown state (for create mode)+ // UI visibility stateconst [showTypeDropdown, setShowTypeDropdown] = useState(false);-- // Folder selection modal state- const [showFolderModal, setShowFolderModal] = useState(false);-- // Alias fields visibility state (for Login type - hidden by default, shown when user adds it)const [showAliasFields, setShowAliasFields] = useState(false);-- // Notes field visibility state (hidden by default, shown when user adds it)const [showNotes, setShowNotes] = useState(false);-- // Add menu dropdown state (unified + button)- const [showAddMenu, setShowAddMenu] = useState(false);+ const [show2FA, setShow2FA] = useState(false);+ const [showAttachments, setShowAttachments] = useState(false);// Track if alias was already auto-generated (to avoid re-generating on re-renders)const aliasGeneratedRef = useRef(false);@@ -148,17 +90,6 @@ const ItemAddEdit: React.FC = () => {// Ref for the item name input field (for auto-focus)const nameInputRef = useRef<HTMLInputElement>(null);- // Track last generated values to avoid overwriting manual user entries on regenerate- const [lastGeneratedValues, setLastGeneratedValues] = useState<{- username: string | null;- password: string | null;- email: string | null;- }>({- username: null,- password: null,- email: null- });-// Track password field visibility (for showing generated passwords)const [showPassword, setShowPassword] = useState(false);@@ -172,16 +103,13 @@ const ItemAddEdit: React.FC = () => {isAddFormVisible: false,formData: { name: '', secretKey: '' }});- const [show2FA, setShow2FA] = useState(false);// Attachments stateconst [attachments, setAttachments] = useState<Attachment[]>([]);const [originalAttachmentIds, setOriginalAttachmentIds] = useState<string[]>([]);- const [showAttachments, setShowAttachments] = useState(false);/*** Get all applicable system fields for the current item type.- * These are sorted by DefaultDisplayOrder.*/const applicableSystemFields = useMemo(() => {if (!item) {@@ -220,7 +148,6 @@ const ItemAddEdit: React.FC = () => {/*** Group system fields by category for organized rendering.- * Excludes metadata fields (notes) and header fields which are handled separately.*/const groupedSystemFields = useMemo(() => {const groups: Record<string, typeof applicableSystemFields> = {};@@ -250,10 +177,7 @@ const ItemAddEdit: React.FC = () => {*/useEffect(() => {if (!dbContext?.sqliteClient || !id || !isEditMode) {- /*- * Create mode - initialize with defaults- * Use provided type parameter or default to 'Login'- */+ // Create mode - initialize with defaultsconst effectiveType: ItemType = (itemTypeParam && VALID_ITEM_TYPES.includes(itemTypeParam))? itemTypeParam: DEFAULT_ITEM_TYPE;@@ -351,6 +275,55 @@ const ItemAddEdit: React.FC = () => {}}, [dbContext?.sqliteClient, id, isEditMode, itemTypeParam, itemNameParam, navigate, setIsInitialLoading]);+ /**+ * Handle generating alias and populating fields.+ */+ const handleGenerateAlias = useCallback(async () => {+ const generatedData = await generateAlias();+ if (!generatedData) {+ return;+ }++ setFieldValues(prev => {+ const currentUsername = (prev['login.username'] as string) || '';+ const currentPassword = (prev['login.password'] as string) || '';+ const currentEmail = (prev['alias.email'] as string) || '';++ const newValues: Record<string, string | string[]> = {+ ...prev,+ // Always update alias identity fields+ 'alias.first_name': generatedData.firstName,+ 'alias.last_name': generatedData.lastName,+ 'alias.nickname': generatedData.nickname,+ 'alias.gender': generatedData.gender,+ 'alias.birthdate': generatedData.birthdate+ };++ // Only overwrite email if it's empty or matches the last generated value+ if (!currentEmail || currentEmail === lastGeneratedValues.email) {+ newValues['alias.email'] = generatedData.email;+ }++ // Only overwrite username if it's empty or matches the last generated value+ if (!currentUsername || currentUsername === lastGeneratedValues.username) {+ newValues['login.username'] = generatedData.username;+ }++ // Only overwrite password if it's empty or matches the last generated value+ if (!currentPassword || currentPassword === lastGeneratedValues.password) {+ newValues['login.password'] = generatedData.password;+ }++ return newValues;+ });++ // Show the generated password+ setShowPassword(true);++ // Show alias fields section+ setShowAliasFields(true);+ }, [generateAlias, lastGeneratedValues]);+/*** Auto-generate alias when Alias type is selected in create mode.*/@@ -359,8 +332,7 @@ const ItemAddEdit: React.FC = () => {aliasGeneratedRef.current = true;void handleGenerateAlias();}- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [isEditMode, item?.ItemType, localLoading, dbContext?.sqliteClient]);+ }, [isEditMode, item?.ItemType, localLoading, dbContext?.sqliteClient, handleGenerateAlias]);/*** Auto-focus the name input field when in add mode.@@ -393,11 +365,11 @@ const ItemAddEdit: React.FC = () => {// Build the fields array from fieldValuesconst fields: ItemField[] = [];- /* Add system fields */+ // Add system fieldsapplicableSystemFields.forEach(systemField => {const value = fieldValues[systemField.FieldKey];- /* Only include fields with non-empty values */+ // Only include fields with non-empty valuesif (value && (Array.isArray(value) ? value.length > 0 : value.trim() !== '')) {fields.push({FieldKey: systemField.FieldKey,@@ -410,11 +382,11 @@ const ItemAddEdit: React.FC = () => {}});- /* Add custom fields */+ // Add custom fieldscustomFields.forEach(customField => {const value = fieldValues[customField.tempId];- /* Only include fields with non-empty values */+ // Only include fields with non-empty valuesif (value && (Array.isArray(value) ? value.length > 0 : value.trim() !== '')) {fields.push({FieldKey: customField.tempId,@@ -433,7 +405,7 @@ const ItemAddEdit: React.FC = () => {UpdatedAt: new Date().toISOString()};- /* Save to database and sync vault */+ // Save to database and sync vaultif (!dbContext?.sqliteClient) {throw new Error('Database not initialized');}@@ -452,7 +424,7 @@ const ItemAddEdit: React.FC = () => {}});- /* Navigate back to details page */+ // Navigate back to details pagenavigate(`/items/${updatedItem.Id}`);} catch (err) {console.error('Error saving item:', err);@@ -468,12 +440,10 @@ const ItemAddEdit: React.FC = () => {}try {- /* Delete from database and sync vault */await executeVaultMutation(async () => {await dbContext.sqliteClient!.deleteItemById(item.Id);});- /* Navigate back to items list */navigate('/items');} catch (err) {console.error('Error deleting item:', err);@@ -485,25 +455,18 @@ const ItemAddEdit: React.FC = () => {/*** Add custom field handler.*/- const handleAddCustomField = useCallback(() => {- if (!newCustomFieldLabel.trim()) {- return;- }-+ const handleAddCustomField = useCallback((label: string, fieldType: FieldType) => {const tempId = `custom_${crypto.randomUUID()}`;const newField: CustomFieldDefinition = {tempId,- label: newCustomFieldLabel,- fieldType: newCustomFieldType,+ label,+ fieldType,isHidden: false,displayOrder: applicableSystemFields.length + customFields.length + 1};setCustomFields(prev => [...prev, newField]);- setNewCustomFieldLabel('');- setNewCustomFieldType('Text');- setShowAddCustomFieldModal(false);- }, [newCustomFieldLabel, newCustomFieldType, applicableSystemFields.length, customFields.length]);+ }, [applicableSystemFields.length, customFields.length]);/*** Delete custom field handler.@@ -528,27 +491,21 @@ const ItemAddEdit: React.FC = () => {/*** Handle item type change from dropdown.- * In edit mode, preserves existing field values that are compatible with the new type.*/const handleTypeChange = useCallback((newType: ItemType) => {if (!item) {return;}- /*- * In create mode, clear all field values when changing type.- * In edit mode, keep existing field values - they'll be filtered during save- * based on what fields apply to the new type.- */+ // In create mode, clear all field values when changing typeif (!isEditMode) {setFieldValues({});setCustomFields([]);}- // For Alias type, show alias fields by default; otherwise hide+ // For Alias type, show alias fields by defaultif (newType === 'Alias') {setShowAliasFields(true);- // Reset the ref so alias will be auto-generated (only in create mode)if (!isEditMode) {aliasGeneratedRef.current = false;}@@ -578,104 +535,9 @@ const ItemAddEdit: React.FC = () => {}, [item, isEditMode, fieldValues, show2FA]);/**- * Initialize generators for random alias generation.- */- const initializeGenerators = useCallback(async () => {- // Get effective identity language (smart default based on UI language if no explicit override)- const identityLanguage = await dbContext.sqliteClient!.getEffectiveIdentityLanguage();-- // Initialize identity generator based on language- const identityGenerator = CreateIdentityGenerator(identityLanguage);-- // Initialize password generator with settings from vault- const passwordSettings = dbContext.sqliteClient!.getPasswordSettings();- const passwordGenerator = CreatePasswordGenerator(passwordSettings);-- return { identityGenerator, passwordGenerator };- }, [dbContext.sqliteClient]);-- /**- * Generate random alias and populate alias fields.- * This shows the alias fields and fills them with random values.- * Only overwrites username/password/email if they're empty or match the last generated value.- */- const handleGenerateAlias = useCallback(async () => {- if (!dbContext?.sqliteClient) {- return;- }-- try {- const { identityGenerator, passwordGenerator } = await initializeGenerators();-- // Get gender preference from database- const genderPreference = dbContext.sqliteClient.getDefaultIdentityGender();-- // Get age range preference and convert to birthdate options- const ageRange = dbContext.sqliteClient.getDefaultIdentityAgeRange();- const birthdateOptions = convertAgeRangeToBirthdateOptions(ageRange);-- // Generate identity with gender preference and birthdate options- const identity = identityGenerator.generateRandomIdentity(genderPreference, birthdateOptions);- const password = passwordGenerator.generateRandomPassword();-- const defaultEmailDomain = await dbContext.sqliteClient.getDefaultEmailDomain();- const email = defaultEmailDomain ? `${identity.emailPrefix}@${defaultEmailDomain}` : identity.emailPrefix;-- // Set field values for alias fields- setFieldValues(prev => {- const currentUsername = (prev['login.username'] as string) || '';- const currentPassword = (prev['login.password'] as string) || '';- const currentEmail = (prev['alias.email'] as string) || '';-- const newValues: Record<string, string | string[]> = {- ...prev,- // Always update alias identity fields- 'alias.first_name': identity.firstName,- 'alias.last_name': identity.lastName,- 'alias.nickname': identity.nickName,- 'alias.gender': identity.gender,- 'alias.birthdate': IdentityHelperUtils.normalizeBirthDateForDisplay(identity.birthDate.toISOString())- };-- // Only overwrite email if it's empty or matches the last generated value- if (!currentEmail || currentEmail === lastGeneratedValues.email) {- newValues['alias.email'] = email;- }-- // Only overwrite username if it's empty or matches the last generated value- if (!currentUsername || currentUsername === lastGeneratedValues.username) {- newValues['login.username'] = identity.nickName;- }-- // Only overwrite password if it's empty or matches the last generated value- if (!currentPassword || currentPassword === lastGeneratedValues.password) {- newValues['login.password'] = password;- }-- return newValues;- });-- // Update tracking with new generated values- setLastGeneratedValues({- username: identity.nickName,- password: password,- email: email- });-- // Show the generated password (it's random so no need to hide)- setShowPassword(true);-- // Show alias fields section- setShowAliasFields(true);- } catch (error) {- console.error('Error generating random alias:', error);- }- }, [dbContext.sqliteClient, initializeGenerators, lastGeneratedValues]);-- /**- * Clear all alias field values but keep them visible.+ * Remove alias section - clears values and hides the section.*/- const handleClearAliasFields = useCallback(() => {+ const handleRemoveAliasSection = useCallback(() => {setFieldValues(prev => ({...prev,'alias.email': '',@@ -685,15 +547,8 @@ const ItemAddEdit: React.FC = () => {'alias.gender': '','alias.birthdate': ''}));- }, []);-- /**- * Remove alias section - clears values and hides the section.- */- const handleRemoveAliasSection = useCallback(() => {- handleClearAliasFields();setShowAliasFields(false);- }, [handleClearAliasFields]);+ }, []);/*** Remove notes section - clears value and hides the section.@@ -707,115 +562,26 @@ const ItemAddEdit: React.FC = () => {}, []);/**- * Get the selected item type option for display.+ * Handle adding notes section.*/- const selectedTypeOption = useMemo(() => {- return ITEM_TYPE_OPTIONS.find(opt => opt.type === item?.ItemType);- }, [item?.ItemType]);-- /**- * Handle adding notes section from menu.- */- const handleAddNotesFromMenu = useCallback((): void => {+ const handleAddNotes = useCallback((): void => {setShowNotes(true);- setShowAddMenu(false);- }, []);-- /**- * Handle adding custom field from menu.- */- const handleAddCustomFieldFromMenu = useCallback((): void => {- setShowAddCustomFieldModal(true);- setShowAddMenu(false);}, []);/**- * Handle adding 2FA section from menu.+ * Handle adding 2FA section.*/- const handleAdd2FAFromMenu = useCallback((): void => {+ const handleAdd2FA = useCallback((): void => {setShow2FA(true);- setShowAddMenu(false);}, []);/**- * Handle adding attachments section from menu.+ * Handle adding attachments section.*/- const handleAddAttachmentsFromMenu = useCallback((): void => {+ const handleAddAttachments = useCallback((): void => {setShowAttachments(true);- setShowAddMenu(false);}, []);- /**- * Add menu options - shows available optional sections (Notes, 2FA, Attachments, and Custom Fields).- * Alias has its own dedicated button since it's a core feature.- */- const addMenuOptions = useMemo(() => {- const options: Array<{- key: string;- label: string;- icon: React.ReactNode;- action: () => void;- }> = [];-- // Notes option - show when notes field exists, is optional (not shown by default), not yet shown, and has no value- const notesIsOptional = notesField && !shouldShowFieldByDefault(notesField);- if (notesField && notesIsOptional && !showNotes && !fieldValues['metadata.notes'] && !isEditMode) {- options.push({- key: 'notes',- label: t('credentials.notes'),- icon: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />- </svg>- ),- action: handleAddNotesFromMenu- });- }-- // 2FA TOTP option - only for Login and Alias types, and when not already shown- const supports2FA = item?.ItemType === 'Login' || item?.ItemType === 'Alias';- if (supports2FA && !show2FA) {- options.push({- key: '2fa',- label: t('common.twoFactorAuthentication'),- icon: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />- </svg>- ),- action: handleAdd2FAFromMenu- });- }-- // Attachments option - available for all types, when not already shown- if (!showAttachments) {- options.push({- key: 'attachments',- label: t('common.attachments'),- icon: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <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" />- </svg>- ),- action: handleAddAttachmentsFromMenu- });- }-- // Custom field option (always available)- options.push({- key: 'custom',- label: t('itemTypes.addCustomField'),- icon: (- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6" />- </svg>- ),- action: handleAddCustomFieldFromMenu- });-- return options;- }, [showNotes, notesField, fieldValues, isEditMode, t, handleAddNotesFromMenu, handleAddCustomFieldFromMenu, handleAdd2FAFromMenu, handleAddAttachmentsFromMenu, shouldShowFieldByDefault, item?.ItemType, show2FA, showAttachments]);-// Set header buttonsuseEffect(() => {const headerButtonsJSX = (@@ -958,134 +724,87 @@ const ItemAddEdit: React.FC = () => {void handleSave();}, [handleSave]);- if (localLoading || !item) {- return <LoadingSpinner />;- }+ /**+ * Get category title for display.+ */+ const getCategoryTitle = useCallback((category: string): string => {+ switch (category) {+ case 'Login':+ return t('common.credentials');+ case 'Alias':+ return t('credentials.alias');+ case 'Card':+ return t('credentials.cardInformation');+ case 'Identity':+ return t('credentials.identityInformation');+ default:+ return category;+ }+ }, [t]);- return (- <form onSubmit={handleFormSubmit} className="space-y-4">- {/* Item Type Selector (both create and edit mode) */}- <div className="relative">- <div className="w-full px-4 py-2 bg-primary-50 dark:bg-primary-900/20 border border-primary-200 dark:border-primary-800 rounded-lg flex items-center gap-2">+ /**+ * Render section action buttons for optional sections.+ */+ const renderSectionActions = useCallback((category: string, isOptional: boolean) => {+ if (category === 'Alias' && isOptional && showAliasFields) {+ return (+ <>+ {/* Regenerate button */}<buttontype="button"- onClick={() => setShowTypeDropdown(!showTypeDropdown)}- className="flex-1 flex items-center justify-between hover:opacity-80 transition-opacity"+ onClick={handleGenerateAlias}+ className="p-1.5 text-gray-400 hover:text-primary-500 focus:outline-none"+ title={t('credentials.generateRandomAlias')}>- <div className="flex items-center gap-2">- <span className="text-primary-600 dark:text-primary-400">- {selectedTypeOption?.iconSvg}- </span>- <span className="text-primary-700 dark:text-primary-300 font-medium text-sm">- {isEditMode ? t('itemTypes.editing') : t('itemTypes.creating')} {selectedTypeOption ? t(selectedTypeOption.titleKey) : ''}- </span>- </div>- <svg- className={`w-4 h-4 text-primary-500 transition-transform ${showTypeDropdown ? 'rotate-180' : ''}`}- fill="none"- stroke="currentColor"- viewBox="0 0 24 24"- >- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />+ <svg className='w-4 h-4' viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">+ <path d="M23 4v6h-6"/>+ <path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg></button>- {/* Regenerate alias button - icon only for flexibility */}- {item?.ItemType === 'Alias' && !isEditMode && (- <button- type="button"- onClick={(e) => {- e.stopPropagation();- void handleGenerateAlias();- }}- className="flex-shrink-0 p-1.5 text-primary-600 dark:text-primary-400 hover:text-primary-700 dark:hover:text-primary-300 hover:bg-primary-100 dark:hover:bg-primary-900/40 rounded transition-colors"- title={t('itemTypes.regenerateAlias')}- >- <svg className='w-4 h-4' viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">- <path d="M23 4v6h-6"/>- <path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>- </svg>- </button>- )}- </div>+ {/* Remove button */}+ <button+ type="button"+ onClick={handleRemoveAliasSection}+ className="p-1.5 text-gray-400 hover:text-red-500 focus:outline-none"+ title={t('common.delete')}+ >+ <svg className='w-4 h-4' viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">+ <line x1="18" y1="6" x2="6" y2="18"/>+ <line x1="6" y1="6" x2="18" y2="18"/>+ </svg>+ </button>+ </>+ );+ }+ return null;+ }, [showAliasFields, handleGenerateAlias, handleRemoveAliasSection, t]);- {/* Type Dropdown Menu */}- {showTypeDropdown && (- <>- <div- className="fixed inset-0 z-10"- onClick={() => setShowTypeDropdown(false)}- />- <div className="absolute z-20 mt-1 w-full bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md shadow-lg">- {ITEM_TYPE_OPTIONS.map((option) => (- <button- key={option.type}- type="button"- onClick={() => handleTypeChange(option.type)}- className={`w-full px-4 py-3 text-left hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-3 border-b border-gray-100 dark:border-gray-700 last:border-b-0 ${- item.ItemType === option.type- ? 'bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300'- : 'text-gray-900 dark:text-white'- }`}- >- <span className={item.ItemType === option.type ? 'text-primary-600 dark:text-primary-400' : 'text-gray-500 dark:text-gray-400'}>- {option.iconSvg}- </span>- <span className="font-medium">- {t(option.titleKey)}- </span>- {item.ItemType === option.type && (- <svg className="w-5 h-5 ml-auto text-primary-600 dark:text-primary-400" fill="currentColor" viewBox="0 0 20 20">- <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />- </svg>- )}- </button>- ))}- </div>- </>- )}- </div>+ if (localLoading || !item) {+ return <LoadingSpinner />;+ }- {/* Item Name and Header fields block */}- <div className="bg-white dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700 space-y-4">- <div>- <label htmlFor="itemName" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">- {t('credentials.itemName')} <span className="text-red-500">*</span>- </label>- <div className="relative">- <input- ref={nameInputRef}- id="itemName"- type="text"- value={item.Name || ''}- onChange={(e) => setItem({ ...item, Name: e.target.value })}- placeholder={t('credentials.itemName')}- className={`w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white ${folders.length > 0 ? 'pr-28' : ''}`}- required- />- {/* Folder Button inside input */}- {folders.length > 0 && (- <button- type="button"- onClick={() => setShowFolderModal(true)}- className={`absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-1 px-2 py-1 rounded transition-colors text-xs ${- item.FolderId- ? 'bg-primary-100 dark:bg-primary-900/30 text-primary-600 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-900/50'- : 'text-gray-400 dark:text-gray-500 hover:text-gray-500 dark:hover:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-600'- }`}- title={item.FolderId ? folders.find(f => f.Id === item.FolderId)?.Name || t('items.folder') : t('items.noFolder')}- >- <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />- </svg>- {item.FolderId && (- <span className="max-w-16 truncate">- {folders.find(f => f.Id === item.FolderId)?.Name}- </span>- )}- </button>- )}- </div>- </div>+ return (+ <form onSubmit={handleFormSubmit} className="space-y-4">+ {/* Item Type Selector */}+ <ItemTypeSelector+ selectedType={item.ItemType}+ isEditMode={isEditMode}+ showDropdown={showTypeDropdown}+ onDropdownToggle={setShowTypeDropdown}+ onTypeChange={handleTypeChange}+ onRegenerateAlias={item.ItemType === 'Alias' && !isEditMode ? handleGenerateAlias : undefined}+ />++ {/* Item Name and Primary fields block */}+ <FormSection>+ <ItemNameInput+ inputRef={nameInputRef}+ value={item.Name || ''}+ onChange={(name) => setItem({ ...item, Name: name })}+ folders={folders}+ selectedFolderId={item.FolderId}+ onFolderChange={(folderId) => setItem({ ...item, FolderId: folderId })}+ />{/* Primary fields (like URL) shown below name */}{primaryFields.map(field => (<div key={field.FieldKey}>@@ -1098,115 +817,69 @@ const ItemAddEdit: React.FC = () => {)}</div>))}- </div>+ </FormSection>{/* Render fields grouped by category */}{Object.keys(groupedSystemFields).map(category => {- // Check if this category has any fields that are optional (not shown by default)const categoryFields = groupedSystemFields[category];const allFieldsOptional = categoryFields.every(f => !shouldShowFieldByDefault(f));const isOptionalCategory = category === 'Alias' && allFieldsOptional && !isEditMode;- // If this is an optional category and not shown, skip rendering (will be available via + button)+ // Skip optional categories that aren't shownif (isOptionalCategory && !showAliasFields) {return null;}return (- <div key={category} className="bg-white dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700">- <h2 className="text-lg font-semibold mb-4 text-gray-900 dark:text-white flex items-center justify-between">- <span>- {category === 'Login' && t('common.credentials')}- {category === 'Alias' && t('credentials.alias')}- {category === 'Card' && t('credentials.cardInformation')}- {category === 'Identity' && t('credentials.identityInformation')}- {category !== 'Login' && category !== 'Alias' && category !== 'Card' && category !== 'Identity' && category}- </span>-- {/* Show action buttons for optional Alias section in create mode */}- {isOptionalCategory && showAliasFields && (- <div className="flex items-center gap-2">- {/* Regenerate button */}- <button- type="button"- onClick={handleGenerateAlias}- className="p-1.5 text-gray-400 hover:text-primary-500 focus:outline-none"- title={t('credentials.generateRandomAlias')}- >- <svg className='w-4 h-4' viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">- <path d="M23 4v6h-6"/>- <path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>- </svg>- </button>- {/* Remove button */}- <button- type="button"- onClick={handleRemoveAliasSection}- className="p-1.5 text-gray-400 hover:text-red-500 focus:outline-none"- title={t('common.delete')}- >- <svg className='w-4 h-4' viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">- <line x1="18" y1="6" x2="6" y2="18"/>- <line x1="6" y1="6" x2="18" y2="18"/>- </svg>- </button>- </div>- )}- </h2>- <div className="space-y-4">- {groupedSystemFields[category].map(field => (- <div key={field.FieldKey}>- {renderFieldInput(- field.FieldKey,- field.Label,- field.FieldType,- field.IsHidden,- field.IsMultiValue- )}- </div>- ))}- </div>- </div>+ <FormSection+ key={category}+ title={getCategoryTitle(category)}+ actions={renderSectionActions(category, isOptionalCategory)}+ >+ {categoryFields.map(field => (+ <div key={field.FieldKey}>+ {renderFieldInput(+ field.FieldKey,+ field.Label,+ field.FieldType,+ field.IsHidden,+ field.IsMultiValue+ )}+ </div>+ ))}+ </FormSection>);})}{/* Custom Fields Section */}{customFields.length > 0 && (- <div className="bg-white dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700">- <h2 className="text-lg font-semibold mb-4 text-gray-900 dark:text-white">- {t('common.customFields')}- </h2>- <div className="space-y-4">- {customFields.map(field => (- <div key={field.tempId}>- <EditableFieldLabel- htmlFor={field.tempId}- label={field.label}- onLabelChange={(newLabel) => handleUpdateCustomFieldLabel(field.tempId, newLabel)}- onDelete={() => handleDeleteCustomField(field.tempId)}- />-- {/* Field input */}- {renderFieldInput(- field.tempId,- '',- field.fieldType,- field.isHidden,- false- )}- </div>- ))}- </div>- </div>+ <FormSection title={t('common.customFields')}>+ {customFields.map(field => (+ <div key={field.tempId}>+ <EditableFieldLabel+ htmlFor={field.tempId}+ label={field.label}+ onLabelChange={(newLabel) => handleUpdateCustomFieldLabel(field.tempId, newLabel)}+ onDelete={() => handleDeleteCustomField(field.tempId)}+ />+ {renderFieldInput(+ field.tempId,+ '',+ field.fieldType,+ field.isHidden,+ false+ )}+ </div>+ ))}+ </FormSection>)}- {/* Notes Section - Hidden by default in create mode, with remove button if optional */}+ {/* Notes Section */}{notesField && (showNotes || isEditMode || fieldValues['metadata.notes']) && (- <div className="bg-white dark:bg-gray-800 p-4 rounded-lg border border-gray-200 dark:border-gray-700">- <h2 className="text-lg font-semibold mb-4 text-gray-900 dark:text-white flex items-center justify-between">- <span>{t('credentials.notes')}</span>- {/* Remove button for notes in create mode - only if notes is optional (not shown by default) */}- {!isEditMode && !shouldShowFieldByDefault(notesField) && (+ <FormSection+ title={t('credentials.notes')}+ actions={+ !isEditMode && !shouldShowFieldByDefault(notesField) ? (<buttontype="button"onClick={handleRemoveNotesSection}@@ -1218,21 +891,20 @@ const ItemAddEdit: React.FC = () => {<line x1="6" y1="6" x2="18" y2="18"/></svg></button>- )}- </h2>- <div className="space-y-4">- {renderFieldInput(- notesField.FieldKey,- notesField.Label,- notesField.FieldType,- notesField.IsHidden,- notesField.IsMultiValue- )}- </div>- </div>+ ) : undefined+ }+ >+ {renderFieldInput(+ notesField.FieldKey,+ notesField.Label,+ notesField.FieldType,+ notesField.IsHidden,+ notesField.IsMultiValue+ )}+ </FormSection>)}- {/* 2FA TOTP Section - only for Login and Alias types */}+ {/* 2FA TOTP Section */}{show2FA && (item?.ItemType === 'Login' || item?.ItemType === 'Alias') && (<TotpEditortotpCodes={totpCodes}@@ -1252,112 +924,22 @@ const ItemAddEdit: React.FC = () => {/>)}- {/* Generic + button with dropdown menu for Notes and Custom Fields */}- <div className="relative">- <button- type="button"- onClick={() => setShowAddMenu(!showAddMenu)}- className="w-full px-4 py-3 border-2 border-dashed border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-400 rounded-md hover:border-primary-500 hover:text-primary-600 dark:hover:text-primary-400 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 transition-colors flex items-center justify-center gap-2"- >- <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6" />- </svg>- </button>-- {/* Add Menu Dropdown */}- {showAddMenu && (- <>- <div- className="fixed inset-0 z-10"- onClick={() => setShowAddMenu(false)}- />- <div className="absolute bottom-full left-0 right-0 mb-1 z-20 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md shadow-lg overflow-hidden">- {addMenuOptions.map((option) => (- <button- key={option.key}- type="button"- onClick={option.action}- className="w-full px-4 py-3 text-left hover:bg-gray-50 dark:hover:bg-gray-700 flex items-center gap-3 border-b border-gray-100 dark:border-gray-700 last:border-b-0 text-gray-700 dark:text-gray-300"- >- <span className="text-gray-500 dark:text-gray-400">- {option.icon}- </span>- <span>{option.label}</span>- </button>- ))}- </div>- </>- )}- </div>-- {/* Add Custom Field Dialog */}- {showAddCustomFieldModal && (- <div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">- <div className="bg-white dark:bg-gray-800 rounded-lg shadow-xl p-6 w-96 max-w-full mx-4">- <h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-4">- Add Custom Field- </h3>-- <div className="space-y-4">- <div>- <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">- Field Label- </label>- <input- type="text"- value={newCustomFieldLabel}- onChange={(e) => setNewCustomFieldLabel(e.target.value)}- className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white"- placeholder="Enter field name"- autoFocus- />- </div>-- <div>- <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">- Field Type- </label>- <select- value={newCustomFieldType}- onChange={(e) => setNewCustomFieldType(e.target.value as FieldType)}- className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white"- >- <option value="Text">Text</option>- <option value="Hidden">Hidden (masked text)</option>- <option value="Email">Email</option>- <option value="URL">URL</option>- <option value="Phone">Phone</option>- <option value="Number">Number</option>- <option value="Date">Date</option>- <option value="TextArea">Text Area</option>- </select>- </div>- </div>-- <div className="flex gap-3 mt-6">- <button- type="button"- onClick={handleAddCustomField}- disabled={!newCustomFieldLabel.trim()}- className="flex-1 px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 disabled:opacity-50 disabled:cursor-not-allowed"- >- Add- </button>- <button- type="button"- onClick={() => {- setShowAddCustomFieldModal(false);- setNewCustomFieldLabel('');- setNewCustomFieldType('Text');- }}- className="px-4 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-md hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"- >- {t('common.cancel')}- </button>- </div>- </div>- </div>- )}+ {/* Add Field Menu */}+ <AddFieldMenu+ itemType={item.ItemType}+ isEditMode={isEditMode}+ visibility={{+ showNotes,+ show2FA,+ showAttachments+ }}+ callbacks={{+ onAddNotes: handleAddNotes,+ onAdd2FA: handleAdd2FA,+ onAddAttachments: handleAddAttachments,+ onAddCustomField: handleAddCustomField+ }}+ />{/* Delete Confirmation Modal */}{isEditMode && (@@ -1373,95 +955,6 @@ const ItemAddEdit: React.FC = () => {/>)}- {/* Folder Selection Modal */}- {showFolderModal && (- <div className="fixed inset-0 z-50 overflow-y-auto">- {/* Backdrop */}- <div- className="fixed inset-0 bg-black bg-opacity-80 transition-opacity"- onClick={() => setShowFolderModal(false)}- />-- {/* Modal */}- <div className="fixed inset-0 flex items-center justify-center p-4">- <div className="relative transform overflow-hidden rounded-lg bg-white dark:bg-gray-800 px-4 pb-4 pt-5 text-left shadow-xl transition-all w-full max-w-sm">- {/* Close button */}- <button- type="button"- className="absolute right-4 top-4 text-gray-400 hover:text-gray-500 focus:outline-none"- onClick={() => setShowFolderModal(false)}- >- <span className="sr-only">{t('common.close')}</span>- <svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">- <path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />- </svg>- </button>-- {/* Content */}- <div className="mb-4">- <h3 className="text-lg font-semibold leading-6 text-gray-900 dark:text-white">- {t('items.folder')}- </h3>- </div>-- {/* Folder Options */}- <div className="space-y-1 max-h-64 overflow-y-auto">- {/* No Folder Option */}- <button- type="button"- onClick={() => {- setItem({ ...item, FolderId: null });- setShowFolderModal(false);- }}- className={`w-full px-3 py-2 text-left rounded-md flex items-center gap-3 transition-colors ${- !item.FolderId- ? 'bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300'- : 'text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700'- }`}- >- <svg className={`w-5 h-5 ${!item.FolderId ? 'text-primary-500' : 'text-gray-400'}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4" />- </svg>- <span className="font-medium">{t('items.noFolder')}</span>- {!item.FolderId && (- <svg className="w-5 h-5 ml-auto text-primary-600 dark:text-primary-400" fill="currentColor" viewBox="0 0 20 20">- <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />- </svg>- )}- </button>-- {/* Folder Options */}- {folders.map(folder => (- <button- key={folder.Id}- type="button"- onClick={() => {- setItem({ ...item, FolderId: folder.Id });- setShowFolderModal(false);- }}- className={`w-full px-3 py-2 text-left rounded-md flex items-center gap-3 transition-colors ${- item.FolderId === folder.Id- ? 'bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300'- : 'text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700'- }`}- >- <svg className={`w-5 h-5 ${item.FolderId === folder.Id ? 'text-primary-500' : 'text-gray-400'}`} fill="none" stroke="currentColor" viewBox="0 0 24 24">- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />- </svg>- <span className="font-medium">{folder.Name}</span>- {item.FolderId === folder.Id && (- <svg className="w-5 h-5 ml-auto text-primary-600 dark:text-primary-400" fill="currentColor" viewBox="0 0 20 20">- <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />- </svg>- )}- </button>- ))}- </div>- </div>- </div>- </div>- )}-{/* Sync Status */}{syncStatus && (<div className="fixed bottom-4 right-4 bg-white dark:bg-gray-800 rounded-lg shadow-lg p-4 border border-gray-200 dark:border-gray-700">diff --git a/apps/browser-extension/src/i18n/locales/en.json b/apps/browser-extension/src/i18n/locales/en.jsonindex 3b769f50e..8a10965c6 100644--- a/apps/browser-extension/src/i18n/locales/en.json+++ b/apps/browser-extension/src/i18n/locales/en.json@@ -300,6 +300,19 @@"addAlias": "Add alias","addNotes": "Add notes","addCustomField": "Add custom field",+ "fieldLabel": "Field Label",+ "enterFieldName": "Enter field name",+ "fieldType": "Field Type",+ "fieldTypes": {+ "text": "Text",+ "hidden": "Hidden (masked text)",+ "email": "Email",+ "url": "URL",+ "phone": "Phone",+ "number": "Number",+ "date": "Date",+ "textArea": "Text Area"+ },"login": {"title": "Login","description": "Username, password, and website credentials"