Skip to content

Commit 928507a

Browse files
committed
fix: api key warning message
1 parent fffac9c commit 928507a

File tree

1 file changed

+64
-9
lines changed

1 file changed

+64
-9
lines changed

grade-management-new/GradeManagement.Client/Components/NewDialogs/NewSubjectDialog.razor

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,63 @@
11
@inject CrudSnackbarService SnackbarService
22
@inject CurrentUserService CurrentUserService
33

4-
<MudDialog>
4+
<MudDialog Style="min-width: 600px;">
55
<TitleContent>
66
<MudText Typo="Typo.h4">New Subject</MudText>
77
</TitleContent>
88
<DialogContent>
99
<MudForm @ref="form" Model="@value" @bind-IsValid="@success" @bind-Errors="@errors">
10-
<MudTextField T="string" Label="Name" For="@(() => value.Name)" @bind-Value="value.Name" Required="true"></MudTextField>
11-
<MudTextField T="string" Label="Neptun Code" @bind-Value="value.NeptunCode" Required="true" Validation="@(new Func<string, IEnumerable<string>>(NeptunCodeValidator))"></MudTextField>
12-
<MudTextField T="string" Label="Github Org" For="@(() => value.GitHubOrgName)" @bind-Value="value.GitHubOrgName" Required="true"></MudTextField>
13-
<div class="d-flex align-center">
14-
<MudTextField T="string" Label="API Key" For="@(() => value.CiApiKey)" @bind-Value="value.CiApiKey" Required="true" Class="flex-grow-1 me-2"></MudTextField>
15-
<MudIconButton Icon="@Icons.Material.Filled.Refresh" OnClick="GenerateApiKey" Size="Size.Small"/>
16-
</div>
10+
<MudTextField T="string"
11+
Label="Name"
12+
For="@(() => value.Name)"
13+
@bind-Value="value.Name"
14+
Required="true"/>
15+
16+
<MudTextField T="string"
17+
Label="Neptun Code"
18+
@bind-Value="value.NeptunCode"
19+
Required="true"
20+
Validation="@(new Func<string, IEnumerable<string>>(NeptunCodeValidator))"/>
21+
22+
<MudTextField T="string"
23+
Label="Github Org"
24+
For="@(() => value.GitHubOrgName)"
25+
@bind-Value="value.GitHubOrgName"
26+
Required="true"/>
27+
28+
@if (showApiKeyWarning)
29+
{
30+
<MudAlert Severity="Severity.Warning" Class="my-2">
31+
This API key will be shown only once. Make sure to save it!
32+
</MudAlert>
33+
}
34+
35+
<MudPaper Elevation="0" Class="d-flex flex-column gap-2">
36+
<div class="d-flex align-center gap-2">
37+
<MudTextField T="string"
38+
Label="API Key"
39+
For="@(() => value.CiApiKey)"
40+
@bind-Value="value.CiApiKey"
41+
Required="true"
42+
ReadOnly="true"
43+
Variant="Variant.Outlined"
44+
Class="flex-grow-1"/>
45+
46+
<MudTooltip Text="Generate new API key">
47+
<MudIconButton Icon="@Icons.Material.Filled.Refresh"
48+
OnClick="GenerateApiKey"
49+
Color="Color.Primary"
50+
Size="Size.Medium"/>
51+
</MudTooltip>
52+
53+
<MudTooltip Text="Copy to clipboard">
54+
<MudIconButton Icon="@Icons.Material.Filled.ContentCopy"
55+
OnClick="CopyToClipboard"
56+
Color="Color.Secondary"
57+
Size="Size.Medium"/>
58+
</MudTooltip>
59+
</div>
60+
</MudPaper>
1761
</MudForm>
1862
</DialogContent>
1963
<DialogActions>
@@ -24,18 +68,29 @@
2468

2569
@code {
2670
[CascadingParameter] MudDialogInstance MudDialog { get; set; }
71+
[Inject] private IJSRuntime JS { get; set; }
2772

2873
private MudForm form;
2974
private bool success;
3075
private string[] errors;
76+
private bool showApiKeyWarning = false;
3177

3278
private void Submit() => MudDialog.Close(DialogResult.Ok(value));
3379
private void Cancel() => MudDialog.Cancel();
3480

3581
private void GenerateApiKey()
3682
{
83+
showApiKeyWarning = true;
3784
value.CiApiKey = Guid.NewGuid().ToString();
38-
SnackbarService.ShowMessage("Current user: " + CurrentUserService.User.Name);
85+
}
86+
87+
private async Task CopyToClipboard()
88+
{
89+
if (!string.IsNullOrEmpty(value.CiApiKey))
90+
{
91+
await JS.InvokeVoidAsync("navigator.clipboard.writeText", value.CiApiKey);
92+
SnackbarService.ShowSuccess("API key copied to clipboard!");
93+
}
3994
}
4095

4196
private async void OnSubmitClicked()

0 commit comments

Comments
 (0)