|
1 | 1 | @inject ResourceService ResourceService |
2 | | -@inject ISnackbar Snackbar |
3 | | - |
4 | | -<MudDialog @bind-Visible="_visible" Options="_dialogOptions"> |
5 | | - <TitleContent> |
6 | | - <MudText Typo="Typo.h6"> |
7 | | - <MudIcon Icon="@Icons.Material.Filled.Add" Class="mr-2" /> |
8 | | - Add New Key |
9 | | - </MudText> |
10 | | - </TitleContent> |
11 | | - <DialogContent> |
12 | | - <EditForm Model="_model" OnValidSubmit="HandleSubmit"> |
13 | | - <DataAnnotationsValidator /> |
14 | | - <MudStack Spacing="3"> |
15 | | - <MudTextField @bind-Value="_model.KeyName" |
16 | | - Label="Key Name" |
17 | | - Variant="Variant.Outlined" |
18 | | - For="@(() => _model.KeyName)" |
19 | | - Disabled="_isSubmitting" |
20 | | - Required="true" |
21 | | - HelperText="e.g., WelcomeMessage, Error.NotFound, Button.Save" /> |
22 | | - |
23 | | - <MudTextField @bind-Value="_model.Comment" |
24 | | - Label="Comment (optional)" |
25 | | - Variant="Variant.Outlined" |
26 | | - Lines="2" |
27 | | - For="@(() => _model.Comment)" |
28 | | - Disabled="_isSubmitting" |
29 | | - HelperText="Description to help translators" /> |
30 | | - |
31 | | - <MudSwitch @bind-Value="_model.IsPlural" |
32 | | - Label="Plural key" |
33 | | - Color="Color.Primary" |
34 | | - Disabled="_isSubmitting" /> |
35 | | - |
36 | | - @if (_model.IsPlural) |
37 | | - { |
38 | | - <MudAlert Severity="Severity.Info" Dense="true"> |
39 | | - Plural keys support different forms for quantities (zero, one, few, many, other). |
40 | | - </MudAlert> |
41 | | - } |
42 | | - |
43 | | - <MudTextField @bind-Value="_defaultValue" |
44 | | - Label="Default Value" |
45 | | - Variant="Variant.Outlined" |
46 | | - Lines="2" |
47 | | - Disabled="_isSubmitting" |
48 | | - HelperText="Value for the default language" /> |
49 | | - |
50 | | - @if (!string.IsNullOrEmpty(_errorMessage)) |
51 | | - { |
52 | | - <MudAlert Severity="Severity.Error" Dense="true">@_errorMessage</MudAlert> |
53 | | - } |
54 | | - </MudStack> |
55 | | - </EditForm> |
56 | | - </DialogContent> |
57 | | - <DialogActions> |
58 | | - <MudButton OnClick="Close" Disabled="_isSubmitting">Cancel</MudButton> |
59 | | - <MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="HandleSubmit" Disabled="_isSubmitting"> |
60 | | - @if (_isSubmitting) |
| 2 | +@inject NotificationService NotificationService |
| 3 | +@inject Radzen.DialogService DialogService |
| 4 | + |
| 5 | +<RadzenStack Gap="1rem"> |
| 6 | + <RadzenTemplateForm TItem="CreateResourceKeyRequest" Data="_model" Submit="HandleSubmit"> |
| 7 | + <RadzenStack Gap="1rem"> |
| 8 | + <RadzenFormField Text="Key Name" Variant="Radzen.Variant.Outlined" Style="width: 100%;"> |
| 9 | + <ChildContent> |
| 10 | + <RadzenTextBox @bind-Value="_model.KeyName" Placeholder="e.g., WelcomeMessage, Error.NotFound, Button.Save" |
| 11 | + Disabled="@_isSubmitting" Style="width: 100%;" Name="KeyName" /> |
| 12 | + </ChildContent> |
| 13 | + <Helper> |
| 14 | + <RadzenText TextStyle="TextStyle.Caption" class="rz-color-secondary">e.g., WelcomeMessage, Error.NotFound, Button.Save</RadzenText> |
| 15 | + </Helper> |
| 16 | + </RadzenFormField> |
| 17 | + |
| 18 | + <RadzenFormField Text="Comment (optional)" Variant="Radzen.Variant.Outlined" Style="width: 100%;"> |
| 19 | + <ChildContent> |
| 20 | + <RadzenTextArea @bind-Value="_model.Comment" Placeholder="Description to help translators" |
| 21 | + Rows="2" Disabled="@_isSubmitting" Style="width: 100%;" /> |
| 22 | + </ChildContent> |
| 23 | + <Helper> |
| 24 | + <RadzenText TextStyle="TextStyle.Caption" class="rz-color-secondary">Description to help translators</RadzenText> |
| 25 | + </Helper> |
| 26 | + </RadzenFormField> |
| 27 | + |
| 28 | + <RadzenSwitch @bind-Value="_model.IsPlural" Disabled="@_isSubmitting"> |
| 29 | + <Template> |
| 30 | + <RadzenText>Plural key</RadzenText> |
| 31 | + </Template> |
| 32 | + </RadzenSwitch> |
| 33 | + |
| 34 | + @if (_model.IsPlural) |
61 | 35 | { |
62 | | - <MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" /> |
63 | | - <MudText Class="ms-2">Creating...</MudText> |
| 36 | + <RadzenAlert AlertStyle="AlertStyle.Info" Shade="Shade.Lighter" AllowClose="false" Size="AlertSize.Small"> |
| 37 | + Plural keys support different forms for quantities (zero, one, few, many, other). |
| 38 | + </RadzenAlert> |
64 | 39 | } |
65 | | - else |
| 40 | + |
| 41 | + <RadzenFormField Text="Default Value" Variant="Radzen.Variant.Outlined" Style="width: 100%;"> |
| 42 | + <ChildContent> |
| 43 | + <RadzenTextArea @bind-Value="_defaultValue" Placeholder="Value for the default language" |
| 44 | + Rows="2" Disabled="@_isSubmitting" Style="width: 100%;" /> |
| 45 | + </ChildContent> |
| 46 | + <Helper> |
| 47 | + <RadzenText TextStyle="TextStyle.Caption" class="rz-color-secondary">Value for the default language</RadzenText> |
| 48 | + </Helper> |
| 49 | + </RadzenFormField> |
| 50 | + |
| 51 | + @if (!string.IsNullOrEmpty(_errorMessage)) |
66 | 52 | { |
67 | | - <MudText>Add Key</MudText> |
| 53 | + <RadzenAlert AlertStyle="AlertStyle.Danger" Shade="Shade.Lighter" AllowClose="false" Size="AlertSize.Small"> |
| 54 | + @_errorMessage |
| 55 | + </RadzenAlert> |
68 | 56 | } |
69 | | - </MudButton> |
70 | | - </DialogActions> |
71 | | -</MudDialog> |
| 57 | + </RadzenStack> |
| 58 | + </RadzenTemplateForm> |
| 59 | + |
| 60 | + <RadzenStack Orientation="Radzen.Orientation.Horizontal" JustifyContent="JustifyContent.End" Gap="0.5rem"> |
| 61 | + <RadzenButton Variant="Radzen.Variant.Text" Text="Cancel" Click="@Close" Disabled="@_isSubmitting" /> |
| 62 | + <RadzenButton ButtonStyle="ButtonStyle.Primary" Text="@(_isSubmitting ? "Creating..." : "Add Key")" |
| 63 | + Click="@HandleSubmit" Disabled="@_isSubmitting" IsBusy="@_isSubmitting" /> |
| 64 | + </RadzenStack> |
| 65 | +</RadzenStack> |
72 | 66 |
|
73 | 67 | @code { |
74 | 68 | [Parameter] |
|
77 | 71 | [Parameter] |
78 | 72 | public EventCallback<ResourceKeyDto> OnKeyAdded { get; set; } |
79 | 73 |
|
80 | | - private bool _visible; |
81 | 74 | private bool _isSubmitting; |
82 | 75 | private string? _errorMessage; |
83 | 76 | private string _defaultValue = string.Empty; |
84 | 77 | private CreateResourceKeyRequest _model = new() { KeyName = "" }; |
85 | 78 |
|
86 | | - private readonly DialogOptions _dialogOptions = new() |
87 | | - { |
88 | | - MaxWidth = MaxWidth.Small, |
89 | | - FullWidth = true, |
90 | | - CloseOnEscapeKey = true |
91 | | - }; |
92 | | - |
93 | | - public void Open() |
94 | | - { |
95 | | - _model = new CreateResourceKeyRequest { KeyName = "" }; |
96 | | - _defaultValue = string.Empty; |
97 | | - _errorMessage = null; |
98 | | - _visible = true; |
99 | | - StateHasChanged(); |
100 | | - } |
101 | | - |
102 | 79 | private void Close() |
103 | 80 | { |
104 | | - _visible = false; |
| 81 | + DialogService.Close(null); |
105 | 82 | } |
106 | 83 |
|
107 | 84 | private async Task HandleSubmit() |
|
127 | 104 |
|
128 | 105 | if (result.IsSuccess && result.Data != null) |
129 | 106 | { |
130 | | - Snackbar.Add($"Key '{result.Data.KeyName}' created successfully!", Severity.Success); |
| 107 | + NotificationService.Notify(NotificationSeverity.Success, "Success", $"Key '{result.Data.KeyName}' created successfully!"); |
131 | 108 | await OnKeyAdded.InvokeAsync(result.Data); |
132 | | - Close(); |
| 109 | + DialogService.Close(result.Data); |
133 | 110 | } |
134 | 111 | else |
135 | 112 | { |
|
0 commit comments