Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Create generic FormModal wrapper (#1404)
Leendert de Borst81316dab9215
diff --git a/apps/server/AliasVault.Client/Main/Components/Folders/FolderModal.razor b/apps/server/AliasVault.Client/Main/Components/Folders/FolderModal.razorindex 8214f6002..c3b2a5341 100644--- a/apps/server/AliasVault.Client/Main/Components/Folders/FolderModal.razor+++ b/apps/server/AliasVault.Client/Main/Components/Folders/FolderModal.razor@@ -1,72 +1,38 @@+@using AliasVault.Client.Main.Components.Layout@using Microsoft.Extensions.Localization@* FolderModal component - modal for creating or editing a folder *@-@if (IsOpen)-{- <div class="fixed inset-0 z-50 overflow-y-auto">- <div class="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">- @* Background overlay *@- <div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity dark:bg-gray-900 dark:bg-opacity-75" @onclick="HandleClose"></div>-- @* Modal panel *@- <div class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg dark:bg-gray-800">- <div class="bg-white px-4 pb-4 pt-5 sm:p-6 dark:bg-gray-800">- <div class="sm:flex sm:items-start">- <div class="mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-orange-100 sm:mx-0 sm:h-10 sm:w-10 dark:bg-orange-900/30">- <svg class="h-6 w-6 text-orange-600 dark:text-orange-400" viewBox="0 0 24 24" fill="currentColor">- <path d="M10 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-8l-2-2z"/>- </svg>- </div>- <div class="mt-3 text-center sm:ml-4 sm:mt-0 sm:text-left flex-1">- <h3 class="text-lg font-semibold leading-6 text-gray-900 dark:text-white">- @(Mode == "create" ? Localizer["CreateFolderTitle"] : Localizer["EditFolderTitle"])- </h3>- <div class="mt-4">- <label for="folder-name" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">- @Localizer["FolderNameLabel"]- </label>- <input- type="text"- id="folder-name"- @bind="FolderName"- @bind:event="oninput"- @onkeydown="HandleKeyDown"- placeholder="@Localizer["FolderNamePlaceholder"]"- class="block w-full rounded-md border-0 py-2 px-3 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-orange-600 sm:text-sm sm:leading-6 dark:bg-gray-700 dark:text-white dark:ring-gray-600 dark:placeholder:text-gray-500 dark:focus:ring-orange-500" />- @if (!string.IsNullOrEmpty(ErrorMessage))- {- <p class="mt-2 text-sm text-red-600 dark:text-red-400">@ErrorMessage</p>- }- </div>- </div>- </div>- </div>- <div class="bg-gray-50 px-4 py-3 sm:flex sm:flex-row-reverse sm:px-6 gap-2 dark:bg-gray-800/50">- <button- type="button"- @onclick="HandleSave"- disabled="@IsSaving"- class="inline-flex w-full justify-center rounded-md bg-orange-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-orange-500 sm:w-auto disabled:opacity-50 disabled:cursor-not-allowed dark:bg-orange-700 dark:hover:bg-orange-600">- @if (IsSaving)- {- <svg class="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 class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>- <path class="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>- }- @(Mode == "create" ? Localizer["CreateButton"] : Localizer["SaveButton"])- </button>- <button- type="button"- @onclick="HandleClose"- class="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">- @Localizer["CancelButton"]- </button>- </div>- </div>- </div>- </div>-}+<FormModal+ IsOpen="IsOpen"+ Title="@(Mode == "create" ? Localizer["CreateFolderTitle"] : Localizer["EditFolderTitle"])"+ ConfirmText="@(Mode == "create" ? Localizer["CreateButton"] : Localizer["SaveButton"])"+ CancelText="@Localizer["CancelButton"]"+ IsLoading="IsSaving"+ ConfirmDisabled="@string.IsNullOrWhiteSpace(FolderName)"+ OnClose="HandleClose"+ OnConfirm="HandleSave">+ <Icon>+ <svg class="h-6 w-6 text-orange-600 dark:text-orange-400" viewBox="0 0 24 24" fill="currentColor">+ <path d="M10 4H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-8l-2-2z"/>+ </svg>+ </Icon>+ <ChildContent>+ <label for="folder-name" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">+ @Localizer["FolderNameLabel"]+ </label>+ <input+ type="text"+ id="folder-name"+ @bind="FolderName"+ @bind:event="oninput"+ placeholder="@Localizer["FolderNamePlaceholder"]"+ class="block w-full rounded-md border-0 py-2 px-3 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-orange-600 sm:text-sm sm:leading-6 dark:bg-gray-700 dark:text-white dark:ring-gray-600 dark:placeholder:text-gray-500 dark:focus:ring-orange-500" />+ @if (!string.IsNullOrEmpty(ErrorMessage))+ {+ <p class="mt-2 text-sm text-red-600 dark:text-red-400">@ErrorMessage</p>+ }+ </ChildContent>+</FormModal>@code {[Inject]@@ -153,16 +119,4 @@{await OnClose.InvokeAsync();}-- private async Task HandleKeyDown(KeyboardEventArgs e)- {- if (e.Key == "Enter")- {- await HandleSave();- }- else if (e.Key == "Escape")- {- await HandleClose();- }- }}diff --git a/apps/server/AliasVault.Client/Main/Components/Items/AddFieldMenu.razor b/apps/server/AliasVault.Client/Main/Components/Items/AddFieldMenu.razorindex c6bf2a02f..871fc954e 100644--- a/apps/server/AliasVault.Client/Main/Components/Items/AddFieldMenu.razor+++ b/apps/server/AliasVault.Client/Main/Components/Items/AddFieldMenu.razor@@ -1,4 +1,5 @@@using AliasClientDb.Models+@using AliasVault.Client.Main.Components.Layout@using Microsoft.Extensions.Localization@inject IStringLocalizerFactory LocalizerFactory@@ -79,58 +80,51 @@</div>@* Custom Field Modal *@-@if (ShowCustomFieldModal)-{- <div class="fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center">- <div class="bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full mx-4">- <div class="px-6 py-4 border-b border-gray-200 dark:border-gray-700">- <h3 class="text-lg font-semibold text-gray-900 dark:text-white">@Localizer["AddCustomField"]</h3>- </div>- <div class="px-6 py-4 space-y-4">- <div>- <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">- @Localizer["FieldLabel"]- </label>- <input type="text"- @bind="CustomFieldLabel"- class="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="@Localizer["EnterFieldName"]" />- </div>- <div>- <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">- @Localizer["FieldType"]- </label>- <select @bind="CustomFieldType"- class="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">@Localizer["FieldTypeText"]</option>- <option value="Hidden">@Localizer["FieldTypeHidden"]</option>- <option value="Email">@Localizer["FieldTypeEmail"]</option>- <option value="URL">@Localizer["FieldTypeUrl"]</option>- <option value="Phone">@Localizer["FieldTypePhone"]</option>- <option value="Number">@Localizer["FieldTypeNumber"]</option>- <option value="Date">@Localizer["FieldTypeDate"]</option>- <option value="TextArea">@Localizer["FieldTypeTextArea"]</option>- </select>- </div>+<FormModal+ IsOpen="ShowCustomFieldModal"+ Title="@Localizer["AddCustomField"]"+ ConfirmText="@Localizer["Add"]"+ CancelText="@Localizer["Cancel"]"+ ConfirmDisabled="@string.IsNullOrWhiteSpace(CustomFieldLabel)"+ ConfirmButtonClass="bg-primary-600 hover:bg-primary-500 dark:bg-primary-700 dark:hover:bg-primary-600"+ MaxWidth="md"+ OnClose="CloseCustomFieldModal"+ OnConfirm="HandleAddCustomField">+ <Icon>+ <svg class="h-6 w-6 text-primary-600 dark:text-primary-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />+ </svg>+ </Icon>+ <ChildContent>+ <div class="space-y-4">+ <div>+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">+ @Localizer["FieldLabel"]+ </label>+ <input type="text"+ @bind="CustomFieldLabel"+ class="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="@Localizer["EnterFieldName"]" /></div>- <div class="px-6 py-4 border-t border-gray-200 dark:border-gray-700 flex gap-3">- <button type="button"- @onclick="HandleAddCustomField"- @onclick:preventDefault="true"- disabled="@string.IsNullOrWhiteSpace(CustomFieldLabel)"- class="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">- @Localizer["Add"]- </button>- <button type="button"- @onclick="CloseCustomFieldModal"- @onclick:preventDefault="true"- class="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">- @Localizer["Cancel"]- </button>+ <div>+ <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">+ @Localizer["FieldType"]+ </label>+ <select @bind="CustomFieldType"+ class="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">@Localizer["FieldTypeText"]</option>+ <option value="Hidden">@Localizer["FieldTypeHidden"]</option>+ <option value="Email">@Localizer["FieldTypeEmail"]</option>+ <option value="URL">@Localizer["FieldTypeUrl"]</option>+ <option value="Phone">@Localizer["FieldTypePhone"]</option>+ <option value="Number">@Localizer["FieldTypeNumber"]</option>+ <option value="Date">@Localizer["FieldTypeDate"]</option>+ <option value="TextArea">@Localizer["FieldTypeTextArea"]</option>+ </select></div></div>- </div>-}+ </ChildContent>+</FormModal>@code {private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Main.Items.AddFieldMenu", "AliasVault.Client");@@ -230,11 +224,12 @@CloseMenu();}- private void CloseCustomFieldModal()+ private Task CloseCustomFieldModal(){ShowCustomFieldModal = false;CustomFieldLabel = string.Empty;CustomFieldType = "Text";+ return Task.CompletedTask;}private async Task HandleAddCustomField()@@ -242,7 +237,7 @@if (!string.IsNullOrWhiteSpace(CustomFieldLabel)){await OnAddCustomField.InvokeAsync((CustomFieldLabel.Trim(), CustomFieldType));- CloseCustomFieldModal();+ await CloseCustomFieldModal();}}diff --git a/apps/server/AliasVault.Client/Main/Components/Layout/FormModal.razor b/apps/server/AliasVault.Client/Main/Components/Layout/FormModal.razornew file mode 100644index 000000000..743533c31--- /dev/null+++ b/apps/server/AliasVault.Client/Main/Components/Layout/FormModal.razor@@ -0,0 +1,254 @@+//-----------------------------------------------------------------------+// <copyright file="FormModal.razor" company="aliasvault">+// Copyright (c) aliasvault. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++@using Microsoft.Extensions.Localization++@* FormModal component - generic modal for displaying forms and content *@+@if (IsOpen)+{+ <div class="fixed inset-0 z-50 overflow-y-auto">+ <div class="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">+ @* Background overlay *@+ <div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity dark:bg-gray-900 dark:bg-opacity-75" @onclick="HandleOverlayClick"></div>++ @* Modal panel *@+ <div @ref="ModalElement" @onkeydown="HandleKeyDown" tabindex="0" class="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all sm:my-8 sm:w-full @GetMaxWidthClass() dark:bg-gray-800">+ <div class="bg-white px-4 pb-4 pt-5 sm:p-6 dark:bg-gray-800">+ <div class="sm:flex sm:items-start">+ @if (Icon != null)+ {+ <div class="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 class="@(Icon != null ? "mt-3 text-center sm:ml-4 sm:mt-0 sm:text-left" : "") flex-1">+ @if (!string.IsNullOrEmpty(Title))+ {+ <h3 class="text-lg font-semibold leading-6 text-gray-900 dark:text-white">+ @Title+ </h3>+ }+ <div class="@(string.IsNullOrEmpty(Title) ? "" : "mt-4")">+ @ChildContent+ </div>+ </div>+ </div>+ </div>++ @if (FooterContent != null)+ {+ <div class="bg-gray-50 px-4 py-3 sm:flex sm:flex-row-reverse sm:px-6 gap-2 dark:bg-gray-800/50">+ @FooterContent+ </div>+ }+ else if (ShowDefaultFooter)+ {+ <div class="bg-gray-50 px-4 py-3 sm:flex sm:flex-row-reverse sm:px-6 gap-2 dark:bg-gray-800/50">+ <button+ type="button"+ @onclick="HandleConfirm"+ disabled="@(IsLoading || ConfirmDisabled)"+ class="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">+ @if (IsLoading)+ {+ <svg class="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 class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>+ <path class="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+ </button>+ <button+ type="button"+ @onclick="HandleCancel"+ class="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+ </button>+ </div>+ }+ </div>+ </div>+ </div>+}++@code {+ [Inject]+ private IStringLocalizerFactory LocalizerFactory { get; set; } = default!;++ private IStringLocalizer SharedLocalizer => LocalizerFactory.Create("SharedResources", "AliasVault.Client");++ private ElementReference ModalElement;++ /// <summary>+ /// Gets or sets whether the modal is open.+ /// </summary>+ [Parameter]+ public bool IsOpen { get; set; }++ /// <summary>+ /// Gets or sets the modal title.+ /// </summary>+ [Parameter]+ public string Title { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the optional icon to display in the header.+ /// </summary>+ [Parameter]+ public RenderFragment? Icon { get; set; }++ /// <summary>+ /// Gets or sets the CSS class for the icon background.+ /// Defaults to orange theme.+ /// </summary>+ [Parameter]+ public string IconBackgroundClass { get; set; } = "bg-orange-100 dark:bg-orange-900/30";++ /// <summary>+ /// Gets or sets the main content of the modal.+ /// </summary>+ [Parameter]+ public RenderFragment? ChildContent { get; set; }++ /// <summary>+ /// Gets or sets the footer content of the modal.+ /// If not provided, default confirm/cancel buttons are shown (if ShowDefaultFooter is true).+ /// </summary>+ [Parameter]+ public RenderFragment? FooterContent { get; set; }++ /// <summary>+ /// Gets or sets whether to show the default footer with confirm/cancel buttons.+ /// </summary>+ [Parameter]+ public bool ShowDefaultFooter { get; set; } = true;++ /// <summary>+ /// Gets or sets the confirm button text.+ /// </summary>+ [Parameter]+ public string? ConfirmText { get; set; }++ /// <summary>+ /// Gets or sets the cancel button text.+ /// </summary>+ [Parameter]+ public string? CancelText { get; set; }++ /// <summary>+ /// Gets or sets whether the confirm button is disabled.+ /// </summary>+ [Parameter]+ public bool ConfirmDisabled { get; set; }++ /// <summary>+ /// Gets or sets the CSS class for the confirm button.+ /// </summary>+ [Parameter]+ public string ConfirmButtonClass { get; set; } = "bg-orange-600 hover:bg-orange-500 dark:bg-orange-700 dark:hover:bg-orange-600";++ /// <summary>+ /// Gets or sets whether the modal is in a loading state.+ /// </summary>+ [Parameter]+ public bool IsLoading { get; set; }++ /// <summary>+ /// Gets or sets the max width class for the modal.+ /// Options: sm, md, lg, xl, 2xl. Defaults to lg.+ /// </summary>+ [Parameter]+ public string MaxWidth { get; set; } = "lg";++ /// <summary>+ /// Gets or sets whether to close the modal when clicking the overlay.+ /// </summary>+ [Parameter]+ public bool CloseOnOverlayClick { get; set; } = true;++ /// <summary>+ /// Gets or sets whether to close the modal when pressing Escape.+ /// </summary>+ [Parameter]+ public bool CloseOnEscape { get; set; } = true;++ /// <summary>+ /// Gets or sets whether to submit the form when pressing Enter.+ /// </summary>+ [Parameter]+ public bool SubmitOnEnter { get; set; } = true;++ /// <summary>+ /// Gets or sets the close callback.+ /// </summary>+ [Parameter]+ public EventCallback OnClose { get; set; }++ /// <summary>+ /// Gets or sets the confirm callback.+ /// </summary>+ [Parameter]+ public EventCallback OnConfirm { get; set; }++ /// <inheritdoc />+ protected override void OnParametersSet()+ {+ // Set default button texts if not provided+ if (string.IsNullOrEmpty(ConfirmText))+ {+ ConfirmText = SharedLocalizer["Confirm"];+ }++ if (string.IsNullOrEmpty(CancelText))+ {+ CancelText = SharedLocalizer["Cancel"];+ }+ }++ private string GetMaxWidthClass()+ {+ return MaxWidth switch+ {+ "sm" => "sm:max-w-sm",+ "md" => "sm:max-w-md",+ "lg" => "sm:max-w-lg",+ "xl" => "sm:max-w-xl",+ "2xl" => "sm:max-w-2xl",+ _ => "sm:max-w-lg"+ };+ }++ private async Task HandleOverlayClick()+ {+ if (CloseOnOverlayClick)+ {+ await OnClose.InvokeAsync();+ }+ }++ private async Task HandleKeyDown(KeyboardEventArgs e)+ {+ if (e.Key == "Escape" && CloseOnEscape)+ {+ await OnClose.InvokeAsync();+ }+ else if (e.Key == "Enter" && SubmitOnEnter && !ConfirmDisabled && !IsLoading)+ {+ await HandleConfirm();+ }+ }++ private async Task HandleConfirm()+ {+ await OnConfirm.InvokeAsync();+ }++ private async Task HandleCancel()+ {+ await OnClose.InvokeAsync();+ }+}diff --git a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css b/apps/server/AliasVault.Client/wwwroot/css/tailwind.cssindex 82c7a7361..24fd38a4f 100644--- a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css+++ b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css@@ -2786,6 +2786,11 @@ video {background-color: rgb(153 27 27 / var(--tw-bg-opacity));}+.hover\:bg-primary-500:hover {+ --tw-bg-opacity: 1;+ background-color: rgb(244 149 65 / var(--tw-bg-opacity));+}+.hover\:from-primary-600:hover {--tw-gradient-from: #d68338 var(--tw-gradient-from-position);--tw-gradient-to: rgb(214 131 56 / 0) var(--tw-gradient-to-position);@@ -3843,6 +3848,22 @@ video {max-width: 32rem;}+ .sm\:max-w-2xl {+ max-width: 42rem;+ }++ .sm\:max-w-md {+ max-width: 28rem;+ }++ .sm\:max-w-sm {+ max-width: 24rem;+ }++ .sm\:max-w-xl {+ max-width: 36rem;+ }+.sm\:grid-cols-2 {grid-template-columns: repeat(2, minmax(0, 1fr));}